death to register
[openafs.git] / src / auth / copyauth.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 <string.h>
15 #include <sys/types.h>
16 #include "auth.h"
17 #ifdef AFS_NT40_ENV
18 #include <winsock2.h>
19 #else
20 #include <netinet/in.h>
21 #endif
22 #include "cellconfig.h"
23 #include <afs/afsutil.h>
24
25 #include "AFS_component_version_number.c"
26
27 char whoami[256];
28
29 int
30 main(int argc, char **argv)
31 {
32     char localName[64];
33     afs_int32 code;
34     char *cname;
35     struct afsconf_dir *tdir;
36     struct ktc_principal tserver;
37     struct ktc_token token;
38
39     strcpy(whoami, argv[0]);
40
41     if (argc <= 1) {
42         printf
43             ("%s: copies a file system ticket from the local cell to another cell\n",
44              whoami);
45         printf("%s: usage is 'setauth <new-cell>\n", whoami);
46         exit(1);
47     }
48
49     cname = argv[1];
50
51     /* lookup the name of the local cell */
52     tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
53     if (!tdir) {
54         printf("copyauth: can't open dir %s\n", AFSDIR_CLIENT_ETC_DIRPATH);
55         exit(1);
56     }
57     code = afsconf_GetLocalCell(tdir, localName, sizeof(localName));
58     if (code) {
59         printf("%s: can't determine local cell name\n", whoami);
60         exit(1);
61     }
62     /* done with configuration stuff now */
63     afsconf_Close(tdir);
64
65
66     /* get ticket in local cell */
67     strcpy(tserver.cell, localName);
68     strcpy(tserver.name, "afs");
69     tserver.instance[0] = 0;
70     code = ktc_GetToken(&tserver, &token, sizeof(token), NULL);
71     if (code) {
72         printf
73             ("%s: failed to get '%s' service ticket in cell '%s' (code %d)\n",
74              whoami, tserver.name, tserver.cell, code);
75         exit(1);
76     }
77
78     /* and now set the ticket in the new cell */
79     strcpy(tserver.cell, argv[1]);
80     code = ktc_SetToken(&tserver, &token, NULL, 0);
81     if (code) {
82         printf
83             ("%s: failed to set ticket (code %d), are you sure you're authenticated?\n",
84              whoami, code);
85         exit(1);
86     }
87
88     /* all done */
89     printf("Authentication established for cell %s.\n", cname);
90     exit(0);
91 }