]>
Commit | Line | Data |
---|---|---|
d80d8d5a | 1 | /* $Header$ |
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 | ||
7 | #include <stdio.h> | |
8 | #include <des.h> | |
9 | #include <krb.h> | |
10 | ||
5eaef520 | 11 | /* Turn a principal, instance, realm triple into a single non-ambiguous |
d80d8d5a | 12 | * string. This is the inverse of kname_parse(). It returns a pointer |
13 | * to a static buffer, or NULL on error. | |
14 | */ | |
15 | ||
5eaef520 | 16 | char *kname_unparse(char *p, char *i, char *r) |
d80d8d5a | 17 | { |
5eaef520 | 18 | static char name[MAX_K_NAME_SZ]; |
19 | char *s; | |
d80d8d5a | 20 | |
5eaef520 | 21 | s = name; |
22 | if (!p || strlen(p) > ANAME_SZ) | |
23 | return NULL; | |
24 | while (*p) | |
25 | { | |
26 | switch (*p) | |
27 | { | |
d80d8d5a | 28 | case '@': |
5eaef520 | 29 | *s++ = '\\'; |
30 | *s++ = '@'; | |
31 | break; | |
d80d8d5a | 32 | case '.': |
5eaef520 | 33 | *s++ = '\\'; |
34 | *s++ = '.'; | |
35 | break; | |
d80d8d5a | 36 | case '\\': |
5eaef520 | 37 | *s++ = '\\'; |
38 | *s++ = '\\'; | |
39 | break; | |
d80d8d5a | 40 | default: |
5eaef520 | 41 | *s++ = *p; |
d80d8d5a | 42 | } |
5eaef520 | 43 | p++; |
d80d8d5a | 44 | } |
5eaef520 | 45 | if (i && *i) |
46 | { | |
47 | if (strlen(i) > INST_SZ) | |
48 | return NULL; | |
49 | *s++ = '.'; | |
50 | while (*i) | |
51 | { | |
52 | switch (*i) | |
53 | { | |
d80d8d5a | 54 | case '@': |
5eaef520 | 55 | *s++ = '\\'; |
56 | *s++ = '@'; | |
57 | break; | |
d80d8d5a | 58 | case '.': |
5eaef520 | 59 | *s++ = '\\'; |
60 | *s++ = '.'; | |
61 | break; | |
d80d8d5a | 62 | case '\\': |
5eaef520 | 63 | *s++ = '\\'; |
64 | *s++ = '\\'; | |
65 | break; | |
d80d8d5a | 66 | default: |
5eaef520 | 67 | *s++ = *i; |
d80d8d5a | 68 | } |
5eaef520 | 69 | i++; |
d80d8d5a | 70 | } |
71 | } | |
5eaef520 | 72 | *s++ = '@'; |
73 | if (!r || strlen(r) > REALM_SZ) | |
74 | return NULL; | |
75 | while (*r) | |
76 | { | |
77 | switch (*r) | |
78 | { | |
d80d8d5a | 79 | case '@': |
5eaef520 | 80 | *s++ = '\\'; |
81 | *s++ = '@'; | |
82 | break; | |
d80d8d5a | 83 | case '\\': |
5eaef520 | 84 | *s++ = '\\'; |
85 | *s++ = '\\'; | |
86 | break; | |
d80d8d5a | 87 | default: |
5eaef520 | 88 | *s++ = *r; |
d80d8d5a | 89 | } |
5eaef520 | 90 | r++; |
d80d8d5a | 91 | } |
5eaef520 | 92 | *s = '\0'; |
93 | return &name[0]; | |
d80d8d5a | 94 | } |