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