#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);
}
#include <netinet/in.h>
#include <arpa/inet.h>
+#include "os-proto.h"
+
void test_get_default_realm(ctx)
krb5_context ctx;
{
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;
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;
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;
{
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;
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;