diff options
-rw-r--r-- | src/lib/krb5/os/ChangeLog | 16 | ||||
-rw-r--r-- | src/lib/krb5/os/ccdefname.c | 223 | ||||
-rw-r--r-- | src/lib/krb5/os/t_std_conf.c | 46 |
3 files changed, 166 insertions, 119 deletions
diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 8378d42..69e04b0 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,19 @@ +1999-01-29 Theodore Ts'o <tytso@rsts-11.mit.edu> + + * ccdefname.c: Add a new function krb5_cc_set_default_name(), + which is used set the default ccname stored in the + krb5_context. All of the OS-specific functions to + determine the default ccname is moved to this function. + The krb5_cc_default_name() function now just reads the + default ccname from the os_context, and will call + krb5_cc_set_default_name() to set the default ccname if + necessary. + + * t_std_conf: Added functions to test krb5_cc_default_name and + krb5_cc_set_default_name(). Fixed the call to + krb5_locate_kdc to support the new variables added by + the Cygnus initial ticket API merge. + 1999-01-27 Theodore Ts'o <tytso@rsts-11.mit.edu> * localaddr.c: On the macintosh, check to see if getmyipaddr diff --git a/src/lib/krb5/os/ccdefname.c b/src/lib/krb5/os/ccdefname.c index d782f94..ca82c9c 100644 --- a/src/lib/krb5/os/ccdefname.c +++ b/src/lib/krb5/os/ccdefname.c @@ -28,136 +28,131 @@ #include "k5-int.h" #include <stdio.h> -#ifdef macintosh -static CInfoPBRec theCatInfo; -static char *FileBuffer; -static int indexCount; -static FSSpec theWorkingFile; - -static char* -GetDirName(short vrefnum, long dirid, char *dststr) +#if defined(_WIN32) +static int get_from_registry(char *name_buf, int name_size) { -CInfoPBRec theCatInfo; -FSSpec theParDir; -char str[37]; -char *curstr; -OSErr err; - // Get info on the directory itself, it's name and it's parent - theCatInfo.dirInfo.ioCompletion = NULL; - theCatInfo.dirInfo.ioNamePtr = (StringPtr) str; - theCatInfo.dirInfo.ioVRefNum = vrefnum; - theCatInfo.dirInfo.ioFDirIndex = -1; - theCatInfo.dirInfo.ioDrDirID = dirid; - err = PBGetCatInfoSync(&theCatInfo); - - // If I'm looking at the root directory and I've tried going up once - // start returning down the call chain - if (err != noErr || (dirid == 2 && theCatInfo.hFileInfo.ioFlParID == 2)) - return dststr; - - // Construct a file spec for the parent - curstr = GetDirName(theCatInfo.dirInfo.ioVRefNum, theCatInfo.hFileInfo.ioFlParID, dststr); + /* If the RegKRB5CCNAME variable is set, it will point to + * the registry key that has the name of the cache to use. + * The Gradient PC-DCE sets the registry key + * [HKEY_CURRENT_USER\Software\Gradient\DCE\Default\KRB5CCNAME] + * to point at the cache file name (including the FILE: prefix). + * By indirecting with the RegKRB5CCNAME entry in kerberos.ini, + * we can accomodate other versions that might set a registry + * variable. + */ + char newkey[256]; + + LONG name_buf_size; + HKEY hkey; + DWORD ipType; + int found = 0; + char *cp; - // Copy the pascal string to the end of a C string - BlockMoveData(&str[1], curstr, str[0]); - curstr += str[0]; - *curstr++ = ':'; + GetPrivateProfileString(INI_FILES, "RegKRB5CCNAME", "", + newkey, sizeof(newkey), KERBEROS_INI); + if (!newkey[0]) + return 0; + + cp = strrchr(newkey,'\\'); + if (cp) { + *cp = '\0'; /* split the string */ + cp++; + } else + cp = ""; - // return a pointer to the end of the string (for someone below to append to) - return curstr; + if (RegOpenKeyEx(HKEY_CURRENT_USER, newkey, 0, + KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) + return 0; + + name_buf_size = name_size; + if (RegQueryValueEx(hkey, cp, 0, &ipType, + name_buf, &name_buf_size) != ERROR_SUCCESS) + return 0; + + return 1; } +#endif -static void -GetPathname(FSSpec *theFile, char *dststr) +#ifdef macintosh +static krb5_error_code get_from_os(char *name_buf, int name_size) { -FSSpec theParDir; -char *curstr; -OSErr err; +#if defined(_WIN32) + if (get_from_registry(name_buf, name_size)) + return 0; +#endif + strcpy(name_buf, "API:default_cache_name"); + return 0; +} +#endif + +#if defined(_MSDOS) || defined(_WIN32) +static krb5_error_code get_from_os(char *name_buf, int name_size) +{ + char defname[160]; /* Default value */ + + strcpy (defname, "default_cache_name"); + strcpy (name_buf, "API:"); + GetPrivateProfileString(INI_FILES, INI_KRB_CCACHE, defname, + name_buf+4, name_size-4, KERBEROS_INI); + return 0; +} +#endif - // Start crawling up the directory path recursivly - curstr = GetDirName(theFile->vRefNum, theFile->parID, dststr); - BlockMoveData(&theFile->name[1], curstr, theFile->name[0]); - curstr += theFile->name[0]; - *curstr = 0; +#if !(defined(_MSDOS) || defined(_WIN32) || defined(macintosh)) +static krb5_error_code get_from_os(char *name_buf, int name_size) +{ + sprintf(name_buf, "FILE:/tmp/krb5cc_%d", getuid()); + return 0; } #endif +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_set_default_name(context, name) + krb5_context context; + const char *name; +{ + char name_buf[1024]; + char *new_name; + krb5_error_code retval; + krb5_os_context os_ctx; + + os_ctx = context->os_context; + + if (!name) + name = getenv(KRB5_ENV_CCNAME); + + if (name) { + strncpy(name_buf, name, sizeof(name_buf)); + name_buf[sizeof(name_buf)-1] = 0; + } else { + retval = get_from_os(name_buf, sizeof(name_buf)); + if (retval) + return retval; + } + new_name = malloc(strlen(name_buf)+1); + if (!new_name) + return ENOMEM; + strcpy(new_name, name_buf); + + if (os_ctx->default_ccname) + free(os_ctx->default_ccname); + + os_ctx->default_ccname = new_name; + return 0; +} + + KRB5_DLLIMP const char FAR * KRB5_CALLCONV krb5_cc_default_name(context) krb5_context context; { - char *name = getenv(KRB5_ENV_CCNAME); - static char name_buf[160]; - - if (name == 0) { - -#ifdef macintosh -{ - strcpy (name_buf, "API:default_cache_name"); -} -#else -#if defined(_MSDOS) || defined(_WIN32) - { - char defname[160]; /* Default value */ + krb5_os_context os_ctx; -#if defined(_WIN32) - /* If the RegKRB5CCNAME variable is set, it will point to - * the registry key that has the name of the cache to use. - * The Gradient PC-DCE sets the registry key - * [HKEY_CURRENT_USER\Software\Gradient\DCE\Default\KRB5CCNAME] - * to point at the cache file name (including the FILE: prefix). - * By indirecting with the RegKRB5CCNAME entry in kerberos.ini, - * we can accomodate other versions that might set a registry - * variable. - */ - char newkey[256]; - - LONG name_buf_size; - HKEY hkey; - DWORD ipType; - int found = 0; - char *cp; - + os_ctx = context->os_context; + if (!os_ctx->default_ccname) + krb5_cc_set_default_name(context, NULL); - GetPrivateProfileString(INI_FILES, "RegKRB5CCNAME", "", - newkey, sizeof(newkey), KERBEROS_INI); - if (strlen(newkey)) { - cp = strrchr(newkey,'\\'); - if (cp) { - *cp = '\0'; /* split the string */ - cp++; - } else - cp = ""; - if (RegOpenKeyEx(HKEY_CURRENT_USER, newkey, 0, - KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) { - name_buf_size = sizeof(name_buf); - if (RegQueryValueEx(hkey, cp, 0, &ipType, - name_buf, &name_buf_size) - == ERROR_SUCCESS) - found = 1; - } - } - if(!(found)) { -#endif - - //GetWindowsDirectory (defname, sizeof(defname)-7); - strcpy (defname, "default_cache_name"); - strcpy (name_buf, "API:"); - GetPrivateProfileString(INI_FILES, INI_KRB_CCACHE, defname, - name_buf+4, sizeof(name_buf)-4, - KERBEROS_INI); -#if defined(_WIN32) - } -#endif - } -#else - /* Default for Unix systems */ - sprintf(name_buf, "FILE:/tmp/krb5cc_%d", getuid()); -#endif -#endif - name = name_buf; - } - return name; + return(os_ctx->default_ccname); } diff --git a/src/lib/krb5/os/t_std_conf.c b/src/lib/krb5/os/t_std_conf.c index 5e61510..c47072c 100644 --- a/src/lib/krb5/os/t_std_conf.c +++ b/src/lib/krb5/os/t_std_conf.c @@ -14,6 +14,8 @@ #include <netinet/in.h> #include <arpa/inet.h> +#include "os-proto.h" + void test_get_default_realm(ctx) krb5_context ctx; { @@ -43,6 +45,32 @@ void test_set_default_realm(ctx, realm) printf("krb5_set_default_realm(%s)\n", realm); } +void test_get_default_ccname(ctx) + krb5_context ctx; +{ + const char *ccname; + + ccname = krb5_cc_default_name(ctx); + if (ccname) + printf("krb5_cc_default_name() returned '%s'\n", ccname); + else + printf("krb5_cc_default_name() returned NULL\n"); +} + +void test_set_default_ccname(ctx, ccname) + krb5_context ctx; + char *ccname; +{ + krb5_error_code retval; + + retval = krb5_cc_set_default_name(ctx, ccname); + if (retval) { + com_err("krb5_set_default_ccname", retval, 0); + return; + } + printf("krb5_set_default_ccname(%s)\n", ccname); +} + void test_get_krbhst(ctx, realm) krb5_context ctx; char *realm; @@ -83,12 +111,14 @@ void test_locate_kdc(ctx, realm) struct sockaddr *addrs; struct sockaddr_in *sin; int i, naddrs; + int master_index, nmasters; krb5_data rlm; krb5_error_code retval; rlm.data = realm; rlm.length = strlen(realm); - retval = krb5_locate_kdc(ctx, &rlm, &addrs, &naddrs); + retval = krb5_locate_kdc(ctx, &rlm, &addrs, &naddrs, + &master_index, &nmasters); if (retval) { com_err("krb5_get_krbhst", retval, 0); return; @@ -152,12 +182,12 @@ void test_get_realm_domain(ctx, realm) void usage(progname) char *progname; { - fprintf(stderr, "%s: Usage: %s [-d] [-k realm] [-r host] [-D realm]\n", + fprintf(stderr, "%s: Usage: %s [-dc] [-k realm] [-r host] [-C ccname] [-D realm]\n", progname, progname); exit(1); } -main(argc, argv) +int main(argc, argv) int argc; char **argv; { @@ -168,13 +198,16 @@ main(argc, argv) retval = krb5_init_context(&ctx); if (retval) { - fprintf(stderr, "krb5_init_context returned error %ld\n", + fprintf(stderr, "krb5_init_context returned error %u\n", retval); exit(1); } - while ((c = getopt(argc, argv, "dk:r:D:l:s:")) != -1) { + while ((c = getopt(argc, argv, "cdk:r:C:D:l:s:")) != -1) { switch (c) { + case 'c': /* Get default ccname */ + test_get_default_ccname(ctx); + break; case 'd': /* Get default realm */ test_get_default_realm(ctx); break; @@ -190,6 +223,9 @@ main(argc, argv) case 's': test_set_default_realm(ctx, optarg); break; + case 'C': + test_set_default_ccname(ctx, optarg); + break; case 'D': test_get_realm_domain(ctx, optarg); break; |