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