summaryrefslogtreecommitdiffstats
path: root/src/kadmin/server/adm_parse.c
blob: aaf7b31d4521cd42690e1ffca49e4ac5fc8a24ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#ifdef SANDIA
/*
 * kadmin/server/adm_parse.c
 *
 * Copyright 1990,1991 by the Massachusetts Institute of Technology.
 * All Rights Reserved.
 *
 * Export of this software from the United States of America may
 *   require a specific license from the United States Government.
 *   It is the responsibility of any person or organization contemplating
 *   export to obtain such a license before exporting.
 *
 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
 * distribute this software and its documentation for any purpose and
 * without fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation, and that
 * the name of M.I.T. not be used in advertising or publicity pertaining
 * to distribution of the software without specific, written prior
 * permission.  M.I.T. makes no representations about the suitability of
 * this software for any purpose.  It is provided "as is" without express
 * or implied warranty.
 *
 * Sandia National Laboratories also makes no representations about the
 * suitability of the modifications, or additions to this software for
 * any purpose.  It is provided "as is" without express or implied warranty.
 *
 * Edit a KDC database.
 */

 
#include <syslog.h>
#include <stdio.h>

#if defined (unicos61) || (defined(mips) && defined(SYSTYPE_BSD43)) || defined(sysvimp)
#include <time.h>
#else
#include <sys/time.h>
#endif  /* unicos61 */
#if defined(aux20)
#include <time.h>
#endif  /* aux20 */

#include <krb5/krb5.h>
#include <krb5/kdb.h>
#include <krb5/kdb_dbm.h>

