Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / log / kseal.c
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 #include <roken.h>
14
15 #include <afs/cellconfig.h>
16 #include <afs/afsutil.h>
17 #include <afs/auth.h>
18
19 #include <rx/xdr.h>
20 #include <rx/rx.h>
21
22 #include <des.h>
23
24 #include <rx/rxkad.h>
25
26 #include "AFS_component_version_number.c"
27
28 int
29 main(int argc, char **argv)
30 {
31 struct ktc_token token;
32 struct ktc_principal sname;
33 afs_int32 code;
34 struct afsconf_dir *dir;
35 afs_int32 now;
36 char skey[9];
37 char cellName[MAXKTCNAMELEN];
38 char session[8];
39
40 #ifdef AFS_AIX32_ENV
41 /*
42 * The following signal action for AIX is necessary so that in case of a
43 * crash (i.e. core is generated) we can include the user's data section
44 * in the core dump. Unfortunately, by default, only a partial core is
45 * generated which, in many cases, isn't too useful.
46 */
47 struct sigaction nsa;
48
49 sigemptyset(&nsa.sa_mask);
50 nsa.sa_handler = SIG_DFL;
51 nsa.sa_flags = SA_FULLDUMP;
52 sigaction(SIGSEGV, &nsa, NULL);
53 #endif
54 if (argc != 3) {
55 printf("kseal: usage is 'kseal <username> <server key>\n");
56 exit(1);
57 }
58
59 /* lookup configuration info */
60 dir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
61 if (!dir) {
62 printf("kseal: can't open config dir (%s)\n",
63 AFSDIR_CLIENT_ETC_DIRPATH);
64 exit(1);
65 }
66 code = afsconf_GetLocalCell(dir, cellName, sizeof(cellName));
67 if (code) {
68 printf("kseal: failed to get local cell name, code %d\n", code);
69 exit(1);
70 }
71
72 /* setup key for sealing */
73 string_to_key(argv[2], skey);
74
75 now = time(0);
76 memcpy(session, &now, 4); /* but this is only a test pgm */
77 memcpy(session + 4, &now, 4);
78 code =
79 tkt_MakeTicket(token.ticket, &token.ticketLen, skey, argv[1], "",
80 cellName, now - 300, now + 25 * 3600, session,
81 /* host */ 0, "afs", "");
82 if (code) {
83 printf("kseal: could not seal ticket, code %d!\n", code);
84 exit(1);
85 }
86
87 /* now send the ticket to the ticket cache */
88 strcpy(sname.name, "afs");
89 strcpy(sname.instance, "");
90 strcpy(sname.cell, cellName);
91 token.startTime = 0;
92 token.endTime = 0x7fffffff;
93 memcpy(&token.sessionKey, session, 8);
94 token.kvno = 0;
95 code = ktc_SetToken(&sname, &token, NULL, 0);
96 if (code) {
97 printf("kseal: could not install newly-sealed ticket, code %d\n",
98 code);
99 exit(1);
100 }
101
102 /* all done */
103 afsconf_Close(dir);
104 exit(0);
105 }