Deleted Added
full compact
smbutil.c (87866) smbutil.c (88282)
1#include <sys/param.h>
2#include <sys/time.h>
3#include <stdio.h>
4#include <string.h>
5#include <unistd.h>
6#include <stdlib.h>
7#include <err.h>
8#include <sysexits.h>
9
10#include <netsmb/smb_lib.h>
11#include <netsmb/smb_conn.h>
12
13#include "common.h"
14
15extern char *__progname;
16
17static void help(void);
18static void help_usage(void);
19static int cmd_crypt(int argc, char *argv[]);
20static int cmd_help(int argc, char *argv[]);
21
22int verbose;
23
24typedef int cmd_fn_t (int argc, char *argv[]);
25typedef void cmd_usage_t (void);
26
27#define CMDFL_NO_KMOD 0x0001
28
29static struct commands {
30 const char * name;
31 cmd_fn_t* fn;
32 cmd_usage_t * usage;
33 int flags;
34} 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},
43 {NULL, NULL}
44};
45
46static struct commands *
47lookupcmd(const char *name)
48{
49 struct commands *cmd;
50
51 for (cmd = commands; cmd->name; cmd++) {
52 if (strcmp(cmd->name, name) == 0)
53 return cmd;
54 }
55 return NULL;
56}
57
58int
59cmd_crypt(int argc, char *argv[])
60{
61 char *cp, *psw;
62
63 if (argc < 2)
64 psw = getpass("Password:");
65 else
66 psw = argv[1];
1#include <sys/param.h>
2#include <sys/time.h>
3#include <stdio.h>
4#include <string.h>
5#include <unistd.h>
6#include <stdlib.h>
7#include <err.h>
8#include <sysexits.h>
9
10#include <netsmb/smb_lib.h>
11#include <netsmb/smb_conn.h>
12
13#include "common.h"
14
15extern char *__progname;
16
17static void help(void);
18static void help_usage(void);
19static int cmd_crypt(int argc, char *argv[]);
20static int cmd_help(int argc, char *argv[]);
21
22int verbose;
23
24typedef int cmd_fn_t (int argc, char *argv[]);
25typedef void cmd_usage_t (void);
26
27#define CMDFL_NO_KMOD 0x0001
28
29static struct commands {
30 const char * name;
31 cmd_fn_t* fn;
32 cmd_usage_t * usage;
33 int flags;
34} 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},
43 {NULL, NULL}
44};
45
46static struct commands *
47lookupcmd(const char *name)
48{
49 struct commands *cmd;
50
51 for (cmd = commands; cmd->name; cmd++) {
52 if (strcmp(cmd->name, name) == 0)
53 return cmd;
54 }
55 return NULL;
56}
57
58int
59cmd_crypt(int argc, char *argv[])
60{
61 char *cp, *psw;
62
63 if (argc < 2)
64 psw = getpass("Password:");
65 else
66 psw = argv[1];
67 cp = malloc(strlen(psw + 4));
67 cp = smb_simplecrypt(NULL, psw);
68 if (cp == NULL)
69 errx(EX_DATAERR, "out of memory");
68 if (cp == NULL)
69 errx(EX_DATAERR, "out of memory");
70 smb_simplecrypt(cp, psw);
71 printf("%s\n", cp);
72 free(cp);
73 exit(0);
74}
75
76int
77cmd_help(int argc, char *argv[])
78{
79 struct commands *cmd;
80 char *cp;
81
82 if (argc < 2)
83 help_usage();
84 cp = argv[1];
85 cmd = lookupcmd(cp);
86 if (cmd == NULL)
87 errx(EX_DATAERR, "unknown command %s", cp);
88 if (cmd->usage == NULL)
89 errx(EX_DATAERR, "no specific help for command %s", cp);
90 cmd->usage();
91 exit(0);
92}
93
94int
95main(int argc, char *argv[])
96{
97 struct commands *cmd;
98 char *cp;
99 int opt;
70 printf("%s\n", cp);
71 free(cp);
72 exit(0);
73}
74
75int
76cmd_help(int argc, char *argv[])
77{
78 struct commands *cmd;
79 char *cp;
80
81 if (argc < 2)
82 help_usage();
83 cp = argv[1];
84 cmd = lookupcmd(cp);
85 if (cmd == NULL)
86 errx(EX_DATAERR, "unknown command %s", cp);
87 if (cmd->usage == NULL)
88 errx(EX_DATAERR, "no specific help for command %s", cp);
89 cmd->usage();
90 exit(0);
91}
92
93int
94main(int argc, char *argv[])
95{
96 struct commands *cmd;
97 char *cp;
98 int opt;
99#ifdef APPLE
100 extern void dropsuid();
100
101
102 dropsuid();
103#endif /* APPLE */
104
101 if (argc < 2)
102 help();
103
104 while ((opt = getopt(argc, argv, "hv")) != EOF) {
105 switch (opt) {
106 case 'h':
107 help();
108 /*NOTREACHED */
109 case 'v':
110 verbose = 1;
111 break;
112 default:
113 warnx("invalid option %c", opt);
114 help();
115 /*NOTREACHED */
116 }
117 }
118 if (optind >= argc)
119 help();
120
121 cp = argv[optind];
122 cmd = lookupcmd(cp);
123 if (cmd == NULL)
124 errx(EX_DATAERR, "unknown command %s", cp);
125
126 if ((cmd->flags & CMDFL_NO_KMOD) == 0 && smb_lib_init() != 0)
127 exit(1);
128
129 argc -= optind;
130 argv += optind;
131 optind = optreset = 1;
132 return cmd->fn(argc, argv);
133}
134
135static void
136help(void) {
137 printf("\n");
138 printf("usage: %s [-hv] command [args]\n", __progname);
139 printf("where commands are:\n"
140 " crypt [password] slightly encrypt password\n"
141 " help command display help on \"command\"\n"
142 " lc display active connections\n"
143 " login //user@host[/share] login to the specified host\n"
144 " logout //user@host[/share] logout from the specified host\n"
145 " print //user@host/share file print file to the specified remote printer\n"
146 " view //user@host list resources on the specified host\n"
147 "\n");
148 exit(1);
149}
150
151static void
152help_usage(void) {
153 printf("usage: smbutil help command\n");
154 exit(1);
155}
105 if (argc < 2)
106 help();
107
108 while ((opt = getopt(argc, argv, "hv")) != EOF) {
109 switch (opt) {
110 case 'h':
111 help();
112 /*NOTREACHED */
113 case 'v':
114 verbose = 1;
115 break;
116 default:
117 warnx("invalid option %c", opt);
118 help();
119 /*NOTREACHED */
120 }
121 }
122 if (optind >= argc)
123 help();
124
125 cp = argv[optind];
126 cmd = lookupcmd(cp);
127 if (cmd == NULL)
128 errx(EX_DATAERR, "unknown command %s", cp);
129
130 if ((cmd->flags & CMDFL_NO_KMOD) == 0 && smb_lib_init() != 0)
131 exit(1);
132
133 argc -= optind;
134 argv += optind;
135 optind = optreset = 1;
136 return cmd->fn(argc, argv);
137}
138
139static void
140help(void) {
141 printf("\n");
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"
151 "\n");
152 exit(1);
153}
154
155static void
156help_usage(void) {
157 printf("usage: smbutil help command\n");
158 exit(1);
159}