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