Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
2001-02-03  Ulrich Drepper  <[email protected]>

	* hesiod/hesiod.c: Remove unnecessary code.  Remove all uses of strcat.

	* hesiod/hesiod.c (hesiod_resolve): Also search HS records if
  • Loading branch information
Ulrich Drepper committed Feb 3, 2001
1 parent 0c7dfa1 commit 3b46325
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 44 deletions.
6 changes: 5 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
2001-02-03 Ulrich Drepper <[email protected]>

* hesiod/hesiod.c: Remove unnecessary code. Remove all uses of strcat.

2001-02-02 Ulrich Drepper <[email protected]>

* hesiod/hesiod.c (hesiod_resolve): Also search HS records is
* hesiod/hesiod.c (hesiod_resolve): Also search HS records if
errno is ECONNREFUSED.

* posix/Makefile: Define MBS_SUPPORT for regex.c.
Expand Down
66 changes: 23 additions & 43 deletions hesiod/hesiod.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ hesiod_init(void **context) {
char *cp;

ctx = malloc(sizeof(struct hesiod_p));
if (ctx == 0) {
__set_errno(ENOMEM);
if (ctx == 0)
return (-1);
}

ctx->LHS = NULL;
ctx->RHS = NULL;
Expand All @@ -96,10 +94,8 @@ hesiod_init(void **context) {
*/
ctx->LHS = malloc(strlen(DEF_LHS)+1);
ctx->RHS = malloc(strlen(DEF_RHS)+1);
if (ctx->LHS == 0 || ctx->RHS == 0) {
__set_errno(ENOMEM);
if (ctx->LHS == 0 || ctx->RHS == 0)
goto cleanup;
}
strcpy(ctx->LHS, DEF_LHS);
strcpy(ctx->RHS, DEF_RHS);
#else
Expand All @@ -111,18 +107,15 @@ hesiod_init(void **context) {
* variable.
*/
if ((cp = __secure_getenv("HES_DOMAIN")) != NULL) {
if (ctx->RHS)
free(ctx->RHS);
free(ctx->RHS);
ctx->RHS = malloc(strlen(cp)+2);
if (!ctx->RHS) {
__set_errno(ENOMEM);
if (!ctx->RHS)
goto cleanup;
}
if (cp[0] == '.')
strcpy(ctx->RHS, cp);
else {
strcpy(ctx->RHS, ".");
strcat(ctx->RHS, cp);
ctx->RHS[0] = '.';
strcpy(ctx->RHS + 1, cp);
}
}

Expand Down Expand Up @@ -158,10 +151,8 @@ hesiod_end(void *context) {

if (ctx->res)
res_nclose(ctx->res);
if (ctx->RHS)
free(ctx->RHS);
if (ctx->LHS)
free(ctx->LHS);
free(ctx->RHS);
free(ctx->LHS);
if (ctx->res && ctx->free_res)
(*ctx->free_res)(ctx->res);
free(ctx);
Expand All @@ -178,6 +169,7 @@ hesiod_to_bind(void *context, const char *name, const char *type) {
char *bindname;
char **rhs_list = NULL;
const char *RHS, *cp;
char *endp;

/* Decide what our RHS is, and set cp to the end of the actual name. */
if ((cp = strchr(name, '@')) != NULL) {
Expand All @@ -201,25 +193,23 @@ hesiod_to_bind(void *context, const char *name, const char *type) {
*/
if ((bindname = malloc((cp - name) + strlen(type) + strlen(RHS) +
(ctx->LHS ? strlen(ctx->LHS) : 0) + 4)) == NULL) {
__set_errno(ENOMEM);
if (rhs_list)
hesiod_free_list(context, rhs_list);
return NULL;
}

/* Now put together the DNS name. */
memcpy(bindname, name, cp - name);
bindname[cp - name] = '\0';
strcat(bindname, ".");
strcat(bindname, type);
endp = (char *) __mempcpy (bindname, name, cp - name);
*endp++ = '.';
endp = (char *) __stpcpy (endp, type);
if (ctx->LHS) {
if (ctx->LHS[0] != '.')
strcat(bindname, ".");
strcat(bindname, ctx->LHS);
*endp++ = '.';
endp = __stpcpy (endp, ctx->LHS);
}
if (RHS[0] != '.')
strcat(bindname, ".");
strcat(bindname, RHS);
*endp++ = '.';
strcpy (endp, RHS);

if (rhs_list)
hesiod_free_list(context, rhs_list);
Expand Down Expand Up @@ -279,10 +269,8 @@ parse_config_file(struct hesiod_p *ctx, const char *filename) {
* Clear the existing configuration variable, just in case
* they're set.
*/
if (ctx->RHS)
free(ctx->RHS);
if (ctx->LHS)
free(ctx->LHS);
free(ctx->RHS);
free(ctx->LHS);
ctx->RHS = ctx->LHS = 0;

/*
Expand Down Expand Up @@ -317,21 +305,17 @@ parse_config_file(struct hesiod_p *ctx, const char *filename) {
continue;

*cpp = malloc(strlen(data) + 1);
if (!*cpp) {
__set_errno(ENOMEM);
if (!*cpp)
goto cleanup;
}
strcpy(*cpp, data);
}
fclose(fp);
return (0);

cleanup:
fclose(fp);
if (ctx->RHS)
free(ctx->RHS);
if (ctx->LHS)
free(ctx->LHS);
free(ctx->RHS);
free(ctx->LHS);
ctx->RHS = ctx->LHS = 0;
return (-1);
}
Expand Down Expand Up @@ -394,10 +378,8 @@ get_txt_records(struct hesiod_p *ctx, int class, const char *name) {
}

list = malloc((ancount + 1) * sizeof(char *));
if (!list) {
__set_errno(ENOMEM);
if (!list)
return (NULL);
}
j = 0;
for (i = 0; i < ancount; i++) {
skip = dn_skipname(cp, eom);
Expand Down Expand Up @@ -467,10 +449,8 @@ __hesiod_res_get(void *context) {
if (!ctx->res) {
struct __res_state *res;
res = (struct __res_state *)malloc(sizeof *res);
if (res == NULL) {
__set_errno(ENOMEM);
if (res == NULL)
return (NULL);
}
memset(res, 0, sizeof *res);
__hesiod_res_set(ctx, res, free);
}
Expand Down

0 comments on commit 3b46325

Please sign in to comment.