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>.
16 * Specialized version of the kerberos krb_get_lrealm function.
17 * krb_get_lrealm takes a pointer to a string, and a number, n. It fills
18 * in the string, r, with the name of the nth realm specified on the
19 * first line of the kerberos config file (KRB_CONF, defined in "krb.h").
20 * It returns 0 (KSUCCESS) on success, and KFAILURE on failure.
22 * On the kerberos version if the config file does not exist, and if n=1, a
23 * successful return will occur with r = KRB_REALM (also defined in "krb.h").
30 parse_str(char *buffer, char *result, int size)
37 while (*buffer && isspace(*buffer))
39 while (*buffer && !isspace(*buffer)) {
55 afs_krb_get_lrealm(char *r, int n)
58 char tr[AFS_REALM_SZ] = "";
60 FILE *cnffile/*, *fopen()*/;
66 if ((cnffile = fopen(AFSDIR_SERVER_KCONF_FILEPATH, "r")) == NULL) {
69 if (fgets(linebuf, sizeof(linebuf)-1, cnffile) == NULL) {
72 linebuf[sizeof(linebuf)-1] = '\0';
73 for (i=0, p=linebuf; i<=n && *p; i++) {
74 p = parse_str(p, tr, AFS_REALM_SZ);
83 (void)fclose(cnffile);
88 afs_krb_exclusion(char * name)
91 char excl_name[256] = "";
92 FILE *cnffile/*, *fopen()*/;
95 if ((cnffile = fopen(AFSDIR_SERVER_KRB_EXCL_FILEPATH, "r")) == NULL)
99 if (fgets(linebuf, sizeof(linebuf)-1, cnffile) == NULL) {
102 linebuf[sizeof(linebuf)-1] = '\0';
103 parse_str(linebuf, excl_name, sizeof(excl_name));
105 if (!strcmp(name,excl_name)) {
112 (void)fclose(cnffile);
117 afs_is_foreign_ticket_name(char *tname, char *tinst, char * tcell, char *localrealm)
121 if (localrealm && strcasecmp(localrealm, tcell))
124 #if defined(AFS_ATHENA_STDENV) || defined(AFS_KERBREALM_ENV)
126 static char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
127 static int num_lrealms = -1;
131 if (num_lrealms == -1) {
132 for (i=0; i<AFS_NUM_LREALMS; i++) {
133 if (afs_krb_get_lrealm(local_realms[i], i) != 0 /*KSUCCESS*/)
137 if (i==0 && localrealm) {
138 strncpy(local_realms[0], localrealm, AFS_REALM_SZ);
145 /* See if the ticket cell matches one of the local realms */
147 for ( i=0;i<num_lrealms;i++ ) {
148 if (!strcasecmp(local_realms[i], tcell)) {
154 /* If yes, then make sure that the name is not present in
155 * an exclusion list */
157 if (tinst && tinst[0])
158 snprintf(uname,sizeof(uname),"%s.%s@%s",tname,tinst,tcell);
160 snprintf(uname,sizeof(uname),"%s@%s",tname,tcell);
162 if (afs_krb_exclusion(uname))
166 foreign = !lrealm_match;