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