aboutsummaryrefslogtreecommitdiff
path: root/src/lib/krb5/os/ccdefname.c
diff options
context:
space:
mode:
authorTheodore Tso <tytso@mit.edu>1999-02-02 04:27:33 +0000
committerTheodore Tso <tytso@mit.edu>1999-02-02 04:27:33 +0000
commit19083c2a7626f485a3605779024aa776926d6786 (patch)
tree3892caf267274828e51fc3658a9cd19aaa34bcc3 /src/lib/krb5/os/ccdefname.c
parentb28c1bca371582d924b06d7a618b20c5cce5359c (diff)
downloadkrb5-19083c2a7626f485a3605779024aa776926d6786.zip
krb5-19083c2a7626f485a3605779024aa776926d6786.tar.gz
krb5-19083c2a7626f485a3605779024aa776926d6786.tar.bz2
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. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11140 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/krb5/os/ccdefname.c')
-rw-r--r--src/lib/krb5/os/ccdefname.c223
1 files changed, 109 insertions, 114 deletions
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);
}