death to register
[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
14 #include <sys/types.h>
15 #include <netinet/in.h>
16 #ifdef  AFS_AIX32_ENV
17 #include <signal.h>
18 #endif
19
20 #include <string.h>
21
22 #include <afs/cellconfig.h>
23 #include <afs/afsutil.h>
24 #include <afs/auth.h>
25 #include <rx/xdr.h>
26 #include <rx/rx.h>
27 #include <des.h>
28 #include <rx/rxkad.h>
29
30 #include "AFS_component_version_number.c"
31
32 int
33 main(int argc, char **argv)
34 {
35     struct ktc_token token;
36     struct ktc_principal sname;
37     afs_int32 code;
38     struct afsconf_dir *dir;
39     afs_int32 now;
40     char skey[9];
41     char cellName[MAXKTCNAMELEN];
42     char session[8];
43
44 #ifdef  AFS_AIX32_ENV
45     /*
46      * The following signal action for AIX is necessary so that in case of a 
47      * crash (i.e. core is generated) we can include the user's data section 
48      * in the core dump. Unfortunately, by default, only a partial core is
49      * generated which, in many cases, isn't too useful.
50      */
51     struct sigaction nsa;
52
53     sigemptyset(&nsa.sa_mask);
54     nsa.sa_handler = SIG_DFL;
55     nsa.sa_flags = SA_FULLDUMP;
56     sigaction(SIGSEGV, &nsa, NULL);
57 #endif
58     if (argc != 3) {
59         printf("kseal: usage is 'kseal <username> <server key>\n");
60         exit(1);
61     }
62
63     /* lookup configuration info */
64     dir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
65     if (!dir) {
66         printf("kseal: can't open config dir (%s)\n",
67                AFSDIR_CLIENT_ETC_DIRPATH);
68         exit(1);
69     }
70     code = afsconf_GetLocalCell(dir, cellName, sizeof(cellName));
71     if (code) {
72         printf("kseal: failed to get local cell name, code %d\n", code);
73         exit(1);
74     }
75
76     /* setup key for sealing */
77     string_to_key(argv[2], skey);
78
79     now = time(0);
80     memcpy(session, &now, 4);   /* but this is only a test pgm */
81     memcpy(session + 4, &now, 4);
82     code =
83         tkt_MakeTicket(token.ticket, &token.ticketLen, skey, argv[1], "",
84                        cellName, now - 300, now + 25 * 3600, session,
85                        /* host */ 0, "afs", "");
86     if (code) {
87         printf("kseal: could not seal ticket, code %d!\n", code);
88         exit(1);
89     }
90
91     /* now send the ticket to the ticket cache */
92     strcpy(sname.name, "afs");
93     strcpy(sname.instance, "");
94     strcpy(sname.cell, cellName);
95     token.startTime = 0;
96     token.endTime = 0x7fffffff;
97     memcpy(&token.sessionKey, session, 8);
98     token.kvno = 0;
99     code = ktc_SetToken(&sname, &token, NULL, 0);
100     if (code) {
101         printf("kseal: could not install newly-sealed ticket, code %d\n",
102                code);
103         exit(1);
104     }
105
106     /* all done */
107     afsconf_Close(dir);
108     exit(0);
109 }