Print this page
3328 smbutil view does't work with Win2008 and later
requires 1575 untangle libmlrpc ...
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/fs.d/smbclnt/smbutil/smbutil.c
+++ new/usr/src/cmd/fs.d/smbclnt/smbutil/smbutil.c
1 1 /*
2 2 * Copyright (c) 2000, Boris Popov
3 3 * All rights reserved.
4 4 *
5 5 * Redistribution and use in source and binary forms, with or without
6 6 * modification, are permitted provided that the following conditions
7 7 * are met:
8 8 * 1. Redistributions of source code must retain the above copyright
9 9 * notice, this list of conditions and the following disclaimer.
10 10 * 2. Redistributions in binary form must reproduce the above copyright
11 11 * notice, this list of conditions and the following disclaimer in the
12 12 * documentation and/or other materials provided with the distribution.
13 13 * 3. All advertising materials mentioning features or use of this software
14 14 * must display the following acknowledgement:
15 15 * This product includes software developed by Boris Popov.
16 16 * 4. Neither the name of the author nor the names of any co-contributors
17 17 * may be used to endorse or promote products derived from this software
18 18 * without specific prior written permission.
19 19 *
20 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
26 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 30 * SUCH DAMAGE.
31 31 */
32 32
33 33 /*
34 34 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
35 35 * Use is subject to license terms.
36 + *
37 + * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
36 38 */
37 39
38 40 #include <sys/param.h>
39 41 #include <sys/time.h>
40 42 #include <stdio.h>
41 43 #include <string.h>
42 44 #include <unistd.h>
43 45 #include <stdlib.h>
44 46 #include <err.h>
45 47 #include <sysexits.h>
46 48 #include <locale.h>
47 49 #include <libintl.h>
48 50
49 51 #include <netsmb/smb_lib.h>
50 52
51 53 #include "common.h"
52 54
53 55 #ifndef EX_DATAERR
54 56 #define EX_DATAERR 1
55 57 #endif
56 58
57 59 static void help(void);
58 60
59 61
60 62 typedef int cmd_fn_t (int argc, char *argv[]);
61 63 typedef void cmd_usage_t (void);
62 64
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
63 65 #define CMDFL_NO_KMOD 0x0001
64 66
65 67 static struct commands {
66 68 const char *name;
67 69 cmd_fn_t *fn;
68 70 cmd_usage_t *usage;
69 71 int flags;
70 72 } commands[] = {
71 73 {"crypt", cmd_crypt, NULL, CMDFL_NO_KMOD},
72 74 {"help", cmd_help, help_usage, CMDFL_NO_KMOD},
75 + {"info", cmd_info, info_usage, 0},
73 76 {"login", cmd_login, login_usage, 0},
74 77 {"logout", cmd_logout, logout_usage, 0},
75 78 {"logoutall", cmd_logoutall, logoutall_usage, 0},
76 79 {"lookup", cmd_lookup, lookup_usage, CMDFL_NO_KMOD},
77 80 {"print", cmd_print, print_usage, 0},
78 81 {"status", cmd_status, status_usage, CMDFL_NO_KMOD},
79 82 {"view", cmd_view, view_usage, 0},
80 83 {NULL, NULL, NULL, 0}
81 84 };
82 85
83 86 static struct commands *
84 87 lookupcmd(const char *name)
85 88 {
86 89 struct commands *cmd;
87 90
88 91 for (cmd = commands; cmd->name; cmd++) {
89 92 if (strcmp(cmd->name, name) == 0)
90 93 return (cmd);
91 94 }
92 95 return (NULL);
93 96 }
94 97
95 98 int
96 99 cmd_crypt(int argc, char *argv[])
97 100 {
98 101 char *cp, *psw;
99 102
100 103 if (argc < 2)
101 104 psw = getpassphrase(gettext("Password:"));
102 105 else
103 106 psw = argv[1];
104 107 /* XXX Better to embed malloc/free in smb_simplecrypt? */
105 108 cp = malloc(4 + 2 * strlen(psw));
106 109 if (cp == NULL)
107 110 errx(EX_DATAERR, gettext("out of memory"));
108 111 smb_simplecrypt(cp, psw);
109 112 printf("%s\n", cp);
110 113 free(cp);
111 114 return (0);
112 115 }
113 116
114 117 int
115 118 cmd_help(int argc, char *argv[])
116 119 {
117 120 struct commands *cmd;
118 121 char *cp;
119 122
120 123 if (argc < 2)
121 124 help_usage();
122 125 cp = argv[1];
123 126 cmd = lookupcmd(cp);
124 127 if (cmd == NULL)
125 128 errx(EX_DATAERR, gettext("unknown command %s"), cp);
126 129 if (cmd->usage == NULL)
127 130 errx(EX_DATAERR,
128 131 gettext("no specific help for command %s"), cp);
129 132 cmd->usage();
130 133 return (0);
131 134 }
132 135
133 136 int
134 137 main(int argc, char *argv[])
135 138 {
136 139 struct commands *cmd;
137 140 char *cp;
138 141 int err, opt;
139 142
140 143 (void) setlocale(LC_ALL, "");
141 144 (void) textdomain(TEXT_DOMAIN);
142 145
143 146 #ifdef APPLE
144 147 dropsuid(); /* see libsmbfs */
145 148 #endif
146 149
147 150 if (argc < 2)
148 151 help();
149 152
150 153 while ((opt = getopt(argc, argv, "dhv")) != EOF) {
151 154 switch (opt) {
152 155 case 'd':
153 156 smb_debug++;
154 157 break;
155 158 case 'h':
156 159 help();
157 160 /* NOTREACHED */
158 161 case 'v':
159 162 smb_verbose++;
160 163 break;
161 164 default:
162 165 help();
163 166 /* NOTREACHED */
164 167 }
165 168 }
166 169 if (optind >= argc)
167 170 help();
168 171
169 172 cp = argv[optind];
170 173 cmd = lookupcmd(cp);
171 174 if (cmd == NULL)
172 175 errx(EX_DATAERR, gettext("unknown command %s"), cp);
173 176
174 177 if ((cmd->flags & CMDFL_NO_KMOD) == 0 && smb_lib_init() != 0)
175 178 exit(1);
176 179
177 180 argc -= optind;
178 181 argv += optind;
179 182 optind = 1;
180 183 err = cmd->fn(argc, argv);
181 184 return ((err) ? 1 : 0);
↓ open down ↓ |
99 lines elided |
↑ open up ↑ |
182 185 }
183 186
184 187 static void
185 188 help(void) {
186 189 printf("\n");
187 190 printf(gettext("usage: %s [-hv] subcommand [args]\n"), __progname);
188 191 printf(gettext("where subcommands are:\n"
189 192 " crypt slightly obscure password\n"
190 193 " help display help on specified subcommand\n"
191 194 /* " lc display active connections\n" */
195 + " info display server type and version\n"
192 196 " login login to specified host\n"
193 197 " logout logout from specified host\n"
194 198 " logoutall logout all users (requires privilege)\n"
195 199 " lookup resolve NetBIOS name to IP address\n"
196 200 " print print file to the specified remote printer\n"
197 201 " status resolve IP address or DNS name to NetBIOS names\n"
198 202 " view list resources on specified host\n"
199 203 "\n"));
200 204 exit(1);
201 205 }
202 206
203 207 void
204 208 help_usage(void) {
205 209 printf(gettext("usage: smbutil help command\n"));
206 210 exit(1);
207 211 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX