|
|
1.1 ! root 1: /* ! 2: * $Source: /usr/src/kerberosIV/krb/RCS/kname_parse.c,v $ ! 3: * $Author: kfall $ ! 4: * ! 5: * Copyright 1987, 1988 by the Massachusetts Institute of Technology. ! 6: * ! 7: * For copying and distribution information, please see the file ! 8: * <mit-copyright.h>. ! 9: */ ! 10: ! 11: #ifndef lint ! 12: static char rcsid_kname_parse_c[] = ! 13: "$Header: /usr/src/kerberosIV/krb/RCS/kname_parse.c,v 4.5 90/06/25 20:56:35 kfall Exp $"; ! 14: #endif /* lint */ ! 15: ! 16: #include <mit-copyright.h> ! 17: ! 18: #include <stdio.h> ! 19: #include <des.h> ! 20: #include <krb.h> ! 21: #include <strings.h> ! 22: ! 23: /* max size of full name */ ! 24: #define FULL_SZ (ANAME_SZ + INST_SZ + REALM_SZ) ! 25: ! 26: #define NAME 0 /* which field are we in? */ ! 27: #define INST 1 ! 28: #define REALM 2 ! 29: ! 30: extern char *krb_err_txt[]; ! 31: ! 32: /* ! 33: * This file contains four routines for handling Kerberos names. ! 34: * ! 35: * kname_parse() breaks a Kerberos name into its name, instance, ! 36: * and realm components. ! 37: * ! 38: * k_isname(), k_isinst(), and k_isrealm() check a given string to see if ! 39: * it's a syntactically legitimate respective part of a Kerberos name, ! 40: * returning 1 if it is, 0 if it isn't. ! 41: * ! 42: * Definition of "syntactically legitimate" names is according to ! 43: * the Project Athena Technical Plan Section E.2.1, page 7 "Specifying ! 44: * names", version dated 21 Dec 1987. ! 45: * / ! 46: ! 47: /* ! 48: * kname_parse() takes a Kerberos name "fullname" of the form: ! 49: * ! 50: * username[.instance][@realm] ! 51: * ! 52: * and returns the three components ("name", "instance", and "realm" ! 53: * in the example above) in the given arguments "np", "ip", and "rp". ! 54: * ! 55: * If successful, it returns KSUCCESS. If there was an error, ! 56: * KNAME_FMT is returned. ! 57: */ ! 58: ! 59: kname_parse(np, ip, rp, fullname) ! 60: char *np, *ip, *rp, *fullname; ! 61: { ! 62: static char buf[FULL_SZ]; ! 63: char *rnext, *wnext; /* next char to read, write */ ! 64: register char c; ! 65: int backslash; ! 66: int field; ! 67: ! 68: backslash = 0; ! 69: rnext = buf; ! 70: wnext = np; ! 71: field = NAME; ! 72: ! 73: if (strlen(fullname) > FULL_SZ) ! 74: return KNAME_FMT; ! 75: (void) strcpy(buf, fullname); ! 76: ! 77: while (c = *rnext++) { ! 78: if (backslash) { ! 79: *wnext++ = c; ! 80: backslash = 0; ! 81: continue; ! 82: } ! 83: switch (c) { ! 84: case '\\': ! 85: backslash++; ! 86: break; ! 87: case '.': ! 88: switch (field) { ! 89: case NAME: ! 90: if (wnext == np) ! 91: return KNAME_FMT; ! 92: *wnext = '\0'; ! 93: field = INST; ! 94: wnext = ip; ! 95: break; ! 96: case INST: ! 97: return KNAME_FMT; ! 98: /* break; */ ! 99: case REALM: ! 100: *wnext++ = c; ! 101: break; ! 102: default: ! 103: fprintf(stderr, "unknown field value\n"); ! 104: exit(1); ! 105: } ! 106: break; ! 107: case '@': ! 108: switch (field) { ! 109: case NAME: ! 110: if (wnext == np) ! 111: return KNAME_FMT; ! 112: *ip = '\0'; ! 113: /* fall through */ ! 114: case INST: ! 115: *wnext = '\0'; ! 116: field = REALM; ! 117: wnext = rp; ! 118: break; ! 119: case REALM: ! 120: return KNAME_FMT; ! 121: default: ! 122: fprintf(stderr, "unknown field value\n"); ! 123: exit(1); ! 124: } ! 125: break; ! 126: default: ! 127: *wnext++ = c; ! 128: } ! 129: } ! 130: *wnext = '\0'; ! 131: if ((strlen(np) > ANAME_SZ - 1) || ! 132: (strlen(ip) > INST_SZ - 1) || ! 133: (strlen(rp) > REALM_SZ - 1)) ! 134: return KNAME_FMT; ! 135: return KSUCCESS; ! 136: } ! 137: ! 138: /* ! 139: * k_isname() returns 1 if the given name is a syntactically legitimate ! 140: * Kerberos name; returns 0 if it's not. ! 141: */ ! 142: ! 143: k_isname(s) ! 144: char *s; ! 145: { ! 146: register char c; ! 147: int backslash = 0; ! 148: ! 149: if (!*s) ! 150: return 0; ! 151: if (strlen(s) > ANAME_SZ - 1) ! 152: return 0; ! 153: while(c = *s++) { ! 154: if (backslash) { ! 155: backslash = 0; ! 156: continue; ! 157: } ! 158: switch(c) { ! 159: case '\\': ! 160: backslash = 1; ! 161: break; ! 162: case '.': ! 163: return 0; ! 164: /* break; */ ! 165: case '@': ! 166: return 0; ! 167: /* break; */ ! 168: } ! 169: } ! 170: return 1; ! 171: } ! 172: ! 173: ! 174: /* ! 175: * k_isinst() returns 1 if the given name is a syntactically legitimate ! 176: * Kerberos instance; returns 0 if it's not. ! 177: */ ! 178: ! 179: k_isinst(s) ! 180: char *s; ! 181: { ! 182: register char c; ! 183: int backslash = 0; ! 184: ! 185: if (strlen(s) > INST_SZ - 1) ! 186: return 0; ! 187: while(c = *s++) { ! 188: if (backslash) { ! 189: backslash = 0; ! 190: continue; ! 191: } ! 192: switch(c) { ! 193: case '\\': ! 194: backslash = 1; ! 195: break; ! 196: case '.': ! 197: return 0; ! 198: /* break; */ ! 199: case '@': ! 200: return 0; ! 201: /* break; */ ! 202: } ! 203: } ! 204: return 1; ! 205: } ! 206: ! 207: /* ! 208: * k_isrealm() returns 1 if the given name is a syntactically legitimate ! 209: * Kerberos realm; returns 0 if it's not. ! 210: */ ! 211: ! 212: k_isrealm(s) ! 213: char *s; ! 214: { ! 215: register char c; ! 216: int backslash = 0; ! 217: ! 218: if (!*s) ! 219: return 0; ! 220: if (strlen(s) > REALM_SZ - 1) ! 221: return 0; ! 222: while(c = *s++) { ! 223: if (backslash) { ! 224: backslash = 0; ! 225: continue; ! 226: } ! 227: switch(c) { ! 228: case '\\': ! 229: backslash = 1; ! 230: break; ! 231: case '@': ! 232: return 0; ! 233: /* break; */ ! 234: } ! 235: } ! 236: return 1; ! 237: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.