source: trunk/third/moira/lib/kname_parse.c @ 24250

Revision 24250, 2.6 KB checked in by broder, 14 years ago (diff)
New Moira snapshot from subversion. Sorry for the large diff - looks like all of the keywords changed in the SVN import process.
Line 
1/* $Id: kname_parse.c,v 1.1 2009-05-21 19:38:46 zacheiss Exp $
2 *
3 * Provide a copy of kname_parse() from krb4 for when krb4 is no
4 * longer available.
5 *
6 * Copyright (C) 2009 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
9 */
10
11#include <mit-copyright.h>
12#include <moira.h>
13
14#include <string.h>
15
16#ifdef HAVE_KRB4
17#include <krb.h>
18#else
19#include <mr_krb.h>
20
21#define KRBET_KNAME_FMT                          (39525457L)
22#define KNAME_FMT                                (KRBET_KNAME_FMT - ERROR_TABLE_BASE_krb)
23#endif
24
25RCSID("$Header: /afs/.athena.mit.edu/astaff/project/moiradev/repository/moira/lib/kname_parse.c,v 1.1 2009-05-21 19:38:46 zacheiss Exp $");
26
27#define NAME    0               /* which field are we in? */
28#define INST    1
29#define REALM   2
30
31int mr_kname_parse(char *np, char *ip, char *rp, char *fullname)
32{
33  char buf[MAX_K_NAME_SZ];
34  char *rnext, *wnext;        /* next char to read, write */
35  register char c;
36  int backslash;
37  int field;
38
39  backslash = 0;
40  rnext = buf;
41  wnext = np;
42  field = NAME;
43
44  if (strlen(fullname) > MAX_K_NAME_SZ)
45    return KNAME_FMT;
46  (void) strcpy(buf, fullname);
47
48  while ((c = *rnext++)) {
49    if (backslash) {
50      *wnext++ = c;
51      backslash = 0;
52      continue;
53    }
54    switch (c) {
55    case '\\':
56      backslash++;
57      break;
58    case '.':
59      switch (field) {
60      case NAME:
61        if (wnext == np)
62          return KNAME_FMT;
63        *wnext = '\0';
64        field = INST;
65        wnext = ip;
66        break;
67      case INST:          /* We now allow period in instance */
68      case REALM:
69        *wnext++ = c;
70        break;
71      default:
72        return KNAME_FMT;
73      }
74      break;
75    case '@':
76      switch (field) {
77      case NAME:
78        if (wnext == np)
79          return KNAME_FMT;
80        *ip = '\0';
81        /* fall through */
82      case INST:
83        *wnext = '\0';
84        field = REALM;
85        wnext = rp;
86        break;
87      case REALM:
88        return KNAME_FMT;
89      default:
90        return KNAME_FMT;
91      }
92      break;
93    default:
94      *wnext++ = c;
95    }
96    /*
97     * Paranoia: check length each time through to ensure that we
98     * don't overwrite things.
99     */
100    switch (field) {
101    case NAME:
102      if (wnext - np >= ANAME_SZ)
103        return KNAME_FMT;
104      break;
105    case INST:
106      if (wnext - ip >= INST_SZ)
107        return KNAME_FMT;
108      break;
109    case REALM:
110      if (wnext - rp >= REALM_SZ)
111        return KNAME_FMT;
112      break;
113    default:
114      return KNAME_FMT;
115    }
116  }
117  *wnext = '\0';
118  return 0;
119}
Note: See TracBrowser for help on using the repository browser.