diff options
author | Greg Hudson <ghudson@mit.edu> | 2010-05-18 17:19:15 +0000 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 2010-05-18 17:19:15 +0000 |
commit | 89621595e15af56f8e4fcf7b635c2cedd0e4043a (patch) | |
tree | c7d09e5d365989b5750bbd9d0e603c7af8b540c8 /src/lib/kadm5 | |
parent | 491a660dfab0748f7468564c44c24bea839eb3be (diff) | |
download | krb5-89621595e15af56f8e4fcf7b635c2cedd0e4043a.zip krb5-89621595e15af56f8e4fcf7b635c2cedd0e4043a.tar.gz krb5-89621595e15af56f8e4fcf7b635c2cedd0e4043a.tar.bz2 |
When parsing a KDC or admin server string, allow the name or address
to be enclosed in brackets so that IPv6 addresses can be represented.
(IPv6 addresses contain colons, which look like port separators.)
ticket: 6562
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24055 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/kadm5')
-rw-r--r-- | src/lib/kadm5/alt_prof.c | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/lib/kadm5/alt_prof.c b/src/lib/kadm5/alt_prof.c index c8dc307..bc5eb23 100644 --- a/src/lib/kadm5/alt_prof.c +++ b/src/lib/kadm5/alt_prof.c @@ -482,6 +482,36 @@ get_deltat_param(krb5_deltat *param_out, krb5_deltat param_in, } /* + * Parse out the port number from an admin_server setting. Modify server to + * contain just the hostname or address. If a port is given, set *port, and + * set the appropriate bit in *mask. + */ +static void +parse_admin_server_port(char *server, int *port, long *mask) +{ + char *end, *portstr; + + /* Allow the name or addr to be enclosed in brackets, for IPv6 addrs. */ + if (*server == '[' && (end = strchr(server + 1, ']')) != NULL) { + portstr = (*(end + 1) == ':') ? end + 2 : NULL; + /* Shift the bracketed name or address back into server. */ + memmove(server, server + 1, end - (server + 1)); + *(end - 1) = '\0'; + } else { + /* Terminate the name at the colon, if any. */ + end = server + strcspn(server, ":"); + portstr = (*end == ':') ? end + 1 : NULL; + *end = '\0'; + } + + /* If we found a port string, parse it and set the appropriate bit. */ + if (portstr) { + *port = atoi(portstr); + *mask |= KADM5_CONFIG_KADMIND_PORT; + } +} + +/* * Function: kadm5_get_config_params * * Purpose: Merge configuration parameters provided by the caller with @@ -581,13 +611,8 @@ krb5_error_code kadm5_get_config_params(context, use_kdc_config, NULL); if (params.mask & KADM5_CONFIG_ADMIN_SERVER) { - char *p; - p = strchr(params.admin_server, ':'); - if (p) { - params.kadmind_port = atoi(p+1); - params.mask |= KADM5_CONFIG_KADMIND_PORT; - *p = '\0'; - } + parse_admin_server_port(params.admin_server, ¶ms.kadmind_port, + ¶ms.mask); } /* Get the value for the database */ |