2 * Copyright (c) 2000, Boris Popov
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
35 * Use is subject to license terms.
37 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
40 #include <sys/param.h>
51 #include <netsmb/smb_lib.h>
59 static void help(void) __NORETURN
;
61 typedef int cmd_fn_t (int argc
, char *argv
[]);
62 typedef void cmd_usage_t (void);
64 #define CMDFL_NO_KMOD 0x0001
66 static struct commands
{
72 {"crypt", cmd_crypt
, NULL
, CMDFL_NO_KMOD
},
73 {"help", cmd_help
, help_usage
, CMDFL_NO_KMOD
},
74 {"info", cmd_info
, info_usage
, 0},
75 {"login", cmd_login
, login_usage
, 0},
76 {"logout", cmd_logout
, logout_usage
, 0},
77 {"logoutall", cmd_logoutall
, logoutall_usage
, 0},
78 {"lookup", cmd_lookup
, lookup_usage
, CMDFL_NO_KMOD
},
79 {"print", cmd_print
, print_usage
, 0},
80 {"status", cmd_status
, status_usage
, CMDFL_NO_KMOD
},
81 {"view", cmd_view
, view_usage
, 0},
85 static struct commands
*
86 lookupcmd(const char *name
)
90 for (cmd
= commands
; cmd
->name
; cmd
++) {
91 if (strcmp(cmd
->name
, name
) == 0)
98 cmd_crypt(int argc
, char *argv
[])
103 psw
= getpassphrase(gettext("Password:"));
106 /* XXX Better to embed malloc/free in smb_simplecrypt? */
107 cp
= malloc(4 + 2 * strlen(psw
));
109 errx(EX_DATAERR
, gettext("out of memory"));
110 smb_simplecrypt(cp
, psw
);
117 cmd_help(int argc
, char *argv
[])
119 struct commands
*cmd
;
127 errx(EX_DATAERR
, gettext("unknown command %s"), cp
);
128 if (cmd
->usage
== NULL
)
130 gettext("no specific help for command %s"), cp
);
136 main(int argc
, char *argv
[])
138 struct commands
*cmd
;
142 (void) setlocale(LC_ALL
, "");
143 (void) textdomain(TEXT_DOMAIN
);
146 dropsuid(); /* see libsmbfs */
152 while ((opt
= getopt(argc
, argv
, "dhv")) != EOF
) {
174 errx(EX_DATAERR
, gettext("unknown command %s"), cp
);
176 if ((cmd
->flags
& CMDFL_NO_KMOD
) == 0 && smb_lib_init() != 0)
182 err
= cmd
->fn(argc
, argv
);
183 return ((err
) ? 1 : 0);
189 printf(gettext("usage: %s [-hv] subcommand [args]\n"), __progname
);
190 printf(gettext("where subcommands are:\n"
191 " crypt slightly obscure password\n"
192 " help display help on specified subcommand\n"
193 /* " lc display active connections\n" */
194 " info display server type and version\n"
195 " login login to specified host\n"
196 " logout logout from specified host\n"
197 " logoutall logout all users (requires privilege)\n"
198 " lookup resolve NetBIOS name to IP address\n"
199 " print print file to the specified remote printer\n"
200 " status resolve IP address or DNS name to NetBIOS names\n"
201 " view list resources on specified host\n"
208 printf(gettext("usage: smbutil help command\n"));