source: trunk/third/moira/lib/kname_unparse.c @ 24319

Revision 24319, 1.9 KB checked in by broder, 14 years ago (diff)
New Moira snapshot from SVN.
Line 
1/* $Id: kname_unparse.c 3956 2010-01-05 20:56:56Z zacheiss $
2 *
3 * Don't know why this function is not in libkrb.a.  It's the inverse
4 * of kname_parse() which is there.
5 *
6 * Copyright (C) 1993-1998 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 <stdio.h>
15#include <string.h>
16
17#ifdef HAVE_KRB4
18#include <krb.h>
19#else
20#include <mr_krb.h>
21#endif
22
23RCSID("$HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/lib/kname_unparse.c $ $Id: kname_unparse.c 3956 2010-01-05 20:56:56Z zacheiss $");
24
25/* Turn a principal, instance, realm triple into a single non-ambiguous
26 * string.  This is the inverse of kname_parse().  It returns a pointer
27 * to a static buffer, or NULL on error.
28 */
29
30char *mr_kname_unparse(char *p, char *i, char *r)
31{
32  static char name[MAX_K_NAME_SZ];
33  char *s;
34
35  s = name;
36  if (!p || strlen(p) > ANAME_SZ)
37    return NULL;
38  while (*p)
39    {
40      switch (*p)
41        {
42        case '@':
43          *s++ = '\\';
44          *s++ = '@';
45          break;
46        case '.':
47          *s++ = '\\';
48          *s++ = '.';
49          break;
50        case '\\':
51          *s++ = '\\';
52          *s++ = '\\';
53          break;
54        default:
55          *s++ = *p;
56        }
57      p++;
58    }
59  if (i && *i)
60    {
61      if (strlen(i) > INST_SZ)
62        return NULL;
63      *s++ = '.';
64      while (*i)
65        {
66          switch (*i)
67            {
68            case '@':
69              *s++ = '\\';
70              *s++ = '@';
71              break;
72            case '.':
73              *s++ = '\\';
74              *s++ = '.';
75              break;
76            case '\\':
77              *s++ = '\\';
78              *s++ = '\\';
79              break;
80            default:
81              *s++ = *i;
82            }
83          i++;
84        }
85    }
86  *s++ = '@';
87  if (!r || strlen(r) > REALM_SZ)
88    return NULL;
89  while (*r)
90    {
91      switch (*r)
92        {
93        case '@':
94          *s++ = '\\';
95          *s++ = '@';
96          break;
97        case '\\':
98          *s++ = '\\';
99          *s++ = '\\';
100          break;
101        default:
102          *s++ = *r;
103        }
104      r++;
105    }
106  *s = '\0';
107  return &name[0];
108}
Note: See TracBrowser for help on using the repository browser.