summaryrefslogtreecommitdiffstats
path: root/src/kadmin.old/client/kadmin_msnd.c
blob: 8cfe6390688b5f0266a1626590c595c2e04a5957 (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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
 * kadmin/client/kadmin_msnd.c
 *
 * Copyright 1988 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <mit-copyright.h>.
 *
 */

/* 
 * 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.
 */


/*
 * kadmin_snd_mod
 * Perform Remote Kerberos Administrative Functions
 */

#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <signal.h>
#include <string.h>
#include <com_err.h>

#include <sys/param.h>
#include <pwd.h>

#include <sys/stat.h>

#include <krb5.h>
#include "adm_defs.h"

#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#else
extern char *malloc(), *calloc(), *realloc();
#endif

#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif

krb5_error_code
kadm_snd_mod(context, auth_context, my_creds, local_socket)
    krb5_context context;
    krb5_auth_context *auth_context;
    krb5_creds *my_creds;
    int *local_socket;
{
    krb5_replay_data replaydata;
    krb5_error_code retval;     /* return code */
    krb5_data msg_data, inbuf;
    char mod_type[10];
    char attrib[20];
    char version[10];
    int value;
    int valid_command;
    int i;

    for ( ; ; ) {
	valid_command = 0;
repeat1:
#ifdef SANDIA
	fprintf(stdout, "\nParameter Type to be Modified (fcnt, vno, attr, or q): ");
#else
	fprintf(stdout, "\nParameter Type to be Modified (vno, attr, or q): ");
#endif
                         
	(void) fgets(mod_type, 10, stdin);
	mod_type[strlen(mod_type) - 1] = '\0';

	if ((inbuf.data = (char *) calloc(1, 80)) == (char *) 0) {
            fprintf(stderr, "No memory for command!\n");
            exit(1);
	}

	if (!strcmp(mod_type, "q")) {
	    free(inbuf.data);
	    goto alldone;
	}
#ifdef SANDIA
	if (!strcmp(mod_type, "fcnt")) {
	    valid_command = 1;
repeat_cnt:
	    fprintf(stdout, "\nFailure Count: ");
	    (void) fgets(version, sizeof(version), stdin);
	    /* Make sure version is null terminated */
	    version[sizeof(version) -1] = '\0';
	    /* Strip linefeed */
	    if (version[strlen(version) - 1] == '\n')
	        version[strlen(version) - 1] = '\0';
	    if (!strcmp(version, "q")) {
            	free(inbuf.data);
            	goto alldone;
            }
	    value = -1;
	    sscanf(version,"%d",&value);
	    if (value < 0 || value > 10 ) {
	        fprintf(stderr, "Value must be between 0 and 10!\n");
	        goto repeat_cnt;
	    }
            inbuf.data[3] = KMODFCNT;
	    (void) memcpy(inbuf.data + 4, version, strlen(version));
	    inbuf.length = strlen(version) + 4;
        }
#endif
	if (!strcmp(mod_type, "vno")) {
	    valid_command = 1;
repeat2:
	    fprintf(stdout, "\nVersion Number: ");
            (void) fgets(version, sizeof(version), stdin);
            /* Make sure version is null terminated */
            version[sizeof(version) -1] = '\0';
            /* Strip linefeed */
            if (version[strlen(version) - 1] == '\n')
                version[strlen(version) - 1] = '\0';
            if (!strcmp(version, "q")) {
                free(inbuf.data);
                goto alldone;
            }
            value = -1;
            sscanf(version,"%d",&value);
	    if (value < 0 || value > 255 ) {
	        fprintf(stderr, "Value must be between 0 and 255!\n");
	        goto repeat2;
	    }
            inbuf.data[3] = KMODVNO;
	    (void) memcpy(inbuf.data + 4, version, strlen(version));
	    inbuf.length = strlen(version) + 4;
        }

	if (!strcmp(mod_type, "attr")) {
	     valid_command = 1;
repeat3:
	    fprintf(stdout, "\nAttribute: ");
	    fgets(attrib, 20, stdin);
	    attrib[strlen(attrib) - 1] = '\0';
	    for (i = 0; attrib[i] != '\0'; i++)
		if (isupper(attrib[i]))
		    attrib[i] = tolower(attrib[i]);

            inbuf.data[3] = KMODATTR;
	    inbuf.data[4] = BADATTR;
            inbuf.length = 5;
	    if (!strcmp(attrib, "post")) inbuf.data[4] = ATTRPOST;
	    if (!strcmp(attrib, "nopost")) inbuf.data[4] = ATTRNOPOST;
	    if (!strcmp(attrib, "forward")) inbuf.data[4] = ATTRFOR;
	    if (!strcmp(attrib, "noforward")) inbuf.data[4] = ATTRNOFOR;
	    if (!strcmp(attrib, "tgt")) inbuf.data[4] = ATTRTGT;
	    if (!strcmp(attrib, "notgt")) inbuf.data[4] = ATTRNOTGT;
	    if (!strcmp(attrib, "ren")) inbuf.data[4] = ATTRREN;
	    if (!strcmp(attrib, "noren")) inbuf.data[4] = ATTRNOREN;
	    if (!strcmp(attrib, "proxy")) inbuf.data[4] = ATTRPROXY;
	    if (!strcmp(attrib, "noproxy")) inbuf.data[4] = ATTRNOPROXY;
	    if (!strcmp(attrib, "dskey")) inbuf.data[4] = ATTRDSKEY;
	    if (!strcmp(attrib, "nodskey")) inbuf.data[4] = ATTRNODSKEY;
	    if (!strcmp(attrib, "lock")) inbuf.data[4] = ATTRLOCK;
	    if (!strcmp(attrib, "unlock")) inbuf.data[4] = ATTRUNLOCK;
	    if (!strcmp(attrib, "svr")) inbuf.data[4] = ATTRSVR;
	    if (!strcmp(attrib, "nosvr")) inbuf.data[4] = ATTRNOSVR;

#ifdef SANDIA
	    if (!strcmp(attrib, "preauth")) inbuf.data[4] = ATTRPRE;
	    if (!strcmp(attrib, "nopreauth")) inbuf.data[4] = ATTRNOPRE;
	    if (!strcmp(attrib, "pwok")) inbuf.data[4] = ATTRPWOK;
	    if (!strcmp(attrib, "pwchange")) inbuf.data[4] = ATTRPWCHG;
	    if (!strcmp(attrib, "sid")) inbuf.data[4] = ATTRSID;
	    if (!strcmp(attrib, "nosid")) inbuf.data[4] = ATTRNOSID;
#endif
	    if (!strcmp(attrib, "q")){
            	free(inbuf.data);
            	goto alldone;
            }
	    if (inbuf.data[4] == BADATTR) {
	        fprintf(stderr, "Valid Responses are:\n");
	        fprintf(stderr, "post/nopost - Allow/Disallow postdating\n");
	        fprintf(stderr, "forward/noforward - Allow/Disallow forwarding\n");
	        fprintf(stderr, "tgt/notgt - Allow/Disallow initial tickets\n");
	        fprintf(stderr, "ren/noren - Allow/Disallow renewable tickets\n");
	        fprintf(stderr, 
		    "proxy/noproxy - Allow/Disallow proxiable tickets\n");
	            fprintf(stderr, 
		    "dskey/nodskey - Allow/Disallow Duplicate Session Keys\n");
	        fprintf(stderr, "lock/unlock - Lock/Unlock client\n");
		fprintf(stderr, 
		    "svr/nosvr - Allow/Disallow Use of Principal as Server\n");
#ifdef SANDIA
	        fprintf(stderr, 
		    "preauth/nopreauth - Require/Do Not Require preauthentication\n");
		fprintf(stderr, 
		   "pwok/pwchange - Password is OK/Needs to be changed\n");
	        fprintf(stderr, 
		    "sid/nosid - Require/Do Not Require Hardware Authentication\n");
#endif
		fprintf(stderr, "q - Quit from setting attributes.\n");
	        goto repeat3;
	    }
	}

	if (!valid_command) {
	    free(inbuf.data);
	    fprintf(stderr, "Invalid command - Try Again\n");
	    goto repeat1;
	}

	inbuf.data[0] = KADMIN;
	inbuf.data[1] = MODOPER;
	inbuf.data[2] = SENDDATA3;

	if ((retval = krb5_mk_priv(context, auth_context, &inbuf,
				   &msg_data, &replaydata))) {
            fprintf(stderr, "Error during Second Message Encoding: %s!\n",
			error_message(retval));
	    free(inbuf.data);
            return(1);
	}
	free(inbuf.data);

    /* write private message to server */
	if (krb5_write_message(context, local_socket, &msg_data)) {
            fprintf(stderr, "Write Error During Second Message Transmission!\n");
            return(1);
	} 
	free(msg_data.data);

    /* Ok Now let's get the private message */
	if (retval = krb5_read_message(context, local_socket, &inbuf)){
            fprintf(stderr, "Read Error During Second Reply: %s!\n",
                        error_message(retval));
            return(1);
	}

	if ((retval = krb5_rd_priv(context, auth_context, &inbuf,
                      		   &msg_data, &replaydata))) {
            fprintf(stderr, "Error during Second Read Decoding :%s!\n",
                        error_message(retval));
            free(inbuf.data);
            return(1);     
	}
	free(inbuf.data);
    }	/* for */

alldone:
    if ((inbuf.data = (char *) calloc(1, 80)) == (char *) 0) {
	fprintf(stderr, "No memory for command!\n");
	exit(1);
    }

    inbuf.data[0] = KADMIN;
    inbuf.data[1] = KADMGOOD;
    inbuf.data[2] = SENDDATA3;
    inbuf.length = 3;

    if ((retval = krb5_mk_priv(context, auth_context, &inbuf,
			       &msg_data, &replaydata))) {
	fprintf(stderr, "Error during Second Message Encoding: %s!\n",
			error_message(retval));
	free(inbuf.data);
	return(1);
    }
    free(inbuf.data);

    /* write private message to server */
    if (krb5_write_message(context, local_socket, &msg_data)) {
	fprintf(stderr, "Write Error During Second Message Transmission!\n");
	return(1);
    } 
    free(msg_data.data);

    return(0);
}