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