void
kadmin_parse_and_set(input_string)
char *input_string;
{
    extern int classification;
    extern krb5_kvno KDB5_VERSION_NUM;
    extern krb5_deltat KDB5_MAX_TKT_LIFE;
    extern krb5_deltat KDB5_MAX_REN_LIFE;
    extern krb5_timestamp KDB5_EXP_DATE;
    extern krb5_flags NEW_ATTRIBUTES;

    int num_args;
    char parameter[40];
    char first_token[40];
    char second_token[40];
 
    int bypass = 0;

    struct tm exp_date;
    long todays_date;
    int year;
    int month;
    int mday;

    first_token[0] = second_token[0] = '\0';
    num_args = sscanf(input_string, "%s %s %s", parameter,
                        first_token, second_token);

    if (strcmp(parameter, "BYPASS") == 0) {
        bypass++;
        syslog(LOG_ERR,
	  "CAUTION: Classified and  Unclassified Principals will be allowed");
	return;
    }
 
    if (strcmp(parameter, "CLASSIFICATION") == 0) {
        if (strcmp(first_token, "CLASS") == 0) {
            classification = 1;
            if (bypass) classification = 0;
	}
	return;
    }

    if (strcmp(parameter, "VERSION_NUM") == 0) {
        if (num_args < 2) {
                KDB5_VERSION_NUM  = 1;
        } else {
                KDB5_VERSION_NUM = atoi(first_token);
        }
        return;
    }    

    if (strcmp(parameter, "MAX_TKT_LIFE") == 0) {
        if (num_args < 2) {
                KDB5_MAX_TKT_LIFE = KRB5_KDB_MAX_LIFE;
        } else {
            switch (second_token[0]) {
                case 's':
                        KDB5_MAX_TKT_LIFE = atoi(first_token);
                        break;
                case 'm':
                        KDB5_MAX_TKT_LIFE = atoi(first_token) * 60;
                        break;
                case 'h':
                        KDB5_MAX_TKT_LIFE = atoi(first_token) * 3600;
                        break;
                case 'd':
                        KDB5_MAX_TKT_LIFE = atoi(first_token) * 86400;
                        break;
                case 'w':
                        KDB5_MAX_TKT_LIFE = atoi(first_token) * 604800;
                        break;
                case 'M':               /* 30 days */
                        KDB5_MAX_TKT_LIFE = atoi(first_token) * 18144000;
                        break;
                case 'y':               /* 365 days */
                        KDB5_MAX_TKT_LIFE = atoi(first_token) * 220752000;
                        break;
                case 'e':               /* eternity */
                        KDB5_MAX_TKT_LIFE = 2145830400;
                        break;
                default:
                        break;
            }            
        }
        return;
    }    

    if (strcmp(parameter, "MAX_REN_LIFE") == 0) {
        if (num_args < 2) {
                KDB5_MAX_REN_LIFE = KRB5_KDB_MAX_RLIFE;
        } else {
            switch (second_token[0]) {
                case 's':
                        KDB5_MAX_REN_LIFE = atoi(first_token);
                        break;
                case 'm':
                        KDB5_MAX_REN_LIFE = atoi(first_token) * 60;
                        break;
                case 'h':
                        KDB5_MAX_REN_LIFE = atoi(first_token) * 3600;
                        break;
                case 'd':
                        KDB5_MAX_REN_LIFE = atoi(first_token) * 86400;
                        break;
                case 'w':
                        KDB5_MAX_REN_LIFE = atoi(first_token) * 604800;
                        break;
                case 'M':               /* 30 days */
                        KDB5_MAX_REN_LIFE = atoi(first_token) * 18144000;
                        break;
                case 'y':               /* 365 days */
                        KDB5_MAX_REN_LIFE = atoi(first_token) * 220752000;
                        break;
                case 'e':               /* eternity */
                        KDB5_MAX_REN_LIFE = 2145830400;
                        break;
                default:
                        break;
            }
        }
        return;
    }    
 
 
    if (strcmp(parameter, "SET_EXP_DATE") == 0) {
        (void) time(&todays_date);
        switch (first_token[0]) {
              case 'e':               /* eternity */
                      KDB5_EXP_DATE = 2145830400;
                      year = 2037;
                      month = 12;
                      mday = 30;
                      sprintf(first_token, "%s", "eternity");
                      break;
              case 'y':               /* yesterday */
                      KDB5_EXP_DATE = todays_date - 86400;
                      year = 1970;
                      month = 01;
                      mday = 01;
                      sprintf(first_token, "%s", "yesterday");
                      break;
              case '0':
              case '1':
              case '2':
              case '3':
              case '9':
                sscanf(first_token, "%d/%d/%d", &year, &month, &mday);
                      year = (year > 1900) ? year - 1900 : year;
                      year = (year > 137) ? year - 100 : year;
                      year = (year > 137) ? 137 : year;
                      exp_date.tm_year =
                         ((year >= 00 && year < 38) ||
                          (year >= 70 && year <= 138)) ? year : 137;
                      exp_date.tm_mon =
                          (month >= 1 &&
                           month <= 12) ? month - 1 : 0;
                      exp_date.tm_mday =
                          (mday >= 1 &&
                           mday <= 31) ? mday : 1;
                      exp_date.tm_hour = 0;
                      exp_date.tm_min = 1;
                      exp_date.tm_sec = 0;
                      KDB5_EXP_DATE = convert_tm_to_sec(&exp_date);
                      break;
              default:
                      KDB5_EXP_DATE = KRB5_KDB_EXPIRATION;
                      sprintf(first_token, "%s", "Default KDB Expiration");
                      break;
        }
        if (year < 1900) year += 1900;
        if (year < 1938) year += 100;
        return;
    }
 
    if (strcmp(parameter, "SET_PWCHG") == 0) {
        if (num_args < 2) {
           NEW_ATTRIBUTES = NEW_ATTRIBUTES | KRB5_KDB_REQUIRES_PWCHANGE;
        } else {
            if (first_token[0] == 'y' || first_token[0] == 'Y') {
                NEW_ATTRIBUTES = NEW_ATTRIBUTES | KRB5_KDB_REQUIRES_PWCHANGE;
            } else {
                NEW_ATTRIBUTES = NEW_ATTRIBUTES & ~KRB5_KDB_REQUIRES_PWCHANGE;
                KDB5_VERSION_NUM  = 1;
            }
        }
        return;
    }    

    if (strcmp(parameter, "SET_PREAUTH") == 0) {
        if (num_args < 2) {
           NEW_ATTRIBUTES = NEW_ATTRIBUTES | KRB5_KDB_REQUIRES_PRE_AUTH;
        } else {
            if (first_token[0] == 'y' || first_token[0] == 'Y') {
                NEW_ATTRIBUTES = NEW_ATTRIBUTES | KRB5_KDB_REQUIRES_PRE_AUTH;
            } else {
                NEW_ATTRIBUTES = NEW_ATTRIBUTES & ~KRB5_KDB_REQUIRES_PRE_AUTH;
            }
        }
        return;
    }    

    if (strcmp(parameter, "SET_SECUREID") == 0) {
        if (num_args < 2) {
           NEW_ATTRIBUTES = NEW_ATTRIBUTES | KRB5_KDB_REQUIRES_HW_AUTH |
                KRB5_KDB_REQUIRES_PRE_AUTH;
        } else {
            if (first_token[0] == 'y' || first_token[0] == 'Y') {
                NEW_ATTRIBUTES = NEW_ATTRIBUTES | KRB5_KDB_REQUIRES_HW_AUTH |
                        KRB5_KDB_REQUIRES_PRE_AUTH;
            } else {
                NEW_ATTRIBUTES = NEW_ATTRIBUTES & ~KRB5_KDB_REQUIRES_HW_AUTH;
            }
        }
        return;
    }
}
#endif