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