free buffers allocated by krb5_get_krbhst.
* locate_kdc.c (_krb5_use_dns): Add _krb_use_dns to abstract
away looking up of whether we use DNS or not in the profile.
* ktdefname.c (krb5_kt_default_name): Use profile_release_string
instead of free to free string allocated by profile_get_string.
* get_krbhst.c (krb5_get_krbhst): Copy results from profile_get_values
into malloc'ed buffers so we can safely free them later. Also call
profile_free_list on the original values.
* locate_kdc.c (krb5_locate_kdc):
* hst_realm.c (krb5_get_host_realm):
* def_realm.c (krb5_get_default_realm): Use _krb5_use_dns to figure
out whether to use DNS or not instead of directly reading the
profile in this routine.
* realm_dom.c (krb5_get_realm_domain):
* hst_realm.c (krb5_get_host_realm):
* def_realm.c (krb5_get_default_realm): Copy results of
profile_get_string into malloc'ed buffer so it can safely be free'd
later.
* locate_kdc.c (krb5_locate_srv_conf):
* def_realm.c (krb5_get_default_realm):
* changepw.c (krb5_change_password):
* an_to_ln.c (krb5_aname_to_localname): Use profile_free_list
to free values allocated by profile_get_values.
* init_os_ctx.c (os_init_paths): Wrap use of ctx->profile_in_memory
with KRB5_DNS_LOOKUP. Use pointer value to determine whether to free
files by checking the files value rather than depending on the
return value.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11626
dc483132-0cff-0310-8789-
dd5450dbe970
+1999-08-05 Danilo Almeida <dalmeida@mit.edu>
+
+ * t_std_conf.c (test_get_krbhst): Use krb5_free_krbhst to
+ free buffers allocated by krb5_get_krbhst.
+
+ * locate_kdc.c (_krb5_use_dns): Add _krb_use_dns to abstract
+ away looking up of whether we use DNS or not in the profile.
+
+ * ktdefname.c (krb5_kt_default_name): Use profile_release_string
+ instead of free to free string allocated by profile_get_string.
+
+ * get_krbhst.c (krb5_get_krbhst): Copy results from profile_get_values
+ into malloc'ed buffers so we can safely free them later. Also call
+ profile_free_list on the original values.
+
+ * locate_kdc.c (krb5_locate_kdc):
+ * hst_realm.c (krb5_get_host_realm):
+ * def_realm.c (krb5_get_default_realm): Use _krb5_use_dns to figure
+ out whether to use DNS or not instead of directly reading the
+ profile in this routine.
+
+ * realm_dom.c (krb5_get_realm_domain):
+ * hst_realm.c (krb5_get_host_realm):
+ * def_realm.c (krb5_get_default_realm): Copy results of
+ profile_get_string into malloc'ed buffer so it can safely be free'd
+ later.
+
+ * locate_kdc.c (krb5_locate_srv_conf):
+ * def_realm.c (krb5_get_default_realm):
+ * changepw.c (krb5_change_password):
+ * an_to_ln.c (krb5_aname_to_localname): Use profile_free_list
+ to free values allocated by profile_get_values.
+
+1999-08-04 Danilo Almeida <dalmeida@mit.edu>
+
+ * init_os_ctx.c (os_init_paths): Wrap use of ctx->profile_in_memory
+ with KRB5_DNS_LOOKUP. Use pointer value to determine whether to free
+ files by checking the files value rather than depending on the
+ return value.
+
1999-07-27 Miro Jurisic <meeroh@mit.edu>
* init_os_ctx.c (GetMacProfileFileSpec): removed bogus string conversion
/* We found one or more explicit mappings. */
for (nvalid=0; mapping_values[nvalid]; nvalid++);
- /* Free the other ones, just use the last one */
- for (i=0; i<nvalid-1; i++)
- krb5_xfree(mapping_values[i]);
-
+ /* Just use the last one. */
/* Trim the value. */
cp = &mapping_values[nvalid-1]
[strlen(mapping_values[nvalid-1])];
kret = KRB5_CONFIG_NOTENUFSPACE;
/* Free residue */
- krb5_xfree(mapping_values[nvalid-1]);
- krb5_xfree(mapping_values);
+ profile_free_list(mapping_values);
}
else {
/*
}
/* We're done, clean up the droppings. */
- for (i=0; mapping_values[i]; i++)
- krb5_xfree(mapping_values[i]);
- krb5_xfree(mapping_values);
+ profile_free_list(mapping_values);
}
else {
/*
}
}
- for (i=0; hostlist[i]; i++)
- free(hostlist[i]);
- free ((char *)hostlist);
+ profile_free_list(hostlist);
if (out == 0) { /* Couldn't resolve any KDC names */
free (addr_p);
krb5_context context;
char FAR * FAR *lrealm;
{
- char *realm;
+ char *realm = 0;
char *cp;
krb5_error_code retval;
return KRB5_CONFIG_CANTOPEN;
retval = profile_get_string(context->profile, "libdefaults",
"default_realm", 0, 0,
- &context->default_realm);
+ &realm);
+
+ if (!retval) {
+ context->default_realm = malloc(strlen(realm) + 1);
+ if (!context->default_realm) {
+ profile_release_string(realm);
+ return ENOMEM;
+ }
+ strcpy(context->default_realm, realm);
+ profile_release_string(realm);
+ }
+
#ifdef KRB5_DNS_LOOKUP
if (context->default_realm == 0) {
- int use_dns=0;
- char * string=NULL;
- krb5_error_code retval2;
-
- retval2 = profile_get_string(context->profile, "libdefaults",
- "dns_fallback", 0,
- context->profile_in_memory?"1":"0",
- &string);
- if ( retval2 )
- return(retval2);
-
- if ( string ) {
- use_dns = krb5_conf_boolean(string);
- free(string);
- }
+ int use_dns = _krb5_use_dns(context);
if ( use_dns ) {
/*
* Since this didn't appear in our config file, try looking
char **values, **cpp, *cp;
const char *realm_kdc_names[4];
krb5_error_code retval;
+ int i, count;
+
+ *hostlist = 0;
realm_kdc_names[0] = "realms";
realm_kdc_names[1] = realm->data;
if (cp)
*cp = 0;
}
-
- *hostlist = values;
- return 0;
+ count = cpp - values;
+ *hostlist = malloc(sizeof(char *) * (count + 1));
+ if (!*hostlist) {
+ retval = ENOMEM;
+ goto cleanup;
+ }
+ for (i = 0; i < count; i++) {
+ *hostlist[i] = malloc(strlen(values[i]) + 1);
+ if (!*hostlist[i]) {
+ retval = ENOMEM;
+ goto cleanup;
+ }
+ }
+ *hostlist[count] = 0;
+ cleanup:
+ if (retval && *hostlist) {
+ for (cpp = *hostlist; *cpp; cpp++)
+ free(*cpp);
+ free(*hostlist);
+ }
+ profile_free_list(values);
+ return retval;
}
char FAR * FAR * FAR *realmsp;
{
char **retrealms;
- char *default_realm, *realm, *cp;
+ char *default_realm, *realm, *cp, *temp_realm;
krb5_error_code retval;
int l;
char local_host[MAX_DNS_NAMELEN+1];
cp = local_host;
realm = default_realm = (char *)NULL;
+ temp_realm = 0;
while (cp) {
retval = profile_get_string(context->profile, "domain_realm", cp,
- 0, (char *)NULL, &realm);
+ 0, (char *)NULL, &temp_realm);
if (retval)
return retval;
- if (realm != (char *)NULL)
+ if (temp_realm != (char *)NULL)
break; /* Match found */
/* Setup for another test */
cp = strchr(cp, '.');
}
}
+ if (temp_realm) {
+ realm = malloc(strlen(temp_realm) + 1);
+ if (!realm) {
+ profile_release_string(temp_realm);
+ return ENOMEM;
+ }
+ strcpy(realm, temp_realm);
+ profile_release_string(temp_realm);
+ }
#ifdef KRB5_DNS_LOOKUP
if (realm == (char *)NULL) {
- int use_dns=0;
- char * string=NULL;
- krb5_error_code retval2;
-
- retval2 = profile_get_string(context->profile, "libdefaults",
- "dns_fallback", 0,
- context->profile_in_memory?"1":"0",
- &string);
- if ( retval2 )
- return(retval2);
-
- if ( string ) {
- use_dns = krb5_conf_boolean(string);
- free(string);
- }
+ int use_dns = _krb5_use_dns(context);
if ( use_dns ) {
/*
* Since this didn't appear in our config file, try looking
profile_filespec_t *files = 0;
ctx->profile_secure = secure;
+#ifdef KRB5_DNS_LOOKUP
ctx->profile_in_memory = 0;
+#endif /* KRB5_DNS_LOOKUP */
retval = os_get_default_config_files(&files, secure);
if (!retval) {
retval = profile_init(files, &ctx->profile);
-
+#ifdef KRB5_DNS_LOOKUP
/* if none of the filenames can be opened use an empty profile */
- if ( retval == ENOENT ) {
- retval = profile_init(NULL,&ctx->profile);
- if ( !retval )
+ if (retval == ENOENT) {
+ retval = profile_init(NULL, &ctx->profile);
+ if (!retval)
ctx->profile_in_memory = 1;
}
-
- if (files)
- free_filespecs(files);
+#endif /* KRB5_DNS_LOOKUP */
}
+ if (files)
+ free_filespecs(files);
+
if (retval)
ctx->profile = 0;
if ((size_t) namesize < (strlen(retval)+1))
return KRB5_CONFIG_NOTENUFSPACE;
strcpy(name, retval);
- free(retval);
+ profile_release_string(retval);
} else {
#if defined (_MSDOS) || defined(_WIN32)
{
#endif
#define MAX_DNS_NAMELEN (15*(MAXHOSTNAMELEN + 1)+1)
+
+int
+_krb5_use_dns(context)
+ krb5_context context;
+{
+ krb5_error_code code;
+ char * value = NULL;
+ int use_dns = 0;
+
+ code = profile_get_string(context->profile, "libdefaults",
+ "dns_fallback", 0,
+ context->profile_in_memory?"1":"0",
+ &value);
+ if (code)
+ return(code);
+
+ if (value) {
+ use_dns = _krb5_conf_boolean(value);
+ profile_release_string(value);
+ }
+
+ return use_dns;
+}
+
#endif /* KRB5_DNS_LOOKUP */
/*
count++;
if (count == 0) {
+ profile_free_list(hostlist);
krb5_xfree(host);
*naddrs = 0;
return 0;
#endif
addr_p = (struct sockaddr *)malloc (sizeof (struct sockaddr) * count);
- if (addr_p == NULL)
+ if (addr_p == NULL) {
+ profile_free_list(hostlist);
+ profile_free_list(masterlist);
return ENOMEM;
+ }
for (i=0, out=0; hostlist[i]; i++) {
host = hostlist[i];
}
if ((hp = gethostbyname(hostlist[i])) == 0) {
- free(hostlist[i]);
- hostlist[i] = 0;
continue;
}
addr_p = (struct sockaddr *)
realloc ((char *)addr_p,
sizeof(struct sockaddr) * count);
- if (addr_p == NULL)
+ if (addr_p == NULL) {
+ profile_free_list(hostlist);
+ profile_free_list(masterlist);
return ENOMEM;
+ }
}
if (sec_udpport && !port) {
addr_p[out] = addr_p[out-1];
}
if (ismaster)
*nmasters = out - *master_index;
-
- /* Free the hostlist entry we are looping over. */
- free(hostlist[i]);
- hostlist[i] = 0;
}
- if (masterlist) {
- for (i=0; masterlist[i]; i++)
- free(masterlist[i]);
- free(masterlist);
- }
-
- free ((char *)hostlist);
+ profile_free_list(hostlist);
+ profile_free_list(masterlist);
if (out == 0) { /* Couldn't resolve any KDC names */
free (addr_p);
#ifdef KRB5_DNS_LOOKUP
if (code) {
- int use_dns=0;
- char * string=NULL;
- krb5_error_code code2; /* preserve error code from krb5_locate_srv_conf */
-
- code2 = profile_get_string(context->profile, "libdefaults",
- "dns_fallback", 0,
- context->profile_in_memory?"1":"0",
- &string);
- if ( code2 )
- return(code2);
-
- if ( string ) {
- use_dns = krb5_conf_boolean(string);
- free(string);
- }
+ int use_dns = _krb5_use_dns(context);
if ( use_dns ) {
code = krb5_locate_srv_dns(realm, "_kerberos", "_udp",
addr_pp, naddrs);
char **domain;
{
krb5_error_code retval;
+ char *temp_domain = 0;
retval = profile_get_string(context->profile, "realms", realm,
- "default_domain", realm, domain);
+ "default_domain", realm, &temp_domain);
+ if (!retval && temp_domain)
+ {
+ *domain = malloc(strlen(temp_domain) + 1);
+ if (!*domain) {
+ retval = ENOMEM;
+ } else {
+ strcpy(*domain, temp_domain);
+ }
+ profile_release_string(temp_domain);
+ }
return retval;
}
}
if (hostlist[0] == 0) {
printf(" (none)\n");
- free(hostlist);
+ krb5_free_krbhst(ctx, hostlist);
return;
}
for (cpp = hostlist; *cpp; cpp++) {
printf(" '%s'", *cpp);
- free(*cpp);
}
- free(hostlist);
+ krb5_free_krbhst(ctx, hostlist);
printf("\n");
}