10 #include <netsmb/smb_lib.h>
11 #include <netsmb/smb_conn.h>
15 extern char *__progname;
17 static void help(void);
18 static void help_usage(void);
19 static int cmd_crypt(int argc, char *argv[]);
20 static int cmd_help(int argc, char *argv[]);
24 typedef int cmd_fn_t (int argc, char *argv[]);
25 typedef void cmd_usage_t (void);
27 #define CMDFL_NO_KMOD 0x0001
29 static struct commands {
35 {"crypt", cmd_crypt, NULL, CMDFL_NO_KMOD},
36 {"help", cmd_help, help_usage, CMDFL_NO_KMOD},
37 {"lc", cmd_dumptree, NULL},
38 {"login", cmd_login, login_usage},
39 {"logout", cmd_logout, logout_usage},
40 {"lookup", cmd_lookup, lookup_usage, CMDFL_NO_KMOD},
41 {"print", cmd_print, print_usage},
42 {"view", cmd_view, view_usage},
46 static struct commands *
47 lookupcmd(const char *name)
51 for (cmd = commands; cmd->name; cmd++) {
52 if (strcmp(cmd->name, name) == 0)
59 cmd_crypt(int argc, char *argv[])
64 psw = getpass("Password:");
67 cp = smb_simplecrypt(NULL, psw);
69 errx(EX_DATAERR, "out of memory");
76 cmd_help(int argc, char *argv[])
86 errx(EX_DATAERR, "unknown command %s", cp);
87 if (cmd->usage == NULL)
88 errx(EX_DATAERR, "no specific help for command %s", cp);
94 main(int argc, char *argv[])
100 extern void dropsuid();
108 while ((opt = getopt(argc, argv, "hv")) != EOF) {
117 warnx("invalid option %c", opt);
128 errx(EX_DATAERR, "unknown command %s", cp);
130 if ((cmd->flags & CMDFL_NO_KMOD) == 0 && smb_lib_init() != 0)
135 optind = optreset = 1;
136 return cmd->fn(argc, argv);
142 printf("usage: %s [-hv] command [args]\n", __progname);
143 printf("where commands are:\n"
144 " crypt [password] slightly encrypt password\n"
145 " help command display help on \"command\"\n"
146 " lc display active connections\n"
147 " login //user@host[/share] login to the specified host\n"
148 " logout //user@host[/share] logout from the specified host\n"
149 " print //user@host/share file print file to the specified remote printer\n"
150 " view //user@host list resources on the specified host\n"
157 printf("usage: smbutil help command\n");