- 论坛徽章:
- 0
|
好奇怪的段错误啊?半天没找出来,高手帮帮小妹啊!!!
- static vchar_t *
- ident_ir2mx(iph1)
- struct ph1handle *iph1;
- {
- vchar_t *buf = 0;
- struct isakmp_gen *gen;
- char *p;
- int tlen;
- int need_cr = 0;
- vchar_t *cr = NULL;
- vchar_t *vid = NULL;
- /*by yvonne*/
- vchar_t *h_psk=NULL;
- vchar_t *hpsk=NULL;
- /*by yvonne*/
- int error = -1;
- int nptype;
- /* create buffer
- */
- tlen = sizeof(struct isakmp)
- + sizeof(*gen) + iph1->;dhpub->;l
- + sizeof(*gen) + iph1->;nonce->;l;
- #ifdef CYH
- printf("\nnext is by yvonne\n");
- #endif
- /* by yvonne */
- if(iph1->;side==INITIATOR&&iph1->;approval->;authmethod==OAKLEY_ATTR_AUTH_METHOD_PSKEY&&iph1->;etype == ISAKMP_ETYPE_IDENT)
- {
- //取psk,给hpsk赋值
- #ifdef CYH
- printf("\nbegin getpskbyaddr function");
- #endif
-
- if(NULL==(hpsk=getpskbyaddr(iph1->;remote)))
- printf("\n hpsk is NULL\n");
-
- #ifdef CYH
- printf("\n finish getpskbyaddr, begin eay_md5_one function");
- #endif
-
- iph1->;h_psk= eay_md5_one(hpsk);
-
- #ifdef CYH
- printf("end eay_md5_one function");
- #endif
-
- tlen += sizeof(*gen) + h_psk->;l;
- }
复制代码
getpskbyaddr代码:
/*
* get PSK by address.
*/
- vchar_t *
- getpskbyaddr(remote)
- struct sockaddr *remote;
- {
- vchar_t *key = NULL;
- char addr[NI_MAXHOST], port[NI_MAXSERV];
- GETNAMEINFO(remote, addr, port);
- #ifdef CYH
- printf("\n begin getpsk funtion\n");
- #endif
- key = getpsk(addr, strlen(addr));
- #ifdef CYH
- if(NULL==key)printf("\n key is NULL\n");
- printf("\n end getpsk\n");
- printf("\nbeing return key in getpskbyaddr function");
- #endif
- return key;
- }
复制代码
getpsk代码:
- static vchar_t *
- getpsk(str, len)
- const char *str;
- const int len;
- {
- FILE *fp;
- char buf[1024]; /* XXX how is variable length ? */
- vchar_t *key = NULL;
- // vchar_t *hpsk = NULL;
- char *p, *q;
- size_t keylen;
- char *k = NULL;
- //验证文件的安全性并只读打开文件
- if (safefile(lcconf->;pathinfo[LC_PATHTYPE_PSK], 1) == 0)
- fp = fopen(lcconf->;pathinfo[LC_PATHTYPE_PSK], "r");
- else
- fp = NULL;
- if (fp == NULL) {
- plog(LLV_ERROR, LOCATION, NULL,
- "failed to open pre_share_key file %s\n",
- lcconf->;pathinfo[LC_PATHTYPE_PSK]);
- return NULL;
- }
- //读入存储区
- #ifdef CYH
- printf("\nread cunchun\n");
- #endif
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- /* comment line 忽略 */
- if (buf[0] == '#')
- continue;
- /* search the end of 1st string. */
- for (p = buf; *p != '\0' && !isspace(*p); p++)
- ;
- if (*p == '\0')
- continue; /* no 2nd parameter */
- *p = '\0';
- /* search the 1st of 2nd string. */
- while (isspace(*++p))
- ;
- if (*p == '\0')
- continue; /* no 2nd parameter */
- p--;
- if (strncmp(buf, str, len) == 0 && buf[len] == '\0') {
- p++;
- keylen = 0;
- for (q = p; *q != '\0' && *q != '\n'; q++)
- keylen++;
- *q = '\0';
- /* fix key if hex string */
- if (strncmp(p, "0x", 2) == 0) {
- k = str2val(p + 2, 16, &keylen);
- if (k == NULL) {
- plog(LLV_ERROR, LOCATION, NULL,
- "failed to get psk buffer.\n");
- goto end;
- }
- p = k;
- }
- key = vmalloc(keylen);
- if (key == NULL) {
- plog(LLV_ERROR, LOCATION, NULL,
- "failed to allocate key buffer.\n");
- goto end;
- }
- memcpy(key->;v, p, key->;l);
- if (k)
- racoon_free(k);
- goto end;
- }
- }
- end:
- fclose(fp);
- return key;
- }
复制代码 |
|