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