move up roken-common.h again.
[heimdal.git] / kadmin / mod.c
blob6350cfb94c33065872e231de2a70d0e16a29290f
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. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #include "kadmin_locl.h"
36 RCSID("$Id$");
38 static int parse_args (krb5_context context, kadm5_principal_ent_t ent,
39 int argc, char **argv, int *optind, char *name,
40 int *mask);
42 static int
43 parse_args(krb5_context context, kadm5_principal_ent_t ent,
44 int argc, char **argv, int *optind, char *name,
45 int *mask)
47 char *attr_str = NULL;
48 char *max_life_str = NULL;
49 char *max_rlife_str = NULL;
50 char *expiration_str = NULL;
51 char *pw_expiration_str = NULL;
52 int ret, i;
54 struct getargs args[] = {
55 {"attributes", 'a', arg_string, NULL, "Attributies",
56 "attributes"},
57 {"max-ticket-life", 0, arg_string, NULL, "max ticket lifetime",
58 "lifetime"},
59 {"max-renewable-life", 0, arg_string, NULL,
60 "max renewable lifetime", "lifetime" },
61 {"expiration-time", 0, arg_string,
62 NULL, "Expiration time", "time"},
63 {"pw-expiration-time", 0, arg_string,
64 NULL, "Password expiration time", "time"},
67 i = 0;
68 args[i++].value = &attr_str;
69 args[i++].value = &max_life_str;
70 args[i++].value = &max_rlife_str;
71 args[i++].value = &expiration_str;
72 args[i++].value = &pw_expiration_str;
74 *optind = 0; /* XXX */
76 if(getarg(args, sizeof(args) / sizeof(args[0]),
77 argc, argv, optind)){
78 arg_printusage(args,
79 sizeof(args) / sizeof(args[0]),
80 name ? name : "",
81 "principal");
82 return -1;
85 ret = set_entry(context, ent, mask, max_life_str, max_rlife_str,
86 expiration_str, pw_expiration_str, attr_str);
87 if (ret)
88 return ret;
89 return 0;
92 int
93 mod_entry(int argc, char **argv)
95 kadm5_principal_ent_rec princ;
96 int mask = 0;
97 krb5_error_code ret;
98 krb5_principal princ_ent = NULL;
99 int optind;
101 memset (&princ, 0, sizeof(princ));
103 ret = parse_args (context, &princ, argc, argv,
104 &optind, "mod", &mask);
105 if (ret)
106 return 0;
108 argc -= optind;
109 argv += optind;
111 if (argc != 1) {
112 printf ("Usage: mod [options] principal\n");
113 return 0;
116 krb5_parse_name(context, argv[0], &princ_ent);
118 if (mask == 0) {
119 memset(&princ, 0, sizeof(princ));
120 ret = kadm5_get_principal(kadm_handle, princ_ent, &princ,
121 KADM5_PRINCIPAL | KADM5_ATTRIBUTES |
122 KADM5_MAX_LIFE | KADM5_MAX_RLIFE |
123 KADM5_PRINC_EXPIRE_TIME |
124 KADM5_PW_EXPIRATION);
125 if (ret) {
126 printf ("no such principal: %s\n", argv[0]);
127 krb5_free_principal (context, princ_ent);
128 return 0;
130 edit_entry(&princ, &mask, NULL, 0);
132 } else {
133 princ.principal = princ_ent;
136 ret = kadm5_modify_principal(kadm_handle, &princ, mask);
137 if(ret)
138 krb5_warn(context, ret, "kadm5_modify_principal");
139 if(princ_ent)
140 krb5_free_principal(context, princ_ent);
141 kadm5_free_principal_ent(kadm_handle, &princ);
142 return 0;