2 * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute of Technology.
3 * For copying and distribution information, please see the file <mit-copyright.h>.
18 * Specialized version of the kerberos krb_get_lrealm function.
19 * krb_get_lrealm takes a pointer to a string, and a number, n. It fills
20 * in the string, r, with the name of the nth realm specified on the
21 * first line of the kerberos config file (KRB_CONF, defined in "krb.h").
22 * It returns 0 (KSUCCESS) on success, and KFAILURE on failure.
24 * On the kerberos version if the config file does not exist, and if n=1, a
25 * successful return will occur with r = KRB_REALM (also defined in "krb.h").
32 parse_str(char *buffer, char *result, int size)
39 while (*buffer && isspace(*buffer))
41 while (*buffer && !isspace(*buffer)) {
57 afs_krb_get_lrealm(char *r, int n)
60 char tr[AFS_REALM_SZ] = "";
62 FILE *cnffile/*, *fopen()*/;
68 if ((cnffile = fopen(AFSDIR_SERVER_KCONF_FILEPATH, "r")) == NULL) {
71 if (fgets(linebuf, sizeof(linebuf)-1, cnffile) == NULL) {
74 linebuf[sizeof(linebuf)-1] = '\0';
75 for (i=0, p=linebuf; i<=n && *p; i++) {
76 p = parse_str(p, tr, AFS_REALM_SZ);
85 (void)fclose(cnffile);
90 afs_krb_exclusion(char * name)
93 char excl_name[256] = "";
94 FILE *cnffile/*, *fopen()*/;
97 if ((cnffile = fopen(AFSDIR_SERVER_KRB_EXCL_FILEPATH, "r")) == NULL)
101 if (fgets(linebuf, sizeof(linebuf)-1, cnffile) == NULL) {
104 linebuf[sizeof(linebuf)-1] = '\0';
105 parse_str(linebuf, excl_name, sizeof(excl_name));
107 if (!strcmp(name,excl_name)) {
114 (void)fclose(cnffile);
119 afs_is_foreign_ticket_name(char *tname, char *tinst, char * tcell, char *localrealm)
123 if (localrealm && strcasecmp(localrealm, tcell))
126 #if defined(AFS_ATHENA_STDENV) || defined(AFS_KERBREALM_ENV)
128 static char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
129 static int num_lrealms = -1;
133 if (num_lrealms == -1) {
134 for (i=0; i<AFS_NUM_LREALMS; i++) {
135 if (afs_krb_get_lrealm(local_realms[i], i) != 0 /*KSUCCESS*/)
139 if (i==0 && localrealm) {
140 strncpy(local_realms[0], localrealm, AFS_REALM_SZ);
147 /* See if the ticket cell matches one of the local realms */
149 for ( i=0;i<num_lrealms;i++ ) {
150 if (!strcasecmp(local_realms[i], tcell)) {
156 /* If yes, then make sure that the name is not present in
157 * an exclusion list */
159 if (tinst && tinst[0])
160 snprintf(uname,sizeof(uname),"%s.%s@%s",tname,tinst,tcell);
162 snprintf(uname,sizeof(uname),"%s@%s",tname,tcell);
164 if (afs_krb_exclusion(uname))
168 foreign = !lrealm_match;