From 479b628dc54d7d45d76d27e91571c7a59d38348e Mon Sep 17 00:00:00 2001 From: Keith Vetter Date: Wed, 29 Mar 1995 05:06:42 +0000 Subject: [PATCH] Added functionality for windows to read default file locations from windows ini files. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5307 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/ChangeLog | 9 +++++++++ src/lib/krb5/os/ccdefname.c | 15 +++++++++++--- src/lib/krb5/os/def_realm.c | 1 + src/lib/krb5/os/get_krbhst.c | 1 + src/lib/krb5/os/hst_realm.c | 10 ++++++--- src/lib/krb5/os/osconfig.c | 39 ++++++++++++++++++++++++++++++++++++ src/lib/krb5/os/realm_dom.c | 7 ++++--- 7 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 51ba47587..69e77c55a 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,12 @@ +Tue Mar 28 19:22:28 1995 Keith Vetter (keithv@fusion.com) + + For Windows, added calls to get the default config, realms and + ccache files out of a windows ini file. + * ccdefname.c: does this for the credential cache. + * osconfig.c: does this for the config and realms files. + * get_krbh.c, realm_do.c, hst_real.c, def_real.c: added calls to + set the default values. + Tue Mar 28 18:35:20 1995 John Gilmore (gnu at toad.com) * DNR.c: Add Apple MacTCP source file for domain name resolution. diff --git a/src/lib/krb5/os/ccdefname.c b/src/lib/krb5/os/ccdefname.c index 79314a6b7..5ec4256cd 100644 --- a/src/lib/krb5/os/ccdefname.c +++ b/src/lib/krb5/os/ccdefname.c @@ -24,6 +24,7 @@ * Return default cred. cache name. */ +#define NEED_WINDOWS #include "k5-int.h" #include @@ -36,10 +37,18 @@ krb5_cc_default_name(context) if (name == 0) { if (name_buf == 0) - name_buf = malloc (35); + name_buf = malloc (160); -#ifdef MSDOS_FILESYSTEM - strcpy (name_buf, "FILE:\\krb5cc"); +#ifdef _WINDOWS + { + char defname[160]; /* Default value */ + + strcpy (defname, "FILE:"); + GetWindowsDirectory (defname+5, 160-5-7); + strcat (defname, "\\krb5cc"); + GetPrivateProfileString(INI_FILES, INI_KRB_CCACHE, defname, + name_buf, 160, KERBEROS_INI); + } #else sprintf(name_buf, "FILE:/tmp/krb5cc_%d", getuid()); #endif diff --git a/src/lib/krb5/os/def_realm.c b/src/lib/krb5/os/def_realm.c index a6f4f993b..a7634376f 100644 --- a/src/lib/krb5/os/def_realm.c +++ b/src/lib/krb5/os/def_realm.c @@ -67,6 +67,7 @@ krb5_get_default_realm(context, lrealm) else if (saved_realm) realm = saved_realm; else { + krb5_find_config_files(); if (!(config_file = fopen(krb5_config_file, "r"))) /* can't open */ return KRB5_CONFIG_CANTOPEN; diff --git a/src/lib/krb5/os/get_krbhst.c b/src/lib/krb5/os/get_krbhst.c index eeb785c0a..0a02a3805 100644 --- a/src/lib/krb5/os/get_krbhst.c +++ b/src/lib/krb5/os/get_krbhst.c @@ -75,6 +75,7 @@ krb5_get_krbhst(context, realm, hostlist) * case. */ + krb5_find_config_files(); if (!(config_file = fopen(krb5_config_file, "r"))) /* can't open */ return KRB5_CONFIG_CANTOPEN; diff --git a/src/lib/krb5/os/hst_realm.c b/src/lib/krb5/os/hst_realm.c index e43655f62..2c16267db 100644 --- a/src/lib/krb5/os/hst_realm.c +++ b/src/lib/krb5/os/hst_realm.c @@ -178,6 +178,7 @@ krb5_get_host_realm(context, host, realmsp) } } + krb5_find_config_files(); if ((trans_file = fopen(krb5_trans_file, "r")) == (FILE *) 0) { krb5_xfree(retrealms[0]); krb5_xfree(retrealms); @@ -186,12 +187,12 @@ krb5_get_host_realm(context, host, realmsp) (void) sprintf(scanstring, "%%%ds %%%ds", sizeof(trans_host)-1,sizeof(trans_realm)-1); while (1) { -#ifdef _WINDOWS + #ifdef _WINDOWS scanval = read_2str (trans_file, trans_host, sizeof(trans_host)-1, trans_realm, sizeof(trans_realm)-1); -#else + #else scanval = fscanf(trans_file, scanstring, trans_host, trans_realm); -#endif + #endif if (scanval != 2) { if (scanval == EOF) { fclose(trans_file); @@ -230,3 +231,6 @@ krb5_get_host_realm(context, host, realmsp) *realmsp = retrealms; return 0; } + + + diff --git a/src/lib/krb5/os/osconfig.c b/src/lib/krb5/os/osconfig.c index 84ec68c2f..07a3d045a 100644 --- a/src/lib/krb5/os/osconfig.c +++ b/src/lib/krb5/os/osconfig.c @@ -24,6 +24,7 @@ * Definition of default configuration parameters. */ +#define NEED_WINDOWS #include "k5-int.h" char *krb5_config_file = DEFAULT_CONFIG_FILENAME; @@ -49,3 +50,41 @@ char *krb5_kdc_sec_udp_portname = 0; char *krb5_default_pwd_prompt1 = DEFAULT_PWD_STRING1; char *krb5_default_pwd_prompt2 = DEFAULT_PWD_STRING2; + +/* + * On Windows, we want to let the user specify in the kerberos.ini file + * where the config and realms files, krb.con and krb.rea, reside. If they + * aren't specified then we fall back to having them in the windows + * directory. We use the same format as the K4 version for compatability. + * + * Note: these values can change asynchronously so we can't cache the values. + */ +krb5_error_code +krb5_find_config_files () +{ +#ifdef _WINDOWS + static char cnfname[160]; /* For krb.con */ + static char realmsname[160]; /* For krb.rea */ + char defname[160]; /* Default value */ + + /* First locate krb.con file */ + GetWindowsDirectory(defname, sizeof(defname)); + strcat (defname, "\\"); + strcat (defname, DEFAULT_CONFIG_FILENAME); + GetPrivateProfileString(INI_FILES, INI_KRB_CONF, defname, + cnfname, sizeof(cnfname), KERBEROS_INI); + + /* Now locate krb.rea file */ + GetWindowsDirectory(defname, sizeof(defname)); + strcat (defname, "\\"); + strcat (defname, DEFAULT_TRANS_FILENAME); + GetPrivateProfileString(INI_FILES, INI_KRB_REALMS, defname, + realmsname, sizeof(realmsname), KERBEROS_INI); + + krb5_config_file = cnfname; + krb5_trans_file = realmsname; + +#endif /* _WINDOWS */ + + return 0; +} diff --git a/src/lib/krb5/os/realm_dom.c b/src/lib/krb5/os/realm_dom.c index 27907ac20..92563c1f7 100644 --- a/src/lib/krb5/os/realm_dom.c +++ b/src/lib/krb5/os/realm_dom.c @@ -122,6 +122,7 @@ krb5_get_realm_domain(context, realm, domain) return retval; realm = realmlist[0]; } + krb5_find_config_files(); if ((trans_file = fopen(krb5_trans_file, "r")) == (FILE *) 0) { if (realmlist != NULL) { krb5_xfree(realmlist[0]); @@ -132,12 +133,12 @@ krb5_get_realm_domain(context, realm, domain) (void) sprintf(scanstring, "%%%ds %%%ds", sizeof(trans_host)-1,sizeof(trans_realm)-1); while (1) { -#ifdef _WINDOWS + #ifdef _WINDOWS scanval = read_2str (trans_file, trans_host, sizeof(trans_host)-1, trans_realm, sizeof(trans_realm)-1); -#else + #else scanval = fscanf(trans_file, scanstring, trans_host, trans_realm); -#endif + #endif if (scanval != 2) { if (scanval == EOF) { fclose(trans_file); -- 2.26.2