aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanilo Almeida <dalmeida@mit.edu>1999-08-05 20:37:18 +0000
committerDanilo Almeida <dalmeida@mit.edu>1999-08-05 20:37:18 +0000
commit300ef32ed9238d8728b427a0379cfc685f247e7f (patch)
tree68a734c09c0cdeb9f266cb00a07fa0eb3889fd2a /src
parentfb112355a2d57fffc76e66437083f9c6261acfd1 (diff)
downloadkrb5-300ef32ed9238d8728b427a0379cfc685f247e7f.zip
krb5-300ef32ed9238d8728b427a0379cfc685f247e7f.tar.gz
krb5-300ef32ed9238d8728b427a0379cfc685f247e7f.tar.bz2
* 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. * 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
Diffstat (limited to 'src')
-rw-r--r--src/lib/krb5/os/ChangeLog40
-rw-r--r--src/lib/krb5/os/an_to_ln.c12
-rw-r--r--src/lib/krb5/os/changepw.c4
-rw-r--r--src/lib/krb5/os/def_realm.c31
-rw-r--r--src/lib/krb5/os/get_krbhst.c28
-rw-r--r--src/lib/krb5/os/hst_realm.c32
-rw-r--r--src/lib/krb5/os/init_os_ctx.c17
-rw-r--r--src/lib/krb5/os/ktdefname.c2
-rw-r--r--src/lib/krb5/os/locate_kdc.c66
-rw-r--r--src/lib/krb5/os/realm_dom.c13
-rw-r--r--src/lib/krb5/os/t_std_conf.c5
11 files changed, 158 insertions, 92 deletions
diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog
index 9982029..1cd8f2c 100644
--- a/src/lib/krb5/os/ChangeLog
+++ b/src/lib/krb5/os/ChangeLog
@@ -1,3 +1,43 @@
+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
diff --git a/src/lib/krb5/os/an_to_ln.c b/src/lib/krb5/os/an_to_ln.c
index 39103c8..39528d2 100644
--- a/src/lib/krb5/os/an_to_ln.c
+++ b/src/lib/krb5/os/an_to_ln.c
@@ -688,10 +688,7 @@ krb5_aname_to_localname(context, aname, lnsize, lname)
/* 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])];
@@ -706,8 +703,7 @@ krb5_aname_to_localname(context, aname, lnsize, lname)
kret = KRB5_CONFIG_NOTENUFSPACE;
/* Free residue */
- krb5_xfree(mapping_values[nvalid-1]);
- krb5_xfree(mapping_values);
+ profile_free_list(mapping_values);
}
else {
/*
@@ -779,9 +775,7 @@ krb5_aname_to_localname(context, aname, lnsize, lname)
}
/* 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 {
/*
diff --git a/src/lib/krb5/os/changepw.c b/src/lib/krb5/os/changepw.c
index e159f20..779fc89 100644
--- a/src/lib/krb5/os/changepw.c
+++ b/src/lib/krb5/os/changepw.c
@@ -180,9 +180,7 @@ krb5_change_password(context, creds, newpw, result_code,
}
}
- 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);
diff --git a/src/lib/krb5/os/def_realm.c b/src/lib/krb5/os/def_realm.c
index 690dcc6..44a4e93 100644
--- a/src/lib/krb5/os/def_realm.c
+++ b/src/lib/krb5/os/def_realm.c
@@ -57,7 +57,7 @@ krb5_get_default_realm(context, lrealm)
krb5_context context;
char FAR * FAR *lrealm;
{
- char *realm;
+ char *realm = 0;
char *cp;
krb5_error_code retval;
@@ -74,24 +74,21 @@ krb5_get_default_realm(context, lrealm)
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
diff --git a/src/lib/krb5/os/get_krbhst.c b/src/lib/krb5/os/get_krbhst.c
index 473a02a..c929bba 100644
--- a/src/lib/krb5/os/get_krbhst.c
+++ b/src/lib/krb5/os/get_krbhst.c
@@ -63,6 +63,9 @@ krb5_get_krbhst(context, realm, hostlist)
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;
@@ -95,7 +98,26 @@ krb5_get_krbhst(context, realm, hostlist)
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;
}
diff --git a/src/lib/krb5/os/hst_realm.c b/src/lib/krb5/os/hst_realm.c
index 3bd766e..bda5e37 100644
--- a/src/lib/krb5/os/hst_realm.c
+++ b/src/lib/krb5/os/hst_realm.c
@@ -230,7 +230,7 @@ krb5_get_host_realm(context, host, realmsp)
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];
@@ -265,12 +265,13 @@ krb5_get_host_realm(context, host, realmsp)
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 */
@@ -284,24 +285,19 @@ krb5_get_host_realm(context, host, realmsp)
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
diff --git a/src/lib/krb5/os/init_os_ctx.c b/src/lib/krb5/os/init_os_ctx.c
index 04d10be..a9c69b3 100644
--- a/src/lib/krb5/os/init_os_ctx.c
+++ b/src/lib/krb5/os/init_os_ctx.c
@@ -321,24 +321,27 @@ os_init_paths(ctx, secure)
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;
diff --git a/src/lib/krb5/os/ktdefname.c b/src/lib/krb5/os/ktdefname.c
index 0493244..d8f3946 100644
--- a/src/lib/krb5/os/ktdefname.c
+++ b/src/lib/krb5/os/ktdefname.c
@@ -60,7 +60,7 @@ krb5_kt_default_name(context, name, namesize)
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)
{
diff --git a/src/lib/krb5/os/locate_kdc.c b/src/lib/krb5/os/locate_kdc.c
index ee81f6c..2c99a2c 100644
--- a/src/lib/krb5/os/locate_kdc.c
+++ b/src/lib/krb5/os/locate_kdc.c
@@ -46,6 +46,30 @@
#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 */
/*
@@ -114,6 +138,7 @@ krb5_locate_srv_conf(context, realm, name, addr_pp, naddrs, master_index, nmaste
count++;
if (count == 0) {
+ profile_free_list(hostlist);
krb5_xfree(host);
*naddrs = 0;
return 0;
@@ -165,8 +190,11 @@ krb5_locate_srv_conf(context, realm, name, addr_pp, naddrs, master_index, nmaste
#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];
@@ -186,8 +214,6 @@ krb5_locate_srv_conf(context, realm, name, addr_pp, naddrs, master_index, nmaste
}
if ((hp = gethostbyname(hostlist[i])) == 0) {
- free(hostlist[i]);
- hostlist[i] = 0;
continue;
}
@@ -218,8 +244,11 @@ krb5_locate_srv_conf(context, realm, name, addr_pp, naddrs, master_index, nmaste
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];
@@ -234,19 +263,10 @@ krb5_locate_srv_conf(context, realm, name, addr_pp, naddrs, master_index, nmaste
}
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);
@@ -550,21 +570,7 @@ krb5_locate_kdc(context, realm, addr_pp, naddrs, master_index, nmasters)
#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);
diff --git a/src/lib/krb5/os/realm_dom.c b/src/lib/krb5/os/realm_dom.c
index 8880c58..3d0b64e 100644
--- a/src/lib/krb5/os/realm_dom.c
+++ b/src/lib/krb5/os/realm_dom.c
@@ -49,8 +49,19 @@ krb5_get_realm_domain(context, realm, domain)
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;
}
diff --git a/src/lib/krb5/os/t_std_conf.c b/src/lib/krb5/os/t_std_conf.c
index c47072c..0846b1c 100644
--- a/src/lib/krb5/os/t_std_conf.c
+++ b/src/lib/krb5/os/t_std_conf.c
@@ -93,14 +93,13 @@ void test_get_krbhst(ctx, realm)
}
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");
}