2 * Copyright (c) 1995-1999 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
36 RCSID("$Id: kauth.c,v 1.20 1999/12/02 16:58:29 joda Exp $");
39 kauth(int argc, char **argv)
44 des_key_schedule schedule;
45 KTEXT_ST tkt, tktcopy;
55 printf("usage: %s [principal]\n", argv[0]);
67 save = set_command_prot(prot_private);
68 ret = command("SITE KAUTH %s", name);
71 set_command_prot(save);
76 p = strstr(reply_string, "T=");
78 printf("Bad reply from server.\n");
79 set_command_prot(save);
84 tmp = base64_decode(p, &tkt.dat);
86 printf("Failed to decode base64 in reply.\n");
87 set_command_prot(save);
92 tktcopy.length = tkt.length;
94 p = strstr(reply_string, "P=");
96 printf("Bad reply from server.\n");
98 set_command_prot(save);
103 for(; *p && *p != ' ' && *p != '\r' && *p != '\n'; p++);
106 snprintf(buf, sizeof(buf), "Password for %s:", name);
107 if (des_read_pw_string (passwd, sizeof(passwd)-1, buf, 0))
109 des_string_to_key (passwd, &key);
111 des_key_sched(&key, schedule);
113 des_pcbc_encrypt((des_cblock*)tkt.dat, (des_cblock*)tktcopy.dat,
115 schedule, &key, DES_DECRYPT);
116 if (strcmp ((char*)tktcopy.dat + 8,
117 KRB_TICKET_GRANTING_TICKET) != 0) {
118 afs_string_to_key (passwd, krb_realmofhost(hostname), &key);
119 des_key_sched (&key, schedule);
120 des_pcbc_encrypt((des_cblock*)tkt.dat, (des_cblock*)tktcopy.dat,
122 schedule, &key, DES_DECRYPT);
124 memset(key, 0, sizeof(key));
125 memset(schedule, 0, sizeof(schedule));
126 memset(passwd, 0, sizeof(passwd));
127 if(base64_encode(tktcopy.dat, tktcopy.length, &p) < 0) {
128 printf("Out of memory base64-encoding.\n");
129 set_command_prot(save);
133 memset (tktcopy.dat, 0, tktcopy.length);
134 ret = command("SITE KAUTH %s %s", name, p);
136 set_command_prot(save);
145 klist(int argc, char **argv)
149 printf("usage: %s\n", argv[0]);
154 ret = command("SITE KLIST");
155 code = (ret == COMPLETE);
159 kdestroy(int argc, char **argv)
163 printf("usage: %s\n", argv[0]);
167 ret = command("SITE KDESTROY");
168 code = (ret == COMPLETE);
172 krbtkfile(int argc, char **argv)
176 printf("usage: %s tktfile\n", argv[0]);
180 ret = command("SITE KRBTKFILE %s", argv[1]);
181 code = (ret == COMPLETE);
185 afslog(int argc, char **argv)
189 printf("usage: %s [cell]\n", argv[0]);
194 ret = command("SITE AFSLOG %s", argv[1]);
196 ret = command("SITE AFSLOG");
197 code = (ret == COMPLETE);