2 * Copyright (c) 1995, 1996, 1997 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. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the Kungliga Tekniska
20 * Högskolan and its contributors.
22 * 4. Neither the name of the Institute nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 kauth(int argc
, char **argv
)
48 des_key_schedule schedule
;
49 KTEXT_ST tkt
, tktcopy
;
57 printf("usage: %s [principal]\n", argv
[0]);
69 ret
= command("SITE KAUTH %s", name
);
76 p
= strstr(reply_string
, "T=");
78 printf("Bad reply from server.\n");
83 tmp
= base64_decode(p
, &tkt
.dat
);
85 printf("Failed to decode base64 in reply.\n");
90 tktcopy
.length
= tkt
.length
;
92 p
= strstr(reply_string
, "P=");
94 printf("Bad reply from server.\n");
100 for(; *p
&& *p
!= ' ' && *p
!= '\r' && *p
!= '\n'; p
++);
103 snprintf(buf
, sizeof(buf
), "Password for %s:", name
);
104 if (des_read_pw_string (passwd
, sizeof(passwd
)-1, buf
, 0))
106 des_string_to_key (passwd
, &key
);
108 des_key_sched(&key
, schedule
);
110 des_pcbc_encrypt((des_cblock
*)tkt
.dat
, (des_cblock
*)tktcopy
.dat
,
112 schedule
, &key
, DES_DECRYPT
);
113 if (strcmp ((char*)tktcopy
.dat
+ 8,
114 KRB_TICKET_GRANTING_TICKET
) != 0) {
115 afs_string_to_key (passwd
, krb_realmofhost(hostname
), &key
);
116 des_key_sched (&key
, schedule
);
117 des_pcbc_encrypt((des_cblock
*)tkt
.dat
, (des_cblock
*)tktcopy
.dat
,
119 schedule
, &key
, DES_DECRYPT
);
121 memset(key
, 0, sizeof(key
));
122 memset(schedule
, 0, sizeof(schedule
));
123 memset(passwd
, 0, sizeof(passwd
));
124 if(base64_encode(tktcopy
.dat
, tktcopy
.length
, &p
) < 0) {
125 printf("Out of memory base64-encoding.\n");
129 memset (tktcopy
.dat
, 0, tktcopy
.length
);
130 ret
= command("SITE KAUTH %s %s", name
, p
);
140 klist(int argc
, char **argv
)
144 printf("usage: %s\n", argv
[0]);
149 ret
= command("SITE KLIST");
150 code
= (ret
== COMPLETE
);
154 kdestroy(int argc
, char **argv
)
158 printf("usage: %s\n", argv
[0]);
162 ret
= command("SITE KDESTROY");
163 code
= (ret
== COMPLETE
);
167 krbtkfile(int argc
, char **argv
)
171 printf("usage: %s tktfile\n", argv
[0]);
175 ret
= command("SITE KRBTKFILE %s", argv
[1]);
176 code
= (ret
== COMPLETE
);
180 afslog(int argc
, char **argv
)
184 printf("usage: %s [cell]\n", argv
[0]);
189 ret
= command("SITE AFSLOG %s", argv
[1]);
191 ret
= command("SITE AFSLOG");
192 code
= (ret
== COMPLETE
);