s3:net: remove unused net_idmap_help
[samba.git] / source3 / utils / net_afs.c
1 /*
2    Samba Unix/Linux SMB client library
3    net afs commands
4    Copyright (C) 2003  Volker Lendecke  (vl@samba.org)
5
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.
10
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.
15
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/>.
18 */
19
20 #include "includes.h"
21 #include "utils/net.h"
22
23 int net_afs_usage(struct net_context *c, int argc, const char **argv)
24 {
25         d_printf(_("  net afs key filename\n"
26                  "\tImports a OpenAFS KeyFile into our secrets.tdb\n\n"));
27         d_printf(_("  net afs impersonate <user> <cell>\n"
28                  "\tCreates a token for user@cell\n\n"));
29         return -1;
30 }
31
32 int net_afs_key(struct net_context *c, int argc, const char **argv)
33 {
34         int fd;
35         struct afs_keyfile keyfile;
36
37         if (argc != 2) {
38                 d_printf(_("Usage:")," net afs key <keyfile> cell\n");
39                 return -1;
40         }
41
42         if (!secrets_init()) {
43                 d_fprintf(stderr, _("Could not open secrets.tdb\n"));
44                 return -1;
45         }
46
47         if ((fd = open(argv[0], O_RDONLY, 0)) < 0) {
48                 d_fprintf(stderr, _("Could not open %s\n"), argv[0]);
49                 return -1;
50         }
51
52         if (read(fd, &keyfile, sizeof(keyfile)) != sizeof(keyfile)) {
53                 d_fprintf(stderr, _("Could not read keyfile\n"));
54                 close(fd);
55                 return -1;
56         }
57         close(fd);
58
59         if (!secrets_store_afs_keyfile(argv[1], &keyfile)) {
60                 d_fprintf(stderr, _("Could not write keyfile to secrets.tdb\n"));
61                 return -1;
62         }
63
64         return 0;
65 }
66
67 int net_afs_impersonate(struct net_context *c, int argc,
68                                const char **argv)
69 {
70         char *token;
71
72         if (argc != 2) {
73                 fprintf(stderr, _("Usage:")," net afs impersonate <user> <cell>\n");
74                 exit(1);
75         }
76
77         token = afs_createtoken_str(argv[0], argv[1]);
78
79         if (token == NULL) {
80                 fprintf(stderr, _("Could not create token\n"));
81                 exit(1);
82         }
83
84         if (!afs_settoken_str(token)) {
85                 fprintf(stderr, _("Could not set token into kernel\n"));
86                 exit(1);
87         }
88
89         printf(_("Success: %s@%s\n"), argv[0], argv[1]);
90         return 0;
91 }
92
93 int net_afs(struct net_context *c, int argc, const char **argv)
94 {
95         struct functable func[] = {
96                 {
97                         "key",
98                         net_afs_key,
99                         NET_TRANSPORT_LOCAL,
100                         N_("Import an OpenAFS keyfile"),
101                         N_("net afs key <filename>\n"
102                            "    Import kefile from <filename>.")
103                 },
104                 {
105                         "impersonate",
106                         net_afs_impersonate,
107                         NET_TRANSPORT_LOCAL,
108                         N_("Get a user token"),
109                         N_("net afs impersonate <user> <cell>\n"
110                            "    Create token for user@cell")
111                 },
112                 {NULL, NULL, 0, NULL, NULL}
113         };
114         return net_run_function(c, argc, argv, "net afs", func);
115 }
116