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
35 RCSID("$Id: kauth.c 15666 2005-07-19 17:08:11Z lha $");
41 kauth(int argc, char **argv)
46 des_key_schedule schedule;
47 KTEXT_ST tkt, tktcopy;
57 printf("usage: %s [principal]\n", argv[0]);
69 save = set_command_prot(prot_private);
70 ret = command("SITE KAUTH %s", name);
73 set_command_prot(save);
78 p = strstr(reply_string, "T=");
80 printf("Bad reply from server.\n");
81 set_command_prot(save);
86 tmp = base64_decode(p, &tkt.dat);
88 printf("Failed to decode base64 in reply.\n");
89 set_command_prot(save);
94 tktcopy.length = tkt.length;
96 p = strstr(reply_string, "P=");
98 printf("Bad reply from server.\n");
100 set_command_prot(save);
105 for(; *p && *p != ' ' && *p != '\r' && *p != '\n'; p++);
108 snprintf(buf, sizeof(buf), "Password for %s:", name);
109 if (des_read_pw_string (passwd, sizeof(passwd)-1, buf, 0))
111 des_string_to_key (passwd, &key);
113 des_key_sched(&key, schedule);
115 des_pcbc_encrypt((des_cblock*)tkt.dat, (des_cblock*)tktcopy.dat,
117 schedule, &key, DES_DECRYPT);
118 if (strcmp ((char*)tktcopy.dat + 8,
119 KRB_TICKET_GRANTING_TICKET) != 0) {
120 afs_string_to_key (passwd, krb_realmofhost(hostname), &key);
121 des_key_sched (&key, schedule);
122 des_pcbc_encrypt((des_cblock*)tkt.dat, (des_cblock*)tktcopy.dat,
124 schedule, &key, DES_DECRYPT);
126 memset(key, 0, sizeof(key));
127 memset(schedule, 0, sizeof(schedule));
128 memset(passwd, 0, sizeof(passwd));
129 if(base64_encode(tktcopy.dat, tktcopy.length, &p) < 0) {
130 printf("Out of memory base64-encoding.\n");
131 set_command_prot(save);
135 memset (tktcopy.dat, 0, tktcopy.length);
136 ret = command("SITE KAUTH %s %s", name, p);
138 set_command_prot(save);
147 kdestroy(int argc, char **argv)
151 printf("usage: %s\n", argv[0]);
155 ret = command("SITE KDESTROY");
156 code = (ret == COMPLETE);
160 krbtkfile(int argc, char **argv)
164 printf("usage: %s tktfile\n", argv[0]);
168 ret = command("SITE KRBTKFILE %s", argv[1]);
169 code = (ret == COMPLETE);
173 #if defined(KRB4) || defined(KRB5)
176 afslog(int argc, char **argv)
180 printf("usage: %s [cell]\n", argv[0]);
185 ret = command("SITE AFSLOG %s", argv[1]);
187 ret = command("SITE AFSLOG");
188 code = (ret == COMPLETE);
192 int ftp_afslog_placeholder;