This commit was manufactured by cvs2svn to create tag
[heimdal.git] / kadmin / get.c
blobfea0ed3ee7168c47d496a1473d5f3c7475aec4dc
1 /*
2 * Copyright (c) 1997, 1998, 1999 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Kungliga Tekniska
20 * Högskolan and its contributors.
22 * 4. Neither the name of the Institute nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
39 #include "kadmin_locl.h"
40 #include <parse_units.h>
42 RCSID("$Id$");
44 struct get_entry_data {
45 void (*header)(void);
46 void (*format)(kadm5_principal_ent_t);
49 static void
50 print_entry_terse(kadm5_principal_ent_t princ)
52 char *p;
53 krb5_unparse_name(context, princ->principal, &p);
54 printf(" %s\n", p);
55 free(p);
58 static void
59 print_header_short(void)
61 printf("%-20s ", "Principal");
63 printf("%-10s ", "Expires");
65 printf("%-10s ", "PW-exp");
67 printf("%-10s ", "PW-change");
69 printf("%-9s ", "Max life");
71 printf("%-9s ", "Max renew");
73 printf("\n");
76 static void
77 print_entry_short(kadm5_principal_ent_t princ)
79 char buf[1024];
81 krb5_unparse_name_fixed_short(context, princ->principal, buf, sizeof(buf));
82 printf("%-20s ", buf);
84 timeval2str(princ->princ_expire_time, buf, sizeof(buf), 0);
85 printf("%-10s ", buf);
87 timeval2str(princ->pw_expiration, buf, sizeof(buf), 0);
88 printf("%-10s ", buf);
90 timeval2str(princ->last_pwd_change, buf, sizeof(buf), 0);
91 printf("%-10s ", buf);
93 deltat2str(princ->max_life, buf, sizeof(buf));
94 printf("%-9s ", buf);
96 deltat2str(princ->max_renewable_life, buf, sizeof(buf));
97 printf("%-9s ", buf);
99 #if 0
100 timeval2str(princ->mod_date, buf, sizeof(buf), 0);
101 printf("%-10s ", buf);
103 krb5_unparse_name_fixed(context, princ->mod_name, buf, sizeof(buf));
104 printf("%-24s", buf);
105 #endif
107 printf("\n");
110 static void
111 print_entry_long(kadm5_principal_ent_t princ)
113 char buf[1024];
114 int i;
116 krb5_unparse_name_fixed(context, princ->principal, buf, sizeof(buf));
117 printf("%24s: %s\n", "Principal", buf);
118 timeval2str(princ->princ_expire_time, buf, sizeof(buf), 1);
119 printf("%24s: %s\n", "Principal expires", buf);
121 timeval2str(princ->pw_expiration, buf, sizeof(buf), 1);
122 printf("%24s: %s\n", "Password expires", buf);
124 timeval2str(princ->last_pwd_change, buf, sizeof(buf), 1);
125 printf("%24s: %s\n", "Last password change", buf);
127 deltat2str(princ->max_life, buf, sizeof(buf));
128 printf("%24s: %s\n", "Max ticket life", buf);
130 deltat2str(princ->max_renewable_life, buf, sizeof(buf));
131 printf("%24s: %s\n", "Max renewable life", buf);
132 printf("%24s: %d\n", "Kvno", princ->kvno);
133 printf("%24s: %d\n", "Mkvno", princ->mkvno);
134 printf("%24s: %s\n", "Policy", princ->policy ? princ->policy : "none");
135 timeval2str(princ->last_success, buf, sizeof(buf), 1);
136 printf("%24s: %s\n", "Last successful login", buf);
137 timeval2str(princ->last_failed, buf, sizeof(buf), 1);
138 printf("%24s: %s\n", "Last failed login", buf);
139 printf("%24s: %d\n", "Failed login count", princ->fail_auth_count);
140 timeval2str(princ->mod_date, buf, sizeof(buf), 1);
141 printf("%24s: %s\n", "Last modified", buf);
142 krb5_unparse_name_fixed(context, princ->mod_name, buf, sizeof(buf));
143 printf("%24s: %s\n", "Modifier", buf);
144 attr2str (princ->attributes, buf, sizeof(buf));
145 printf("%24s: %s\n", "Attributes", buf);
147 printf("%24s: ", "Keytypes(salts)");
149 for (i = 0; i < princ->n_key_data; ++i) {
150 krb5_key_data *k = &princ->key_data[i];
151 krb5_error_code ret;
152 char *e_string, *s_string;
154 ret = krb5_enctype_to_string (context,
155 k->key_data_type[0],
156 &e_string);
157 if (ret)
158 asprintf (&e_string, "unknown(%d)", k->key_data_type[0]);
160 ret = krb5_salttype_to_string (context,
161 k->key_data_type[0],
162 k->key_data_type[1],
163 &s_string);
164 if (ret)
165 asprintf (&s_string, "unknown(%d)", k->key_data_type[1]);
167 printf ("%s%s(%s)", (i != 0) ? ", " : "", e_string, s_string);
168 free (e_string);
169 free (s_string);
171 printf("\n\n");
174 static int
175 do_get_entry(krb5_principal principal, void *data)
177 kadm5_principal_ent_rec princ;
178 krb5_error_code ret;
179 struct get_entry_data *e = data;
181 memset(&princ, 0, sizeof(princ));
182 ret = kadm5_get_principal(kadm_handle, principal,
183 &princ,
184 KADM5_PRINCIPAL_NORMAL_MASK|KADM5_KEY_DATA);
185 if(ret)
186 return ret;
187 else {
188 if(e->header) {
189 (*e->header)();
190 e->header = NULL; /* XXX only once */
192 (e->format)(&princ);
193 kadm5_free_principal_ent(kadm_handle, &princ);
195 return 0;
199 get_entry(int argc, char **argv)
201 int i;
202 krb5_error_code ret;
203 struct get_entry_data data;
204 struct getargs args[] = {
205 { "long", 'l', arg_flag, NULL, "long format" },
206 { "terse", 't', arg_flag, NULL, "terse format" },
208 int num_args = sizeof(args) / sizeof(args[0]);
209 int optind = 0;
210 int long_flag = 0;
211 int terse_flag = 0;
213 args[0].value = &long_flag;
214 args[1].value = &terse_flag;
215 if(getarg(args, num_args, argc, argv, &optind))
216 goto usage;
217 if(optind == argc)
218 goto usage;
220 if(long_flag) {
221 data.format = print_entry_long;
222 data.header = NULL;
223 } else if(terse_flag) {
224 data.format = print_entry_terse;
225 data.header = NULL;
226 } else {
227 data.format = print_entry_short;
228 data.header = print_header_short;
231 argc -= optind;
232 argv += optind;
234 for(i = 0; i < argc; i++)
235 ret = foreach_principal(argv[i], do_get_entry, &data);
236 return 0;
237 usage:
238 arg_printusage (args, num_args, "get", "principal...");
239 return 0;
243 list_princs(int argc, char **argv)
245 int i;
246 krb5_error_code ret;
247 struct get_entry_data data;
249 data.format = print_entry_terse;
250 data.header = NULL;
252 for(i = 1; i < argc; i++)
253 ret = foreach_principal(argv[i], do_get_entry, &data);
254 return 0;