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