From 551b55bd3887f8108c5cde71cddf686a078f5bb0 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Wed, 7 Jun 1995 19:22:30 +0000 Subject: [PATCH] def_realm.c (krb5_get_default_realm), get_krbhst.c (krb5_get_krbhst), hst_realm.c (krb5_get_host_realm), init_os_ctx.c (krb5_os_init_context), osconfig.c, realm_dom.c (krb5_get_realm_domain): Remove old ifdef'ed code which read in krb.conf and krb.realms. read_pwd.c (krb5_read_password): Remove old #ifdef notdef code. Significantly simplified and cleaned up function. Removed BSD 4.3 compatibility code. (If we ever need to make this work on a non-POSIX system, we'll supply POSIX termios emulation functions in src/lib/krb5/posix.) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5964 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/ChangeLog | 14 +++ src/lib/krb5/os/def_realm.c | 31 ------- src/lib/krb5/os/get_krbhst.c | 105 ---------------------- src/lib/krb5/os/hst_realm.c | 161 ---------------------------------- src/lib/krb5/os/init_os_ctx.c | 3 +- src/lib/krb5/os/osconfig.c | 47 ---------- src/lib/krb5/os/read_pwd.c | 151 ++++++------------------------- src/lib/krb5/os/realm_dom.c | 144 ------------------------------ 8 files changed, 44 insertions(+), 612 deletions(-) diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 238672c61..788a5e7bd 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,17 @@ +Wed Jun 7 14:43:56 1995 + + * def_realm.c (krb5_get_default_realm), get_krbhst.c + (krb5_get_krbhst), hst_realm.c (krb5_get_host_realm), + init_os_ctx.c (krb5_os_init_context), osconfig.c, + realm_dom.c (krb5_get_realm_domain): Remove old ifdef'ed + code which read in krb.conf and krb.realms. + + * read_pwd.c (krb5_read_password): Remove old #ifdef notdef code. + Significantly simplified and cleaned up function. + Removed BSD 4.3 compatibility code. (If we ever need + to make this work on a non-POSIX system, we'll supply + POSIX termios emulation functions in src/lib/krb5/posix.) + Fri Jun 2 17:54:12 1995 Keith Vetter (keithv@fusion.com) * net_read.c, net_write.c: made to work with sockets. diff --git a/src/lib/krb5/os/def_realm.c b/src/lib/krb5/os/def_realm.c index f028c65e4..fbff2d5ef 100644 --- a/src/lib/krb5/os/def_realm.c +++ b/src/lib/krb5/os/def_realm.c @@ -49,10 +49,6 @@ krb5_get_default_realm(context, lrealm) krb5_context context; char **lrealm; { -#ifdef OLD_CONFIG_FILE - FILE *config_file; - char realmbuf[BUFSIZ]; -#endif char *realm; char *cp; @@ -60,32 +56,6 @@ krb5_get_default_realm(context, lrealm) return KV5M_CONTEXT; if (!context->default_realm) { -#ifdef OLD_CONFIG_FILE - krb5_find_config_files(); - if (!(config_file = fopen(krb5_config_file, "r"))) - /* can't open */ - return KRB5_CONFIG_CANTOPEN; - - if (fgets(realmbuf, sizeof(realmbuf), config_file) == NULL) { - fclose(config_file); - return(KRB5_CONFIG_BADFORMAT); - } - fclose(config_file); - - realmbuf[BUFSIZ-1] = '0'; - cp = strchr(realmbuf, '\n'); - if (cp) - *cp = '\0'; - cp = strchr(realmbuf, ' '); - if (cp) - *cp = '\0'; - - context->default_realm = malloc(strlen (realmbuf) + 1); - if (!context->default_realm) - return ENOMEM; - - strcpy(context->default_realm, realmbuf); -#else /* * XXX should try to figure out a reasonable default based * on the host's DNS domain. @@ -96,7 +66,6 @@ krb5_get_default_realm(context, lrealm) &context->default_realm); if (context->default_realm == 0) return(KRB5_CONFIG_BADFORMAT); -#endif } realm = context->default_realm; diff --git a/src/lib/krb5/os/get_krbhst.c b/src/lib/krb5/os/get_krbhst.c index 2a0042bbb..473a02a3b 100644 --- a/src/lib/krb5/os/get_krbhst.c +++ b/src/lib/krb5/os/get_krbhst.c @@ -54,110 +54,6 @@ * hostname added to the list returned. */ -#ifdef OLD_CONFIG_FILES - -extern char *krb5_config_file; /* extern so can be set at - load/runtime */ - -krb5_error_code -krb5_get_krbhst(context, realm, hostlist) - krb5_context context; - const krb5_data *realm; - char ***hostlist; -{ - FILE *config_file; - char filebuf[BUFSIZ]; - krb5_error_code retval; - char *cp, *cp2; - register char **rethlist = 0; - int hlindex = 0; - int hlsize = 2; /* Always have to null terminate - * host list, so be sure there - * is enough room in the common - * case. - */ - - krb5_find_config_files(); - if (!(config_file = fopen(krb5_config_file, "r"))) - /* can't open */ - return KRB5_CONFIG_CANTOPEN; - - if (fgets(filebuf, sizeof(filebuf), config_file) == NULL) - retval = KRB5_CONFIG_BADFORMAT; - else { - retval = 0; - rethlist = (char **)calloc(hlsize, sizeof (*rethlist)); - if (rethlist == NULL) - retval = ENOMEM; - - while (retval == 0) { - if (fgets(filebuf, sizeof(filebuf), config_file) == NULL) - break; - if (strncmp(filebuf, realm->data, realm->length)) - continue; /* no match */ - - /* +1 to get beyond trailing space */ - if (strlen(filebuf) < (size_t) realm->length + 1) { - /* no hostname on config line */ - retval = KRB5_CONFIG_BADFORMAT; - break; - } - - if (!isspace(filebuf[realm->length])) { - continue; /* no match */ - } - - /* Throw away any whitespace between tokens */ - for (cp = &filebuf[realm->length + 1]; isspace(*cp); cp++); - if (! *cp) { - /* no hostname on config line */ - retval = KRB5_CONFIG_BADFORMAT; - break; - } - - /* Throw away any trailing whitespace or tokens */ - for (cp2 = cp+1; *cp2 && !isspace(*cp2); cp2++); - *cp2 = '\0'; - - rethlist[hlindex] = strdup(cp); - if (!rethlist[hlindex]) { - for (--hlindex; hlindex >= 0; hlindex--) - free(rethlist[hlindex]); - krb5_xfree(rethlist); - rethlist = 0; - retval = ENOMEM; - break; - } - - if (++hlindex >= hlsize) { - /* need larger pointer array */ - hlsize *= 2; - rethlist = (char **)realloc((char *)rethlist, - hlsize * sizeof(*rethlist)); - if (!rethlist) { - /* XXX clean up the old saved strings? - realloc might possibly trash them if it fails? */ - retval = ENOMEM; - break; - } - } - rethlist[hlindex] = 0; - } - } - (void) fclose(config_file); - - if (hlindex == 0) { - krb5_xfree(rethlist); - rethlist = 0; - if (retval == 0) - retval = KRB5_REALM_UNKNOWN; - } - *hostlist = rethlist; - - return retval; -} - -#else krb5_error_code krb5_get_krbhst(context, realm, hostlist) krb5_context context; @@ -203,4 +99,3 @@ krb5_get_krbhst(context, realm, hostlist) *hostlist = values; return 0; } -#endif diff --git a/src/lib/krb5/os/hst_realm.c b/src/lib/krb5/os/hst_realm.c index 5ce9c8229..3cd135566 100644 --- a/src/lib/krb5/os/hst_realm.c +++ b/src/lib/krb5/os/hst_realm.c @@ -77,165 +77,6 @@ #define MAXHOSTNAMELEN 64 #endif -#ifdef OLD_CONFIG_FILES - -#define DEF_REALMNAME_SIZE 256 - -extern char *krb5_trans_file; - -#ifdef _WINDOWS -/* - * Windows DLL can't use the fscanf routine. We need fscanf to read - * in the host and realm. Read_2str with read_1str duplicate the needed - * functionality. See also realm_dom.c. - */ -static int -read_1str (FILE *fp, char *buf, int buflen) { - int c; - - while (1) { - c = fgetc (fp); /* Past leading whitespace */ - if (c == EOF) - return 0; - if (! isspace (c)) - break; - } - - while (1) { - if (buflen > 0) { /* Store the character */ - *buf++ = (char) c; - --buflen; - } - if (buflen <= 0) /* Fscanf stops scanning... */ - break; /* ...when buffer is full */ - - c = fgetc (fp); /* Get next character */ - if (c == EOF || isspace (c)) - break; - } - - if (buflen) /* Make ASCIIZ if room */ - *buf = '\0'; - - return 1; -} - -static int -read_2str (FILE *fp, char *b1, int l1, char *b2, int l2) { - int n; - - n = read_1str (fp, b1, l1); /* Read first string */ - if (!n) return EOF; - n = read_1str (fp, b2, l2); /* Read second string */ - if (!n) return 1; - return 2; -} - -#endif /* _WINDOWS */ - -krb5_error_code -krb5_get_host_realm(context, host, realmsp) - krb5_context context; - const char *host; - char ***realmsp; -{ - char **retrealms; - char *domain; - FILE *trans_file; - char trans_host[MAXHOSTNAMELEN+1]; - char local_host[MAXHOSTNAMELEN+1]; - char trans_realm[DEF_REALMNAME_SIZE]; - krb5_error_code retval; - int scanval; - char scanstring[7+2*16]; /* 7 chars + 16 for each decimal - conversion */ - - if (!host) { - if (gethostname(local_host, sizeof(local_host)-1) == -1) - return errno; - local_host[sizeof(local_host)-1] = '\0'; - host = local_host; - } - domain = strchr(host, '.'); - - if (!(retrealms = (char **)calloc(2, sizeof(*retrealms)))) - return ENOMEM; - - /* prepare default */ - if (domain) { - char *cp; - - if (!(retrealms[0] = malloc(strlen(&domain[1])+1))) { - krb5_xfree(retrealms); - return ENOMEM; - } - strcpy(retrealms[0], &domain[1]); - /* Upper-case realm */ - for (cp = retrealms[0]; *cp; cp++) - if (islower(*cp)) - *cp = toupper(*cp); - } else { - if (retval = krb5_get_default_realm(context, &retrealms[0])) { - krb5_xfree(retrealms); - return retval; - } - } - - krb5_find_config_files(); - if ((trans_file = fopen(krb5_trans_file, "r")) == (FILE *) 0) { - *realmsp = retrealms; - return 0; - } - (void) sprintf(scanstring, "%%%ds %%%ds", - sizeof(trans_host)-1,sizeof(trans_realm)-1); - while (1) { -#ifdef _WINDOWS - scanval = read_2str (trans_file, trans_host, sizeof(trans_host)-1, - trans_realm, sizeof(trans_realm)-1); -#else - scanval = fscanf(trans_file, scanstring, trans_host, trans_realm); -#endif - if (scanval != 2) { - if (scanval == EOF) { - fclose(trans_file); - goto out; - } - continue; /* ignore broken lines */ - } - trans_host[sizeof(trans_host)-1] = '\0'; - trans_realm[sizeof(trans_realm)-1] = '\0'; - if (!strcasecmp(trans_host, host)) { - /* exact match of hostname, so return the realm */ - if (!(retrealms[0] = realloc(retrealms[0], - strlen(trans_realm)+1))) { - krb5_xfree(retrealms); - return ENOMEM; - } - (void) strcpy(retrealms[0], trans_realm); - fclose(trans_file); - goto out; - } - if ((trans_host[0] == '.') && domain) { - /* this is a possible domain match */ - if (!strcasecmp(trans_host, domain)) { - /* domain match, save for later */ - if (!(retrealms[0] = realloc(retrealms[0], - strlen(trans_realm)+1))) { - krb5_xfree(retrealms); - return ENOMEM; - } - (void) strcpy(retrealms[0], trans_realm); - continue; - } - } - } - out: - *realmsp = retrealms; - return 0; -} - -#else - krb5_error_code krb5_get_host_realm(context, host, realmsp) krb5_context context; @@ -306,5 +147,3 @@ krb5_get_host_realm(context, host, realmsp) *realmsp = retrealms; return 0; } - -#endif diff --git a/src/lib/krb5/os/init_os_ctx.c b/src/lib/krb5/os/init_os_ctx.c index fb4e31214..49921a900 100644 --- a/src/lib/krb5/os/init_os_ctx.c +++ b/src/lib/krb5/os/init_os_ctx.c @@ -46,7 +46,6 @@ krb5_os_init_context(ctx) ctx->os_context = (void *) os_ctx; -#ifndef OLD_CONFIG_FILES #ifdef _WINDOWS { char defname[160]; /* Default value */ @@ -78,7 +77,7 @@ krb5_os_init_context(ctx) retval = profile_init(filenames, &ctx->profile); if (retval) ctx->profile = 0; -#endif + /* * We ignore errors if the profile can not be initialized, * since there must be a way to get a context even if the diff --git a/src/lib/krb5/os/osconfig.c b/src/lib/krb5/os/osconfig.c index 95a5fd6bc..84f72bb40 100644 --- a/src/lib/krb5/os/osconfig.c +++ b/src/lib/krb5/os/osconfig.c @@ -24,15 +24,8 @@ * Definition of default configuration parameters. */ -#ifdef OLD_CONFIG_FILES -#define NEED_WINDOWS -#endif #include "k5-int.h" -#ifdef OLD_CONFIG_FILES -char *krb5_config_file = DEFAULT_CONFIG_FILENAME; -char *krb5_trans_file = DEFAULT_TRANS_FILENAME; -#endif char *krb5_defkeyname = DEFAULT_KEYTAB_NAME; #ifdef USE_DBM_LNAME char *krb5_lname_file = DEFAULT_LNAME_FILENAME; @@ -46,43 +39,3 @@ int krb5_skdc_timeout_1 = SKDC_TIMEOUT_1; char *krb5_default_pwd_prompt1 = DEFAULT_PWD_STRING1; char *krb5_default_pwd_prompt2 = DEFAULT_PWD_STRING2; -#ifdef OLD_CONFIG_FILES -/* - * 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; -} -#endif /* OLD_CONFIG_FILES */ - diff --git a/src/lib/krb5/os/read_pwd.c b/src/lib/krb5/os/read_pwd.c index 1b7da37ad..5da734c50 100644 --- a/src/lib/krb5/os/read_pwd.c +++ b/src/lib/krb5/os/read_pwd.c @@ -31,40 +31,12 @@ #include #include -#ifdef sun -#include -#endif - -extern int errno; - -#ifdef ECHO_PASSWORD -#define cleanup(errcode) (void) signal(SIGINT, ointrfunc); return errcode; -#else - -/* POSIX_* are auto-magically defined in at source - configuration time. */ - -#ifdef POSIX_TERMIOS +#ifndef ECHO_PASSWORD #include -#else -#include -#endif /* POSIX_TERMIOS */ - -#ifdef POSIX_TERMIOS -#define cleanup(errcode) (void) signal(SIGINT, ointrfunc); tcsetattr(fd, TCSANOW, &save_control); return errcode; -#else -#ifdef sun -#define cleanup(errcode) (void) signal(SIGINT, ointrfunc); stty(fd, (char *)&tty_savestate); return errcode; -#else /* !sun */ -#define cleanup(errcode) (void) signal(SIGINT, ointrfunc); ioctl(fd, TIOCSETP, (char *)&tty_savestate); return errcode; -#endif /* sun */ -#endif /* POSIX_TERMIOS */ - #endif /* ECHO_PASSWORD */ static jmp_buf pwd_jump; - static krb5_sigtype intr_routine() { @@ -86,23 +58,14 @@ krb5_read_password(context, prompt, prompt2, return_pwd, size_return) register char *ptr; int scratchchar; krb5_sigtype (*ointrfunc)(); + krb5_error_code errcode; #ifndef ECHO_PASSWORD -#ifdef POSIX_TERMIOS struct termios echo_control, save_control; int fd; /* get the file descriptor associated with stdin */ fd=fileno(stdin); -#ifdef notdef - /* don't want to read password from anything but a terminal */ - if (!isatty(fd)) { - fprintf(stderr,"Can only read password from a tty\n"); /* XXX */ - errno=ENOTTY; /* say innapropriate ioctl for device */ - return errno; - } -#endif /* notdef */ - if (tcgetattr(fd, &echo_control) == -1) return errno; @@ -111,56 +74,11 @@ krb5_read_password(context, prompt, prompt2, return_pwd, size_return) if (tcsetattr(fd, TCSANOW, &echo_control) == -1) return errno; -#else - /* 4.3BSD style */ - struct sgttyb tty_state, tty_savestate; - int fd; - - /* get the file descriptor associated with stdin */ - fd=fileno(stdin); - -#ifdef notdef - /* don't want to read password from anything but a terminal */ - if (!isatty(fd)) { - fprintf(stderr,"Can only read password from a tty\n"); /* XXX */ - errno=ENOTTY; /* say innapropriate ioctl for device */ - return errno; - } -#endif /* notdef */ - - /* save terminal state */ - if ( -#ifdef sun - gtty(fd,(char *)&tty_savestate) -#else - ioctl(fd,TIOCGETP,(char *)&tty_savestate) -#endif - == -1) - return errno; - - tty_state = tty_savestate; - - tty_state.sg_flags &= ~ECHO; - if ( -#ifdef sun - stty(fd,(char *)&tty_state) -#else - ioctl(fd,TIOCSETP,(char *)&tty_state) -#endif - == -1) - return errno; -#endif - #endif /* ECHO_PASSWORD */ if (setjmp(pwd_jump)) { - /* interrupted */ - if (readin_string) { - (void) memset((char *)readin_string, 0, *size_return); - krb5_xfree(readin_string); - } - (void) memset(return_pwd, 0, *size_return); - cleanup(KRB5_LIBOS_PWDINTR); + errcode = KRB5_LIBOS_PWDINTR; /* we were interrupted... */ + goto cleanup; } /* save intrfunc */ ointrfunc = signal(SIGINT, intr_routine); @@ -171,16 +89,15 @@ krb5_read_password(context, prompt, prompt2, return_pwd, size_return) (void) memset(return_pwd, 0, *size_return); if (fgets(return_pwd, *size_return, stdin) == NULL) { - /* error */ (void) putchar('\n'); - (void) memset(return_pwd, 0, *size_return); - cleanup(KRB5_LIBOS_CANTREADPWD); + errcode = KRB5_LIBOS_CANTREADPWD; + goto cleanup; } (void) putchar('\n'); /* fgets always null-terminates the returned string */ /* replace newline with null */ - if (ptr = strchr(return_pwd, '\n')) + if ((ptr = strchr(return_pwd, '\n'))) *ptr = '\0'; else /* flush rest of input line */ do { @@ -193,21 +110,18 @@ krb5_read_password(context, prompt, prompt2, return_pwd, size_return) (void) fflush(stdout); readin_string = malloc(*size_return); if (!readin_string) { - (void) memset(return_pwd, 0, *size_return); - cleanup(ENOMEM); + errcode = ENOMEM; + goto cleanup; } (void) memset((char *)readin_string, 0, *size_return); if (fgets((char *)readin_string, *size_return, stdin) == NULL) { - /* error */ (void) putchar('\n'); - (void) memset((char *)readin_string, 0, *size_return); - (void) memset(return_pwd, 0, *size_return); - krb5_xfree(readin_string); - cleanup(KRB5_LIBOS_CANTREADPWD); + errcode = KRB5_LIBOS_CANTREADPWD; + goto cleanup; } (void) putchar('\n'); - if (ptr = strchr((char *)readin_string, '\n')) + if ((ptr = strchr((char *)readin_string, '\n'))) *ptr = '\0'; else /* need to flush */ do { @@ -216,36 +130,29 @@ krb5_read_password(context, prompt, prompt2, return_pwd, size_return) /* compare */ if (strncmp(return_pwd, (char *)readin_string, *size_return)) { - (void) memset((char *)readin_string, 0, *size_return); - (void) memset(return_pwd, 0, *size_return); - krb5_xfree(readin_string); - cleanup(KRB5_LIBOS_BADPWDMATCH); + errcode = KRB5_LIBOS_BADPWDMATCH; + goto cleanup; } - (void) memset((char *)readin_string, 0, *size_return); - krb5_xfree(readin_string); } - /* reset intrfunc */ + errcode = 0; + +cleanup: (void) signal(SIGINT, ointrfunc); - #ifndef ECHO_PASSWORD -#ifdef POSIX_TERMIOS - if (tcsetattr(fd, TCSANOW, &save_control) == -1) - return errno; -#else - if ( -#ifdef sun - stty(fd, (char *)&tty_savestate) -#else - ioctl(fd, TIOCSETP, (char *)&tty_savestate) -#endif - == -1) - return errno; + if ((tcsetattr(fd, TCSANOW, &save_control) == -1) && + errcode == 0) + return errno; #endif -#endif /* ECHO_PASSWORD */ - *size_return = strlen(return_pwd); - - return 0; + if (readin_string) { + memset((char *)readin_string, 0, *size_return); + krb5_xfree(readin_string); + } + if (errcode) + memset(return_pwd, 0, *size_return); + else + *size_return = strlen(return_pwd); + return errcode; } #else /* MSDOS */ /* Don't expect to be called, just define it for sanity and the linker. diff --git a/src/lib/krb5/os/realm_dom.c b/src/lib/krb5/os/realm_dom.c index 4bc14585f..e6afa3188 100644 --- a/src/lib/krb5/os/realm_dom.c +++ b/src/lib/krb5/os/realm_dom.c @@ -42,149 +42,6 @@ #include #include -#ifdef OLD_CONFIG_FILES - -/* for old Unixes and friends ... */ -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 64 -#endif - -#define DEF_REALMNAME_SIZE 256 - -extern char *krb5_trans_file; - -#ifdef _WINDOWS -/* - * Windows DLL can't use the fscanf routine. We need fscanf to read - * in the host and realm. Read_2str with read_1str duplicate the needed - * functionality. See also host_realm.c - */ -static int -read_1str (FILE *fp, char *buf, int buflen) { - int c; - - while (1) { - c = fgetc (fp); /* Past leading whitespace */ - if (c == EOF) - return 0; - if (! isspace (c)) - break; - } - - while (1) { - if (buflen > 0) { /* Store the character */ - *buf++ = (char) c; - --buflen; - } - if (buflen <= 0) /* Fscanf stops scanning... */ - break; /* ...when buffer is full */ - - c = fgetc (fp); /* Get next character */ - if (c == EOF || isspace (c)) - break; - } - - if (buflen) /* Make ASCIIZ if room */ - *buf = '\0'; - - return 1; -} - -static int -read_2str (FILE *fp, char *b1, int l1, char *b2, int l2) { - int n; - - n = read_1str (fp, b1, l1); /* Read first string */ - if (!n) return EOF; - n = read_1str (fp, b2, l2); /* Read second string */ - if (!n) return 1; - return 2; -} - -#endif /* _WINDOWS */ - -krb5_error_code -krb5_get_realm_domain(context, realm, domain) - krb5_context context; - const char *realm; - char **domain; -{ - char **realmlist = NULL; - char *retdomain = NULL; - char trans_host[MAXHOSTNAMELEN+1]; - char trans_realm[DEF_REALMNAME_SIZE]; - krb5_error_code retval; - FILE *trans_file; - int scanval; - char scanstring[7+2*16]; /* 7 chars + 16 for each decimal - conversion */ - - if (realm == NULL) { - if (retval = krb5_get_host_realm(context, NULL, &realmlist)) - 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]); - krb5_xfree(realmlist); - } - return KRB5_TRANS_CANTOPEN; - } - (void) sprintf(scanstring, "%%%ds %%%ds", - sizeof(trans_host)-1,sizeof(trans_realm)-1); - while (1) { -#ifdef _WINDOWS - scanval = read_2str (trans_file, trans_host, sizeof(trans_host)-1, - trans_realm, sizeof(trans_realm)-1); -#else - scanval = fscanf(trans_file, scanstring, trans_host, trans_realm); -#endif - if (scanval != 2) { - if (scanval == EOF) { - fclose(trans_file); - if (realmlist != NULL) { - krb5_xfree(realmlist[0]); - krb5_xfree(realmlist); - } - if ((retdomain = malloc(strlen(realm) + 2)) == NULL) - return ENOMEM; - strcpy(retdomain, "."); - strcat(retdomain, realm); /* return the realm as the domain - if lookup fails */ - *domain = retdomain; - return 0; - } - continue; - } - trans_host[sizeof(trans_host)-1] = '\0'; - trans_realm[sizeof(trans_realm)-1] = '\0'; - if (!strcmp(trans_realm, realm)) { - if (trans_host[0] == '.') { - if ((retdomain = malloc(strlen(trans_host) + 1)) == NULL) { - if (realmlist != NULL) { - krb5_xfree(realmlist[0]); - krb5_xfree(realmlist); - } - return ENOMEM; - } - (void)strcpy(retdomain, trans_host); - fclose(trans_file); - if (realmlist != NULL) { - krb5_xfree(realmlist[0]); - krb5_xfree(realmlist); - } - *domain = retdomain; - return 0; - } else - continue; - } - } -} - -#else - krb5_error_code krb5_get_realm_domain(context, realm, domain) krb5_context context; @@ -197,4 +54,3 @@ krb5_get_realm_domain(context, realm, domain) "default_domain", realm, domain); return retval; } -#endif -- 2.26.2