Change __signed to signed.
[dragonfly.git] / crypto / kerberosIV / lib / kadm / kadm_supp.c
1 /* 
2   Copyright (C) 1989 by the Massachusetts Institute of Technology
3
4    Export of this software from the United States of America is assumed
5    to require a specific license from the United States Government.
6    It is the responsibility of any person or organization contemplating
7    export to obtain such a license before exporting.
8
9 WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
10 distribute this software and its documentation for any purpose and
11 without fee is hereby granted, provided that the above copyright
12 notice appear in all copies and that both that copyright notice and
13 this permission notice appear in supporting documentation, and that
14 the name of M.I.T. not be used in advertising or publicity pertaining
15 to distribution of the software without specific, written prior
16 permission.  M.I.T. makes no representations about the suitability of
17 this software for any purpose.  It is provided "as is" without express
18 or implied warranty.
19
20   */
21
22 /*
23  * Support functions for Kerberos administration server & clients
24  */
25
26 /*
27   kadm_supp.c
28   this holds the support routines for the kerberos administration server
29
30     error: prints out a kadm error message, returns
31     fatal: prints out a kadm fatal error message, exits
32     prin_vals: prints out data associated with a Principal in the vals
33            structure
34 */
35
36 #include "kadm_locl.h"
37     
38 RCSID("$Id: kadm_supp.c,v 1.14 1999/09/16 20:41:46 assar Exp $");
39
40 static void
41 time2str(char *buf, size_t len, time_t t)
42 {
43     strftime(buf, len, "%Y-%m-%d %H:%M:%S", localtime(&t));
44 }
45
46 /*
47 prin_vals:
48   recieves    : a vals structure
49 */
50 void
51 prin_vals(Kadm_vals *vals)
52 {
53     char date[32];
54     if(IS_FIELD(KADM_NAME, vals->fields) && IS_FIELD(KADM_INST, vals->fields))
55         printf("%20s: %s\n", "Principal", 
56                krb_unparse_name_long(vals->name, vals->instance, NULL));
57     else {
58         printf("Dump of funny entry:\n");
59         if(IS_FIELD(KADM_NAME, vals->fields))
60             printf("%20s: %s\n", "Name", vals->name);
61         if(IS_FIELD(KADM_INST, vals->fields))
62             printf("%20s: %s\n", "Instance", vals->instance);
63     }
64     if(IS_FIELD(KADM_MAXLIFE, vals->fields))
65         printf("%20s: %d (%s)\n", "Max ticket life", 
66                vals->max_life, 
67                krb_life_to_atime(vals->max_life));
68     if(IS_FIELD(KADM_EXPDATE, vals->fields)) {
69         time2str(date, sizeof(date), vals->exp_date);
70         printf("%20s: %s\n", "Expiration date", date);
71     }
72     if(IS_FIELD(KADM_ATTR, vals->fields))
73         printf("%20s: %d\n", "Attributes",
74                vals->attributes);
75     if(IS_FIELD(KADM_DESKEY, vals->fields))
76         printf("%20s: %#lx %#lx\n", "Key",
77                (unsigned long)vals->key_low,
78                (unsigned long)vals->key_high);
79
80 #ifdef EXTENDED_KADM
81     if (IS_FIELD(KADM_MODDATE,vals->fields)) {
82         time2str(date, sizeof(date), vals->mod_date);
83         printf("%20s: %s\n", "Modification date", date);
84     }
85     if (IS_FIELD(KADM_MODNAME,vals->fields) && 
86         IS_FIELD(KADM_MODINST,vals->fields))
87         printf("%20s: %s\n", "Modifier", 
88                krb_unparse_name_long(vals->mod_name, vals->mod_instance, NULL));
89     if (IS_FIELD(KADM_KVNO,vals->fields))
90         printf("%20s: %d\n", "Key version", vals->key_version);
91 #endif
92
93 #if 0
94     printf("Info in Database for %s.%s:\n", vals->name, vals->instance);
95     printf("   Max Life: %d (%s)   Exp Date: %s\n",
96            vals->max_life,
97            krb_life_to_atime(vals->max_life), 
98            asctime(k_localtime(&vals->exp_date)));
99     printf("   Attribs: %.2x  key: %#lx %#lx\n",
100            vals->attributes,
101            (unsigned long)vals->key_low,
102            (unsigned long)vals->key_high);
103 #endif
104 }
105
106 /* kadm_prin_to_vals takes a fields arguments, a Kadm_vals and a Principal,
107    it copies the fields in Principal specified by fields into Kadm_vals, 
108    i.e from old to new */
109
110 void
111 kadm_prin_to_vals(u_char *fields, Kadm_vals *new, Principal *old)
112 {
113     memset(new, 0, sizeof(*new));
114     if (IS_FIELD(KADM_NAME,fields)) {
115         strlcpy(new->name, old->name, ANAME_SZ); 
116         SET_FIELD(KADM_NAME, new->fields);
117     }
118     if (IS_FIELD(KADM_INST,fields)) {
119         strlcpy(new->instance, old->instance, INST_SZ); 
120         SET_FIELD(KADM_INST, new->fields);
121     }      
122     if (IS_FIELD(KADM_EXPDATE,fields)) {
123         new->exp_date   = old->exp_date; 
124         SET_FIELD(KADM_EXPDATE, new->fields);
125     }      
126     if (IS_FIELD(KADM_ATTR,fields)) {
127         new->attributes = old->attributes; 
128         SET_FIELD(KADM_ATTR, new->fields);
129     }      
130     if (IS_FIELD(KADM_MAXLIFE,fields)) {
131         new->max_life   = old->max_life; 
132         SET_FIELD(KADM_MAXLIFE, new->fields);
133     }      
134     if (IS_FIELD(KADM_DESKEY,fields)) {
135         new->key_low    = old->key_low; 
136         new->key_high   = old->key_high; 
137         SET_FIELD(KADM_DESKEY, new->fields);
138     }
139 #ifdef EXTENDED_KADM
140     if (IS_FIELD(KADM_MODDATE,fields)) {
141         new->mod_date = old->mod_date;
142         SET_FIELD(KADM_MODDATE, new->fields);
143     }
144     if (IS_FIELD(KADM_MODNAME,fields)) {
145         strlcpy(new->mod_name, old->mod_name, ANAME_SZ);
146         SET_FIELD(KADM_MODNAME, new->fields);
147     }
148     if (IS_FIELD(KADM_MODINST,fields)) {
149         strlcpy(new->mod_instance, old->mod_instance, ANAME_SZ);
150         SET_FIELD(KADM_MODINST, new->fields);
151     }
152     if (IS_FIELD(KADM_KVNO,fields)) {
153         new->key_version = old->key_version;
154         SET_FIELD(KADM_KVNO, new->fields);
155     }
156 #endif
157 }
158
159 void
160 kadm_vals_to_prin(u_char *fields, Principal *new, Kadm_vals *old)
161 {
162
163     memset(new, 0, sizeof(*new));
164     if (IS_FIELD(KADM_NAME,fields))
165         strlcpy(new->name, old->name, ANAME_SZ); 
166     if (IS_FIELD(KADM_INST,fields))
167         strlcpy(new->instance, old->instance, INST_SZ); 
168     if (IS_FIELD(KADM_EXPDATE,fields))
169         new->exp_date   = old->exp_date; 
170     if (IS_FIELD(KADM_ATTR,fields))
171         new->attributes = old->attributes; 
172     if (IS_FIELD(KADM_MAXLIFE,fields))
173         new->max_life   = old->max_life; 
174     if (IS_FIELD(KADM_DESKEY,fields)) {
175         new->key_low    = old->key_low; 
176         new->key_high   = old->key_high; 
177     }
178 #ifdef EXTENDED_KADM
179     if (IS_FIELD(KADM_MODDATE,fields))
180         new->mod_date = old->mod_date;
181     if (IS_FIELD(KADM_MODNAME,fields))
182         strlcpy(new->mod_name, old->mod_name, ANAME_SZ);
183     if (IS_FIELD(KADM_MODINST,fields))
184         strlcpy(new->mod_instance, old->mod_instance, ANAME_SZ);
185     if (IS_FIELD(KADM_KVNO,fields))
186         new->key_version = old->key_version;
187 #endif
188 }