remove gcc34
[dragonfly.git] / crypto / heimdal-0.6.3 / kadmin / mod.c
blob0e9cd08c7f7e4ae3496769d16ef06263ad07e320
1 /*
2 * Copyright (c) 1997 - 2000 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: mod.c,v 1.11 2002/12/03 14:12:30 joda Exp $");
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 new_kvno = -1;
53 int ret, i;
55 struct getargs args[] = {
56 {"attributes", 'a', arg_string, NULL, "Attributies",
57 "attributes"},
58 {"max-ticket-life", 0, arg_string, NULL, "max ticket lifetime",
59 "lifetime"},
60 {"max-renewable-life", 0, arg_string, NULL,
61 "max renewable lifetime", "lifetime" },
62 {"expiration-time", 0, arg_string,
63 NULL, "Expiration time", "time"},
64 {"pw-expiration-time", 0, arg_string,
65 NULL, "Password expiration time", "time"},
66 {"kvno", 0, arg_integer,
67 NULL, "Key version number", "number"},
70 i = 0;
71 args[i++].value = &attr_str;
72 args[i++].value = &max_life_str;
73 args[i++].value = &max_rlife_str;
74 args[i++].value = &expiration_str;
75 args[i++].value = &pw_expiration_str;
76 args[i++].value = &new_kvno;
78 *optind = 0; /* XXX */
80 if(getarg(args, sizeof(args) / sizeof(args[0]),
81 argc, argv, optind)){
82 arg_printusage(args,
83 sizeof(args) / sizeof(args[0]),
84 name ? name : "",
85 "principal");
86 return -1;
89 ret = set_entry(context, ent, mask, max_life_str, max_rlife_str,
90 expiration_str, pw_expiration_str, attr_str);
91 if (ret)
92 return ret;
94 if(new_kvno != -1) {
95 ent->kvno = new_kvno;
96 *mask |= KADM5_KVNO;
98 return 0;
102 mod_entry(int argc, char **argv)
104 kadm5_principal_ent_rec princ;
105 int mask = 0;
106 krb5_error_code ret;
107 krb5_principal princ_ent = NULL;
108 int optind;
110 memset (&princ, 0, sizeof(princ));
112 ret = parse_args (context, &princ, argc, argv,
113 &optind, "mod", &mask);
114 if (ret)
115 return 0;
117 argc -= optind;
118 argv += optind;
120 if (argc != 1) {
121 printf ("Usage: mod [options] principal\n");
122 return 0;
125 krb5_parse_name(context, argv[0], &princ_ent);
127 if (mask == 0) {
128 memset(&princ, 0, sizeof(princ));
129 ret = kadm5_get_principal(kadm_handle, princ_ent, &princ,
130 KADM5_PRINCIPAL | KADM5_ATTRIBUTES |
131 KADM5_MAX_LIFE | KADM5_MAX_RLIFE |
132 KADM5_PRINC_EXPIRE_TIME |
133 KADM5_PW_EXPIRATION);
134 krb5_free_principal (context, princ_ent);
135 if (ret) {
136 printf ("no such principal: %s\n", argv[0]);
137 return 0;
139 if(edit_entry(&princ, &mask, NULL, 0))
140 goto out;
141 } else {
142 princ.principal = princ_ent;
145 ret = kadm5_modify_principal(kadm_handle, &princ, mask);
146 if(ret)
147 krb5_warn(context, ret, "kadm5_modify_principal");
148 out:
149 kadm5_free_principal_ent(kadm_handle, &princ);
150 return 0;