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

Revision 23899, 1.8 KB checked in by broder, 15 years ago (diff)
In moira: * New CVS snapshot. * Drop krb4less-fix; it was incorporated upstream.
Line 
1/* $Id: kname_unparse.c,v 1.7 2009-06-21 15:29:55 zacheiss Exp $
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
16#ifdef HAVE_KRB4
17#include <krb.h>
18#else
19#include <mr_krb.h>
20#endif
21
22RCSID("$Header: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/lib/kname_unparse.c,v 1.7 2009-06-21 15:29:55 zacheiss Exp $");
23
24/* Turn a principal, instance, realm triple into a single non-ambiguous
25 * string.  This is the inverse of kname_parse().  It returns a pointer
26 * to a static buffer, or NULL on error.
27 */
28
29char *mr_kname_unparse(char *p, char *i, char *r)
30{
31  static char name[MAX_K_NAME_SZ];
32  char *s;
33
34  s = name;
35  if (!p || strlen(p) > ANAME_SZ)
36    return NULL;
37  while (*p)
38    {
39      switch (*p)
40        {
41        case '@':
42          *s++ = '\\';
43          *s++ = '@';
44          break;
45        case '.':
46          *s++ = '\\';
47          *s++ = '.';
48          break;
49        case '\\':
50          *s++ = '\\';
51          *s++ = '\\';
52          break;
53        default:
54          *s++ = *p;
55        }
56      p++;
57    }
58  if (i && *i)
59    {
60      if (strlen(i) > INST_SZ)
61        return NULL;
62      *s++ = '.';
63      while (*i)
64        {
65          switch (*i)
66            {
67            case '@':
68              *s++ = '\\';
69              *s++ = '@';
70              break;
71            case '.':
72              *s++ = '\\';
73              *s++ = '.';
74              break;
75            case '\\':
76              *s++ = '\\';
77              *s++ = '\\';
78              break;
79            default:
80              *s++ = *i;
81            }
82          i++;
83        }
84    }
85  *s++ = '@';
86  if (!r || strlen(r) > REALM_SZ)
87    return NULL;
88  while (*r)
89    {
90      switch (*r)
91        {
92        case '@':
93          *s++ = '\\';
94          *s++ = '@';
95          break;
96        case '\\':
97          *s++ = '\\';
98          *s++ = '\\';
99          break;
100        default:
101          *s++ = *r;
102        }
103      r++;
104    }
105  *s = '\0';
106  return &name[0];
107}
Note: See TracBrowser for help on using the repository browser.