]> andersk Git - moira.git/blame_incremental - lib/kname_unparse.c
Use krb5_error_code for return value of krb5 library functions.
[moira.git] / lib / kname_unparse.c
... / ...
CommitLineData
1/* $Id$
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#include <des.h>
17#include <krb.h>
18
19RCSID("$Header$");
20
21/* Turn a principal, instance, realm triple into a single non-ambiguous
22 * string. This is the inverse of kname_parse(). It returns a pointer
23 * to a static buffer, or NULL on error.
24 */
25
26char *kname_unparse(char *p, char *i, char *r)
27{
28 static char name[MAX_K_NAME_SZ];
29 char *s;
30
31 s = name;
32 if (!p || strlen(p) > ANAME_SZ)
33 return NULL;
34 while (*p)
35 {
36 switch (*p)
37 {
38 case '@':
39 *s++ = '\\';
40 *s++ = '@';
41 break;
42 case '.':
43 *s++ = '\\';
44 *s++ = '.';
45 break;
46 case '\\':
47 *s++ = '\\';
48 *s++ = '\\';
49 break;
50 default:
51 *s++ = *p;
52 }
53 p++;
54 }
55 if (i && *i)
56 {
57 if (strlen(i) > INST_SZ)
58 return NULL;
59 *s++ = '.';
60 while (*i)
61 {
62 switch (*i)
63 {
64 case '@':
65 *s++ = '\\';
66 *s++ = '@';
67 break;
68 case '.':
69 *s++ = '\\';
70 *s++ = '.';
71 break;
72 case '\\':
73 *s++ = '\\';
74 *s++ = '\\';
75 break;
76 default:
77 *s++ = *i;
78 }
79 i++;
80 }
81 }
82 *s++ = '@';
83 if (!r || strlen(r) > REALM_SZ)
84 return NULL;
85 while (*r)
86 {
87 switch (*r)
88 {
89 case '@':
90 *s++ = '\\';
91 *s++ = '@';
92 break;
93 case '\\':
94 *s++ = '\\';
95 *s++ = '\\';
96 break;
97 default:
98 *s++ = *r;
99 }
100 r++;
101 }
102 *s = '\0';
103 return &name[0];
104}
This page took 0.034036 seconds and 5 git commands to generate.