ldb: change version to 1.1.17
[Samba.git] / source3 / utils / net_afs.c
blob3c7f28242ce73060bd36b4f97c72357c98706ebc
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 "utils/net_afs.h"
23 #include "secrets.h"
24 #include "system/filesys.h"
26 int net_afs_usage(struct net_context *c, int argc, const char **argv)
28 d_printf(_(" net afs key filename\n"
29 "\tImports a OpenAFS KeyFile into our secrets.tdb\n\n"));
30 d_printf(_(" net afs impersonate <user> <cell>\n"
31 "\tCreates a token for user@cell\n\n"));
32 return -1;
35 int net_afs_key(struct net_context *c, int argc, const char **argv)
37 int fd;
38 struct afs_keyfile keyfile;
40 if (argc != 2) {
41 d_printf("%s net afs key <keyfile> cell\n", _("Usage:"));
42 return -1;
45 if (!secrets_init()) {
46 d_fprintf(stderr, _("Could not open secrets.tdb\n"));
47 return -1;
50 if ((fd = open(argv[0], O_RDONLY, 0)) < 0) {
51 d_fprintf(stderr, _("Could not open %s\n"), argv[0]);
52 return -1;
55 if (read(fd, &keyfile, sizeof(keyfile)) != sizeof(keyfile)) {
56 d_fprintf(stderr, _("Could not read keyfile\n"));
57 close(fd);
58 return -1;
60 close(fd);
62 if (!secrets_store_afs_keyfile(argv[1], &keyfile)) {
63 d_fprintf(stderr, _("Could not write keyfile to secrets.tdb\n"));
64 return -1;
67 return 0;
70 int net_afs_impersonate(struct net_context *c, int argc,
71 const char **argv)
73 char *token;
75 if (argc != 2) {
76 d_fprintf(stderr, "%s net afs impersonate <user> <cell>\n",
77 _("Usage:"));
78 exit(1);
81 token = afs_createtoken_str(argv[0], argv[1]);
83 if (token == NULL) {
84 fprintf(stderr, _("Could not create token\n"));
85 exit(1);
88 if (!afs_settoken_str(token)) {
89 fprintf(stderr, _("Could not set token into kernel\n"));
90 exit(1);
93 printf(_("Success: %s@%s\n"), argv[0], argv[1]);
94 return 0;
97 int net_afs(struct net_context *c, int argc, const char **argv)
99 struct functable func[] = {
101 "key",
102 net_afs_key,
103 NET_TRANSPORT_LOCAL,
104 N_("Import an OpenAFS keyfile"),
105 N_("net afs key <filename>\n"
106 " Import kefile from <filename>.")
109 "impersonate",
110 net_afs_impersonate,
111 NET_TRANSPORT_LOCAL,
112 N_("Get a user token"),
113 N_("net afs impersonate <user> <cell>\n"
114 " Create token for user@cell")
116 {NULL, NULL, 0, NULL, NULL}
118 return net_run_function(c, argc, argv, "net afs", func);