s3:lib/afs fix the build with --with-fake-kaserver
[Samba.git] / source3 / utils / net_afs.c
blobe8d28f48fd88551563087ac7ac86a69a202574da
1 /*
2 Samba Unix/Linux SMB client library
3 net afs commands
4 Copyright (C) 2003 Volker Lendecke (vl@samba.org)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "utils/net.h"
22 #include "secrets.h"
23 #include "system/filesys.h"
25 int net_afs_usage(struct net_context *c, int argc, const char **argv)
27 d_printf(_(" net afs key filename\n"
28 "\tImports a OpenAFS KeyFile into our secrets.tdb\n\n"));
29 d_printf(_(" net afs impersonate <user> <cell>\n"
30 "\tCreates a token for user@cell\n\n"));
31 return -1;
34 int net_afs_key(struct net_context *c, int argc, const char **argv)
36 int fd;
37 struct afs_keyfile keyfile;
39 if (argc != 2) {
40 d_printf(_("Usage:")," net afs key <keyfile> cell\n");
41 return -1;
44 if (!secrets_init()) {
45 d_fprintf(stderr, _("Could not open secrets.tdb\n"));
46 return -1;
49 if ((fd = open(argv[0], O_RDONLY, 0)) < 0) {
50 d_fprintf(stderr, _("Could not open %s\n"), argv[0]);
51 return -1;
54 if (read(fd, &keyfile, sizeof(keyfile)) != sizeof(keyfile)) {
55 d_fprintf(stderr, _("Could not read keyfile\n"));
56 close(fd);
57 return -1;
59 close(fd);
61 if (!secrets_store_afs_keyfile(argv[1], &keyfile)) {
62 d_fprintf(stderr, _("Could not write keyfile to secrets.tdb\n"));
63 return -1;
66 return 0;
69 int net_afs_impersonate(struct net_context *c, int argc,
70 const char **argv)
72 char *token;
74 if (argc != 2) {
75 fprintf(stderr, _("Usage:")," net afs impersonate <user> <cell>\n");
76 exit(1);
79 token = afs_createtoken_str(argv[0], argv[1]);
81 if (token == NULL) {
82 fprintf(stderr, _("Could not create token\n"));
83 exit(1);
86 if (!afs_settoken_str(token)) {
87 fprintf(stderr, _("Could not set token into kernel\n"));
88 exit(1);
91 printf(_("Success: %s@%s\n"), argv[0], argv[1]);
92 return 0;
95 int net_afs(struct net_context *c, int argc, const char **argv)
97 struct functable func[] = {
99 "key",
100 net_afs_key,
101 NET_TRANSPORT_LOCAL,
102 N_("Import an OpenAFS keyfile"),
103 N_("net afs key <filename>\n"
104 " Import kefile from <filename>.")
107 "impersonate",
108 net_afs_impersonate,
109 NET_TRANSPORT_LOCAL,
110 N_("Get a user token"),
111 N_("net afs impersonate <user> <cell>\n"
112 " Create token for user@cell")
114 {NULL, NULL, 0, NULL, NULL}
116 return net_run_function(c, argc, argv, "net afs", func);