summaryrefslogtreecommitdiff
path: root/source3/utils/net_afs.c
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2008-05-14 09:01:53 +0200
committerKai Blin <kai@samba.org>2008-05-20 14:27:56 +0200
commit00f6ad7b5a7ea684b329c2ce68ada77036c94b08 (patch)
tree38786f9c4eb324124dcbdcc7dea6930169389f94 /source3/utils/net_afs.c
parentb5965290417200a52da1f4c87f745a7044e84453 (diff)
downloadsamba-00f6ad7b5a7ea684b329c2ce68ada77036c94b08.tar.gz
samba-00f6ad7b5a7ea684b329c2ce68ada77036c94b08.tar.bz2
samba-00f6ad7b5a7ea684b329c2ce68ada77036c94b08.zip
net: Split out "net afs"
(This used to be commit 3f10527f79dddff703d31588cad3e9f37176565b)
Diffstat (limited to 'source3/utils/net_afs.c')
-rw-r--r--source3/utils/net_afs.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/source3/utils/net_afs.c b/source3/utils/net_afs.c
new file mode 100644
index 0000000000..f3f2976eb0
--- /dev/null
+++ b/source3/utils/net_afs.c
@@ -0,0 +1,101 @@
+/*
+ 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"
+
+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("usage: 'net afs key <keyfile> cell'\n");
+ 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");
+ return -1;
+ }
+
+ if (!secrets_store_afs_keyfile(argv[1], &keyfile)) {
+ d_fprintf(stderr, "Could not write keyfile to secrets.tdb\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+int net_afs_impersonate(struct net_context *c, int argc,
+ const char **argv)
+{
+ char *token;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: net afs impersonate <user> <cell>\n");
+ 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},
+ {"impersonate", net_afs_impersonate},
+ {"help", net_afs_usage},
+ {NULL, NULL}
+ };
+ return net_run_function(c, argc, argv, func, net_afs_usage);
+}
+