]> andersk Git - moira.git/blame - lib/kname_unparse.c
Fix typo.
[moira.git] / lib / kname_unparse.c
CommitLineData
fa59b86f 1/* $Id$
d80d8d5a 2 *
3 * Don't know why this function is not in libkrb.a. It's the inverse
4 * of kname_parse() which is there.
7ac48069 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>.
d80d8d5a 9 */
10
7ac48069 11#include <mit-copyright.h>
12#include <moira.h>
13
d80d8d5a 14#include <stdio.h>
7ac48069 15
c4b0f378 16#ifdef HAVE_KRB4
d80d8d5a 17#include <krb.h>
cb974713 18#else
19#include <mr_krb.h>
20#endif
d80d8d5a 21
7ac48069 22RCSID("$Header$");
23
5eaef520 24/* Turn a principal, instance, realm triple into a single non-ambiguous
d80d8d5a 25 * string. This is the inverse of kname_parse(). It returns a pointer
26 * to a static buffer, or NULL on error.
27 */
28
866127a1 29char *mr_kname_unparse(char *p, char *i, char *r)
d80d8d5a 30{
5eaef520 31 static char name[MAX_K_NAME_SZ];
32 char *s;
d80d8d5a 33
5eaef520 34 s = name;
35 if (!p || strlen(p) > ANAME_SZ)
36 return NULL;
37 while (*p)
38 {
39 switch (*p)
40 {
d80d8d5a 41 case '@':
5eaef520 42 *s++ = '\\';
43 *s++ = '@';
44 break;
d80d8d5a 45 case '.':
5eaef520 46 *s++ = '\\';
47 *s++ = '.';
48 break;
d80d8d5a 49 case '\\':
5eaef520 50 *s++ = '\\';
51 *s++ = '\\';
52 break;
d80d8d5a 53 default:
5eaef520 54 *s++ = *p;
d80d8d5a 55 }
5eaef520 56 p++;
d80d8d5a 57 }
5eaef520 58 if (i && *i)
59 {
60 if (strlen(i) > INST_SZ)
61 return NULL;
62 *s++ = '.';
63 while (*i)
64 {
65 switch (*i)
66 {
d80d8d5a 67 case '@':
5eaef520 68 *s++ = '\\';
69 *s++ = '@';
70 break;
d80d8d5a 71 case '.':
5eaef520 72 *s++ = '\\';
73 *s++ = '.';
74 break;
d80d8d5a 75 case '\\':
5eaef520 76 *s++ = '\\';
77 *s++ = '\\';
78 break;
d80d8d5a 79 default:
5eaef520 80 *s++ = *i;
d80d8d5a 81 }
5eaef520 82 i++;
d80d8d5a 83 }
84 }
5eaef520 85 *s++ = '@';
86 if (!r || strlen(r) > REALM_SZ)
87 return NULL;
88 while (*r)
89 {
90 switch (*r)
91 {
d80d8d5a 92 case '@':
5eaef520 93 *s++ = '\\';
94 *s++ = '@';
95 break;
d80d8d5a 96 case '\\':
5eaef520 97 *s++ = '\\';
98 *s++ = '\\';
99 break;
d80d8d5a 100 default:
5eaef520 101 *s++ = *r;
d80d8d5a 102 }
5eaef520 103 r++;
d80d8d5a 104 }
5eaef520 105 *s = '\0';
106 return &name[0];
d80d8d5a 107}
This page took 0.090225 seconds and 5 git commands to generate.