From: Paul Park Date: Fri, 23 Jun 1995 13:59:17 +0000 (+0000) Subject: Add alternate profile routines X-Git-Tag: krb5-1.0-beta6~1679 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ce94caed528bf25b4bbec4a418950653bbf22a54;p=krb5.git Add alternate profile routines git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6135 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/include/krb5/adm_proto.h b/src/include/krb5/adm_proto.h index a8c593261..5e695f9da 100644 --- a/src/include/krb5/adm_proto.h +++ b/src/include/krb5/adm_proto.h @@ -128,4 +128,17 @@ krb5_error_code krb5_klog_init krb5_boolean)); void krb5_klog_close KRB5_PROTOTYPE((krb5_context)); int krb5_klog_syslog KRB5_PROTOTYPE((int, const char *, ...)); + +/* alt_prof.c */ +krb5_error_code krb5_aprof_init + KRB5_PROTOTYPE((char *, char *, krb5_pointer *)); +krb5_error_code krb5_aprof_getvals + KRB5_PROTOTYPE((krb5_pointer, char **, char ***)); +krb5_error_code krb5_aprof_get_deltat + KRB5_PROTOTYPE((krb5_pointer, char **, krb5_boolean, krb5_deltat *)); +krb5_error_code krb5_aprof_get_string + KRB5_PROTOTYPE((krb5_pointer, char **, krb5_boolean, char **)); +krb5_error_code krb5_aprof_get_int32 + KRB5_PROTOTYPE((krb5_pointer, char **, krb5_boolean, krb5_int32 *)); +krb5_error_code krb5_aprof_finish KRB5_PROTOTYPE((krb5_pointer)); #endif /* KRB5_ADM_PROTO_H__ */ diff --git a/src/lib/kadm/ChangeLog b/src/lib/kadm/ChangeLog index bf568b92a..681f3e21f 100644 --- a/src/lib/kadm/ChangeLog +++ b/src/lib/kadm/ChangeLog @@ -1,4 +1,11 @@ +Thu Jun 22 11:56:15 EDT 1995 Paul Park (pjpark@mit.edu) + * alt_prof.c - New jacket routines for handling profiles. This includes + the ability to parse certain string values to appropriate types + (e.g. delta time or 32-bit integer). + * Makefile.in - Add alt_prof.c + + Thu Jun 15 18:03:40 EDT 1995 Paul Park (pjpark@mit.edu) * Makefile.in - Remove explicit copying of archive library to library directory. diff --git a/src/lib/kadm/Makefile.in b/src/lib/kadm/Makefile.in index 86470df43..a0f65b5b5 100644 --- a/src/lib/kadm/Makefile.in +++ b/src/lib/kadm/Makefile.in @@ -8,7 +8,8 @@ LDFLAGS = -g BASE_OBJS= adm_conn.$(OBJEXT) \ adm_kt_dec.$(OBJEXT) \ adm_kt_enc.$(OBJEXT) \ - adm_rw.$(OBJEXT) + adm_rw.$(OBJEXT) \ + alt_prof.$(OBJEXT) UNIX_OBJS = logger.$(OBJEXT) @@ -23,7 +24,8 @@ SRCS= $(srcdir)/adm_conn.c \ $(srcdir)/adm_rw.c \ $(srcdir)/adm_kw_dec.c \ $(srcdir)/adm_kw_enc.c \ - $(srcdir)/logger.c + $(srcdir)/logger.c \ + $(srcdir)/alt_prof.c all:: all-$(WHAT) $(BASE_OBJS) diff --git a/src/lib/kadm/alt_prof.c b/src/lib/kadm/alt_prof.c new file mode 100644 index 000000000..0b112bce7 --- /dev/null +++ b/src/lib/kadm/alt_prof.c @@ -0,0 +1,300 @@ +/* + * lib/kadm/alt_prof.c + * + * Copyright 1995 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + */ + +/* + * alt_prof.c - Implement alternate profile file handling. + * + * XXX is this really necessary? + */ +#include "krb5.h" +#include "profile.h" +#include + +/* + * krb5_aprof_init() - Initialize alternate profile context. + * + * Parameters: + * fname - default file name of the profile. + * envname - environment variable name which can override fname. + * acontextp - Pointer to opaque context for alternate profile. + * + * Returns: + * error codes from profile_init() + */ +krb5_error_code +krb5_aprof_init(fname, envname, acontextp) + char *fname; + char *envname; + krb5_pointer *acontextp; +{ + krb5_error_code kret; + char *namelist[2]; + profile_t profile; + extern char *getenv PROTOTYPE((char *)); + + namelist[1] = (char *) NULL; + profile = (profile_t) NULL; + if (envname) { + if (namelist[0] = getenv(envname)) { + if (!(kret = profile_init(namelist, &profile))) { + *acontextp = (krb5_pointer) profile; + return(0); + } + } + } + namelist[0] = fname; + profile = (profile_t) NULL; + if (!(kret = profile_init(namelist, &profile))) { + *acontextp = (krb5_pointer) profile; + return(0); + } + return(kret); +} + +/* + * krb5_aprof_getvals() - Get values from alternate profile. + * + * Parameters: + * acontext - opaque context for alternate profile. + * hierarchy - hierarchy of value to retrieve. + * retdata - Returned data values. + * + * Returns: + * error codes from profile_get_values() + */ +krb5_error_code +krb5_aprof_getvals(acontext, hierarchy, retdata) + krb5_pointer acontext; + char **hierarchy; + char ***retdata; +{ + return(profile_get_values((profile_t) acontext, + hierarchy, + retdata)); +} + +/* + * krb5_aprof_get_deltat() - Get a delta time value from the alternate + * profile. + * + * Parameters: + * acontext - opaque context for alternate profile. + * hierarchy - hierarchy of value to retrieve. + * uselast - if true, use last value, otherwise use + * first value found. + * deltatp - returned delta time value. + * + * Returns: + * error codes from profile_get_values() + * EINVAL - Invalid syntax. + * + * Valid formats are: + * -:: + * d h m s + * :: + * h m s + * : + * h m + * + */ +krb5_error_code +krb5_aprof_get_deltat(acontext, hierarchy, uselast, deltatp) + krb5_pointer acontext; + char **hierarchy; + krb5_boolean uselast; + krb5_deltat *deltatp; +{ + krb5_error_code kret; + char **values; + char *valp; + int index; + krb5_boolean found; + int days, hours, minutes, seconds; + krb5_deltat dt; + + if (!(kret = krb5_aprof_getvals(acontext, hierarchy, &values))) { + index = 0; + if (uselast) { + for (index=0; values[index]; index++); + index--; + } + valp = values[index]; + days = hours = minutes = seconds = 0; + found = 0; + + /* + * Blast our way through potential syntaxes until we find a match. + */ + if (sscanf(valp, "%d-%d:%d:%d", &days, &hours, &minutes, &seconds) + == 4) + found = 1; + else if (sscanf(valp, "%dd %dh %dm %ds", + &days, &hours, &minutes, &seconds) == 4) + found = 1; + else if (sscanf(valp, "%d:%d:%d", &hours, &minutes, &seconds) == 3) { + found = 1; + days = 0; + } + else if (sscanf(valp, "%dh %dm %ds", &hours, &minutes, &seconds) + == 3) { + found = 1; + days = 0; + } + else if (sscanf(valp, "%d:%d", &hours, &minutes) == 2) { + found = 1; + days = seconds = 0; + } + else if (sscanf(valp, "%dh %dm", &hours, &minutes) == 2) { + found = 1; + days = seconds = 0; + } + else if (sscanf(valp, "%d", &seconds) == 1) { + found = 1; + days = hours = minutes = 0; + } + + /* If found, calculate the delta value */ + if (found) { + dt = days; + dt *= 24; + dt += hours; + dt *= 60; + dt += minutes; + dt *= 60; + dt += seconds; + *deltatp = dt; + } + else + kret = EINVAL; + + /* Free the string storage */ + for (index=0; values[index]; index++) + krb5_xfree(values[index]); + krb5_xfree(values); + } + return(kret); +} + +/* + * krb5_aprof_get_string() - Get a string value from the alternate + * profile. + * + * Parameters: + * acontext - opaque context for alternate profile. + * hierarchy - hierarchy of value to retrieve. + * uselast - if true, use last value, otherwise use + * first value found. + * stringp - returned string value. + * + * Returns: + * error codes from profile_get_values() + */ +krb5_error_code +krb5_aprof_get_string(acontext, hierarchy, uselast, stringp) + krb5_pointer acontext; + char **hierarchy; + krb5_boolean uselast; + char **stringp; +{ + krb5_error_code kret; + char **values; + int index, i; + + if (!(kret = krb5_aprof_getvals(acontext, hierarchy, &values))) { + index = 0; + if (uselast) { + for (index=0; values[index]; index++); + index--; + } + + *stringp = values[index]; + + /* Free the string storage */ + for (i=0; values[i]; i++) + if (i != index) + krb5_xfree(values[i]); + krb5_xfree(values); + } + return(kret); +} + +/* + * krb5_aprof_get_int32() - Get a 32-bit integer value from the alternate + * profile. + * + * Parameters: + * acontext - opaque context for alternate profile. + * hierarchy - hierarchy of value to retrieve. + * uselast - if true, use last value, otherwise use + * first value found. + * intp - returned 32-bit integer value. + * + * Returns: + * error codes from profile_get_values() + * EINVAL - value is not an integer + */ +krb5_error_code +krb5_aprof_get_int32(acontext, hierarchy, uselast, intp) + krb5_pointer acontext; + char **hierarchy; + krb5_boolean uselast; + krb5_int32 *intp; +{ + krb5_error_code kret; + char **values; + int index; + + if (!(kret = krb5_aprof_getvals(acontext, hierarchy, &values))) { + index = 0; + if (uselast) { + for (index=0; values[index]; index++); + index--; + } + + if (sscanf(values[index], "%d", intp) != 1) + kret = EINVAL; + + /* Free the string storage */ + for (index=0; values[index]; index++) + krb5_xfree(values[index]); + krb5_xfree(values); + } + return(kret); +} + +/* + * krb5_aprof_finish() - Finish alternate profile context. + * + * Parameter: + * acontext - opaque context for alternate profile. + * + * Returns: + * 0 on success, something else on failure. + */ +krb5_error_code +krb5_aprof_finish(acontext) + krb5_pointer acontext; +{ + profile_release(acontext); +}