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