xref: /titanic_44/usr/src/cmd/smbsrv/smbadm/smbadm.c (revision 96a62ada8aa6cb19b04270da282e7e21ba74b808)
1da6c28aaSamw /*
2da6c28aaSamw  * CDDL HEADER START
3da6c28aaSamw  *
4da6c28aaSamw  * The contents of this file are subject to the terms of the
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * You may not use this file except in compliance with the License.
7da6c28aaSamw  *
8da6c28aaSamw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw  * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw  * See the License for the specific language governing permissions
11da6c28aaSamw  * and limitations under the License.
12da6c28aaSamw  *
13da6c28aaSamw  * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw  * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw  * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw  * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw  *
19da6c28aaSamw  * CDDL HEADER END
20da6c28aaSamw  */
21da6c28aaSamw /*
22*96a62adaSjoyce mcintosh  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23da6c28aaSamw  * Use is subject to license terms.
24da6c28aaSamw  */
25da6c28aaSamw 
26da6c28aaSamw /*
27da6c28aaSamw  * This module contains smbadm CLI which offers smb configuration
28da6c28aaSamw  * functionalities.
29da6c28aaSamw  */
308d7e4166Sjose borrego #include <errno.h>
318d7e4166Sjose borrego #include <err.h>
328d7e4166Sjose borrego #include <ctype.h>
33da6c28aaSamw #include <stdlib.h>
34*96a62adaSjoyce mcintosh #include <unistd.h>
35da6c28aaSamw #include <stdio.h>
36da6c28aaSamw #include <syslog.h>
37da6c28aaSamw #include <strings.h>
38da6c28aaSamw #include <limits.h>
39da6c28aaSamw #include <getopt.h>
40da6c28aaSamw #include <libintl.h>
41da6c28aaSamw #include <zone.h>
42*96a62adaSjoyce mcintosh #include <pwd.h>
43da6c28aaSamw #include <grp.h>
44da6c28aaSamw #include <libgen.h>
45c8ec8eeaSjose borrego #include <netinet/in.h>
46*96a62adaSjoyce mcintosh #include <auth_attr.h>
47*96a62adaSjoyce mcintosh #include <locale.h>
48da6c28aaSamw #include <smbsrv/libsmb.h>
49da6c28aaSamw 
50*96a62adaSjoyce mcintosh #if !defined(TEXT_DOMAIN)
51*96a62adaSjoyce mcintosh #define	TEXT_DOMAIN "SYS_TEST"
52*96a62adaSjoyce mcintosh #endif
53*96a62adaSjoyce mcintosh 
54da6c28aaSamw typedef enum {
55da6c28aaSamw 	HELP_ADD_MEMBER,
56da6c28aaSamw 	HELP_CREATE,
57da6c28aaSamw 	HELP_DELETE,
58da6c28aaSamw 	HELP_DEL_MEMBER,
59da6c28aaSamw 	HELP_GET,
60da6c28aaSamw 	HELP_JOIN,
61da6c28aaSamw 	HELP_LIST,
62da6c28aaSamw 	HELP_RENAME,
63da6c28aaSamw 	HELP_SET,
64da6c28aaSamw 	HELP_SHOW,
653db3f65cSamw 	HELP_USER_DISABLE,
663db3f65cSamw 	HELP_USER_ENABLE
67da6c28aaSamw } smbadm_help_t;
68da6c28aaSamw 
69*96a62adaSjoyce mcintosh #define	SMBADM_CMDF_NONE	0x00
703db3f65cSamw #define	SMBADM_CMDF_USER	0x01
713db3f65cSamw #define	SMBADM_CMDF_GROUP	0x02
723db3f65cSamw #define	SMBADM_CMDF_TYPEMASK	0x0F
73faa1795aSjb150015 
74c8ec8eeaSjose borrego #define	SMBADM_ANSBUFSIZ	64
75c8ec8eeaSjose borrego 
76da6c28aaSamw typedef struct smbadm_cmdinfo {
77da6c28aaSamw 	char *name;
78da6c28aaSamw 	int (*func)(int, char **);
79da6c28aaSamw 	smbadm_help_t usage;
80faa1795aSjb150015 	uint32_t flags;
81*96a62adaSjoyce mcintosh 	char *auth;
82da6c28aaSamw } smbadm_cmdinfo_t;
83da6c28aaSamw 
84da6c28aaSamw smbadm_cmdinfo_t *curcmd;
85da6c28aaSamw static char *progname;
86da6c28aaSamw 
87*96a62adaSjoyce mcintosh #define	SMBADM_ACTION_AUTH	"solaris.smf.manage.smb"
88*96a62adaSjoyce mcintosh #define	SMBADM_VALUE_AUTH	"solaris.smf.value.smb"
89*96a62adaSjoyce mcintosh #define	SMBADM_BASIC_AUTH	"solaris.network.hosts.read"
90*96a62adaSjoyce mcintosh 
91*96a62adaSjoyce mcintosh static boolean_t smbadm_checkauth(const char *);
92*96a62adaSjoyce mcintosh 
938d7e4166Sjose borrego static void smbadm_usage(boolean_t);
948d7e4166Sjose borrego static int smbadm_join_workgroup(const char *);
958d7e4166Sjose borrego static int smbadm_join_domain(const char *, const char *);
968d7e4166Sjose borrego static void smbadm_extract_domain(char *, char **, char **);
978d7e4166Sjose borrego 
98da6c28aaSamw static int smbadm_join(int, char **);
99da6c28aaSamw static int smbadm_list(int, char **);
100da6c28aaSamw static int smbadm_group_create(int, char **);
101da6c28aaSamw static int smbadm_group_delete(int, char **);
102da6c28aaSamw static int smbadm_group_rename(int, char **);
103da6c28aaSamw static int smbadm_group_show(int, char **);
104fe1c642dSBill Krier static void smbadm_group_show_name(const char *, const char *);
105da6c28aaSamw static int smbadm_group_getprop(int, char **);
106da6c28aaSamw static int smbadm_group_setprop(int, char **);
107da6c28aaSamw static int smbadm_group_addmember(int, char **);
108da6c28aaSamw static int smbadm_group_delmember(int, char **);
109da6c28aaSamw static int smbadm_user_disable(int, char **);
110da6c28aaSamw static int smbadm_user_enable(int, char **);
111da6c28aaSamw 
112da6c28aaSamw static smbadm_cmdinfo_t smbadm_cmdtable[] =
113da6c28aaSamw {
114faa1795aSjb150015 	{ "add-member",		smbadm_group_addmember,	HELP_ADD_MEMBER,
115*96a62adaSjoyce mcintosh 		SMBADM_CMDF_GROUP,	SMBADM_ACTION_AUTH },
116faa1795aSjb150015 	{ "create",		smbadm_group_create,	HELP_CREATE,
117*96a62adaSjoyce mcintosh 		SMBADM_CMDF_GROUP,	SMBADM_ACTION_AUTH },
118faa1795aSjb150015 	{ "delete",		smbadm_group_delete,	HELP_DELETE,
119*96a62adaSjoyce mcintosh 		SMBADM_CMDF_GROUP,	SMBADM_ACTION_AUTH },
1203db3f65cSamw 	{ "disable-user",	smbadm_user_disable,	HELP_USER_DISABLE,
121*96a62adaSjoyce mcintosh 		SMBADM_CMDF_USER,	SMBADM_ACTION_AUTH },
1223db3f65cSamw 	{ "enable-user",	smbadm_user_enable,	HELP_USER_ENABLE,
123*96a62adaSjoyce mcintosh 		SMBADM_CMDF_USER,	SMBADM_ACTION_AUTH },
124faa1795aSjb150015 	{ "get",		smbadm_group_getprop,	HELP_GET,
125*96a62adaSjoyce mcintosh 		SMBADM_CMDF_GROUP,	SMBADM_ACTION_AUTH },
126*96a62adaSjoyce mcintosh 	{ "join",		smbadm_join,		HELP_JOIN,
127*96a62adaSjoyce mcintosh 		SMBADM_CMDF_NONE,	SMBADM_VALUE_AUTH },
128*96a62adaSjoyce mcintosh 	{ "list",		smbadm_list,		HELP_LIST,
129*96a62adaSjoyce mcintosh 		SMBADM_CMDF_NONE,	SMBADM_BASIC_AUTH },
130faa1795aSjb150015 	{ "remove-member",	smbadm_group_delmember,	HELP_DEL_MEMBER,
131*96a62adaSjoyce mcintosh 		SMBADM_CMDF_GROUP,	SMBADM_ACTION_AUTH },
132faa1795aSjb150015 	{ "rename",		smbadm_group_rename,	HELP_RENAME,
133*96a62adaSjoyce mcintosh 		SMBADM_CMDF_GROUP,	SMBADM_ACTION_AUTH },
134faa1795aSjb150015 	{ "set",		smbadm_group_setprop,	HELP_SET,
135*96a62adaSjoyce mcintosh 		SMBADM_CMDF_GROUP,	SMBADM_ACTION_AUTH },
136faa1795aSjb150015 	{ "show",		smbadm_group_show,	HELP_SHOW,
137*96a62adaSjoyce mcintosh 		SMBADM_CMDF_GROUP,	SMBADM_ACTION_AUTH },
138da6c28aaSamw };
139da6c28aaSamw 
140da6c28aaSamw #define	SMBADM_NCMD	(sizeof (smbadm_cmdtable) / sizeof (smbadm_cmdtable[0]))
141da6c28aaSamw 
142da6c28aaSamw typedef struct smbadm_prop {
143da6c28aaSamw 	char *p_name;
144da6c28aaSamw 	char *p_value;
145da6c28aaSamw } smbadm_prop_t;
146da6c28aaSamw 
147da6c28aaSamw typedef struct smbadm_prop_handle {
148da6c28aaSamw 	char *p_name;
149da6c28aaSamw 	char *p_dispvalue;
150da6c28aaSamw 	int (*p_setfn)(char *, smbadm_prop_t *);
151da6c28aaSamw 	int (*p_getfn)(char *, smbadm_prop_t *);
152da6c28aaSamw 	boolean_t (*p_chkfn)(smbadm_prop_t *);
153da6c28aaSamw } smbadm_prop_handle_t;
154da6c28aaSamw 
155da6c28aaSamw static boolean_t smbadm_prop_validate(smbadm_prop_t *prop, boolean_t chkval);
156da6c28aaSamw static int smbadm_prop_parse(char *arg, smbadm_prop_t *prop);
157da6c28aaSamw static smbadm_prop_handle_t *smbadm_prop_gethandle(char *pname);
158da6c28aaSamw 
159da6c28aaSamw static boolean_t smbadm_chkprop_priv(smbadm_prop_t *prop);
160da6c28aaSamw static int smbadm_setprop_tkowner(char *gname, smbadm_prop_t *prop);
161da6c28aaSamw static int smbadm_getprop_tkowner(char *gname, smbadm_prop_t *prop);
162da6c28aaSamw static int smbadm_setprop_backup(char *gname, smbadm_prop_t *prop);
163da6c28aaSamw static int smbadm_getprop_backup(char *gname, smbadm_prop_t *prop);
164da6c28aaSamw static int smbadm_setprop_restore(char *gname, smbadm_prop_t *prop);
165da6c28aaSamw static int smbadm_getprop_restore(char *gname, smbadm_prop_t *prop);
166da6c28aaSamw static int smbadm_setprop_desc(char *gname, smbadm_prop_t *prop);
167da6c28aaSamw static int smbadm_getprop_desc(char *gname, smbadm_prop_t *prop);
168da6c28aaSamw 
169da6c28aaSamw static smbadm_prop_handle_t smbadm_ptable[] = {
170da6c28aaSamw 	{"backup",	"on | off", 	smbadm_setprop_backup,
171da6c28aaSamw 	smbadm_getprop_backup,	smbadm_chkprop_priv 	},
172da6c28aaSamw 	{"restore",	"on | off",	smbadm_setprop_restore,
173da6c28aaSamw 	smbadm_getprop_restore,	smbadm_chkprop_priv	},
174da6c28aaSamw 	{"take-ownership", "on | off",	smbadm_setprop_tkowner,
175da6c28aaSamw 	smbadm_getprop_tkowner,	smbadm_chkprop_priv	},
176da6c28aaSamw 	{"description",	"<string>",	smbadm_setprop_desc,
177da6c28aaSamw 	smbadm_getprop_desc,	NULL			},
178da6c28aaSamw };
179da6c28aaSamw 
1803db3f65cSamw static int smbadm_init(void);
1813db3f65cSamw static void smbadm_fini(void);
182da6c28aaSamw static const char *smbadm_pwd_strerror(int error);
183da6c28aaSamw 
184da6c28aaSamw /*
185da6c28aaSamw  * Number of supported properties
186da6c28aaSamw  */
187da6c28aaSamw #define	SMBADM_NPROP	(sizeof (smbadm_ptable) / sizeof (smbadm_ptable[0]))
188da6c28aaSamw 
189da6c28aaSamw static void
190da6c28aaSamw smbadm_cmdusage(FILE *fp, smbadm_cmdinfo_t *cmd)
191da6c28aaSamw {
192da6c28aaSamw 	switch (cmd->usage) {
193da6c28aaSamw 	case HELP_ADD_MEMBER:
194da6c28aaSamw 		(void) fprintf(fp,
195da6c28aaSamw 		    gettext("\t%s -m member [[-m member] ...] group\n"),
196da6c28aaSamw 		    cmd->name);
197da6c28aaSamw 		return;
198da6c28aaSamw 
199da6c28aaSamw 	case HELP_CREATE:
200da6c28aaSamw 		(void) fprintf(fp, gettext("\t%s [-d description] group\n"),
201da6c28aaSamw 		    cmd->name);
202da6c28aaSamw 		return;
203da6c28aaSamw 
204da6c28aaSamw 	case HELP_DELETE:
205da6c28aaSamw 		(void) fprintf(fp, gettext("\t%s group\n"), cmd->name);
206da6c28aaSamw 		return;
207da6c28aaSamw 
2083db3f65cSamw 	case HELP_USER_DISABLE:
2093db3f65cSamw 	case HELP_USER_ENABLE:
210da6c28aaSamw 		(void) fprintf(fp, gettext("\t%s user\n"), cmd->name);
211da6c28aaSamw 		return;
212da6c28aaSamw 
213da6c28aaSamw 	case HELP_GET:
214da6c28aaSamw 		(void) fprintf(fp, gettext("\t%s [[-p property] ...] group\n"),
215da6c28aaSamw 		    cmd->name);
216da6c28aaSamw 		return;
217da6c28aaSamw 
218da6c28aaSamw 	case HELP_JOIN:
219da6c28aaSamw 		(void) fprintf(fp, gettext("\t%s -u username domain\n"
220da6c28aaSamw 		    "\t%s -w workgroup\n"), cmd->name, cmd->name);
221da6c28aaSamw 		return;
222da6c28aaSamw 
223da6c28aaSamw 	case HELP_LIST:
224da6c28aaSamw 		(void) fprintf(fp, gettext("\t%s\n"), cmd->name);
22589dc44ceSjose borrego 		(void) fprintf(fp,
22689dc44ceSjose borrego 		    gettext("\t\t[*] primary domain\n"));
22789dc44ceSjose borrego 		(void) fprintf(fp, gettext("\t\t[.] local domain\n"));
22889dc44ceSjose borrego 		(void) fprintf(fp, gettext("\t\t[-] other domains\n"));
22989dc44ceSjose borrego 		(void) fprintf(fp,
23089dc44ceSjose borrego 		    gettext("\t\t[+] selected domain controller\n"));
231da6c28aaSamw 		return;
232da6c28aaSamw 
233da6c28aaSamw 	case HELP_DEL_MEMBER:
234da6c28aaSamw 		(void) fprintf(fp,
235da6c28aaSamw 		    gettext("\t%s -m member [[-m member] ...] group\n"),
236da6c28aaSamw 		    cmd->name);
237da6c28aaSamw 		return;
238da6c28aaSamw 
239da6c28aaSamw 	case HELP_RENAME:
240da6c28aaSamw 		(void) fprintf(fp, gettext("\t%s group new-group\n"),
241da6c28aaSamw 		    cmd->name);
242da6c28aaSamw 		return;
243da6c28aaSamw 
244da6c28aaSamw 	case HELP_SET:
245da6c28aaSamw 		(void) fprintf(fp, gettext("\t%s -p property=value "
246da6c28aaSamw 		    "[[-p property=value] ...] group\n"), cmd->name);
247da6c28aaSamw 		return;
248da6c28aaSamw 
249da6c28aaSamw 	case HELP_SHOW:
250da6c28aaSamw 		(void) fprintf(fp, gettext("\t%s [-m] [-p] [group]\n"),
251da6c28aaSamw 		    cmd->name);
252da6c28aaSamw 		return;
253da6c28aaSamw 
2543db3f65cSamw 	default:
2553db3f65cSamw 		break;
256da6c28aaSamw 	}
257da6c28aaSamw 
258da6c28aaSamw 	abort();
259da6c28aaSamw 	/* NOTREACHED */
260da6c28aaSamw }
261da6c28aaSamw 
262da6c28aaSamw static void
263da6c28aaSamw smbadm_usage(boolean_t requested)
264da6c28aaSamw {
265da6c28aaSamw 	FILE *fp = requested ? stdout : stderr;
266da6c28aaSamw 	boolean_t show_props = B_FALSE;
267da6c28aaSamw 	int i;
268da6c28aaSamw 
269da6c28aaSamw 	if (curcmd == NULL) {
270da6c28aaSamw 		(void) fprintf(fp,
271da6c28aaSamw 		    gettext("usage: %s [-h | <command> [options]]\n"),
272da6c28aaSamw 		    progname);
273da6c28aaSamw 		(void) fprintf(fp,
274da6c28aaSamw 		    gettext("where 'command' is one of the following:\n\n"));
275da6c28aaSamw 
276da6c28aaSamw 		for (i = 0; i < SMBADM_NCMD; i++)
277da6c28aaSamw 			smbadm_cmdusage(fp, &smbadm_cmdtable[i]);
278da6c28aaSamw 
279da6c28aaSamw 		(void) fprintf(fp,
280da6c28aaSamw 		    gettext("\nFor property list, run %s %s|%s\n"),
281da6c28aaSamw 		    progname, "get", "set");
282da6c28aaSamw 
283da6c28aaSamw 		exit(requested ? 0 : 2);
284da6c28aaSamw 	}
285da6c28aaSamw 
286da6c28aaSamw 	(void) fprintf(fp, gettext("usage:\n"));
287da6c28aaSamw 	smbadm_cmdusage(fp, curcmd);
288da6c28aaSamw 
289da6c28aaSamw 	if (strcmp(curcmd->name, "get") == 0 ||
290da6c28aaSamw 	    strcmp(curcmd->name, "set") == 0)
291da6c28aaSamw 		show_props = B_TRUE;
292da6c28aaSamw 
293da6c28aaSamw 	if (show_props) {
294da6c28aaSamw 		(void) fprintf(fp,
295da6c28aaSamw 		    gettext("\nThe following properties are supported:\n"));
296da6c28aaSamw 
297da6c28aaSamw 		(void) fprintf(fp, "\n\t%-16s   %s\n\n",
298da6c28aaSamw 		    "PROPERTY", "VALUES");
299da6c28aaSamw 
300da6c28aaSamw 		for (i = 0; i < SMBADM_NPROP; i++) {
301da6c28aaSamw 			(void) fprintf(fp, "\t%-16s   %s\n",
302da6c28aaSamw 			    smbadm_ptable[i].p_name,
303da6c28aaSamw 			    smbadm_ptable[i].p_dispvalue);
304da6c28aaSamw 		}
305da6c28aaSamw 	}
306da6c28aaSamw 
307da6c28aaSamw 	exit(requested ? 0 : 2);
308da6c28aaSamw }
309da6c28aaSamw 
310da6c28aaSamw /*
311c8ec8eeaSjose borrego  * smbadm_strcasecmplist
312c8ec8eeaSjose borrego  *
313c8ec8eeaSjose borrego  * Find a string 's' within a list of strings.
314c8ec8eeaSjose borrego  *
315c8ec8eeaSjose borrego  * Returns the index of the matching string or -1 if there is no match.
316c8ec8eeaSjose borrego  */
317c8ec8eeaSjose borrego static int
318c8ec8eeaSjose borrego smbadm_strcasecmplist(const char *s, ...)
319c8ec8eeaSjose borrego {
320c8ec8eeaSjose borrego 	va_list ap;
321c8ec8eeaSjose borrego 	char *p;
322c8ec8eeaSjose borrego 	int ndx;
323c8ec8eeaSjose borrego 
324c8ec8eeaSjose borrego 	va_start(ap, s);
325c8ec8eeaSjose borrego 
326c8ec8eeaSjose borrego 	for (ndx = 0; ((p = va_arg(ap, char *)) != NULL); ++ndx) {
327c8ec8eeaSjose borrego 		if (strcasecmp(s, p) == 0) {
328c8ec8eeaSjose borrego 			va_end(ap);
329c8ec8eeaSjose borrego 			return (ndx);
330c8ec8eeaSjose borrego 		}
331c8ec8eeaSjose borrego 	}
332c8ec8eeaSjose borrego 
333c8ec8eeaSjose borrego 	va_end(ap);
334c8ec8eeaSjose borrego 	return (-1);
335c8ec8eeaSjose borrego }
336c8ec8eeaSjose borrego 
337c8ec8eeaSjose borrego /*
338c8ec8eeaSjose borrego  * smbadm_answer_prompt
339c8ec8eeaSjose borrego  *
340c8ec8eeaSjose borrego  * Prompt for the answer to a question.  A default response must be
341c8ec8eeaSjose borrego  * specified, which will be used if the user presses <enter> without
342c8ec8eeaSjose borrego  * answering the question.
343c8ec8eeaSjose borrego  */
344c8ec8eeaSjose borrego static int
345c8ec8eeaSjose borrego smbadm_answer_prompt(const char *prompt, char *answer, const char *dflt)
346c8ec8eeaSjose borrego {
347c8ec8eeaSjose borrego 	char buf[SMBADM_ANSBUFSIZ];
348c8ec8eeaSjose borrego 	char *p;
349c8ec8eeaSjose borrego 
350c8ec8eeaSjose borrego 	(void) printf(gettext("%s [%s]: "), prompt, dflt);
351c8ec8eeaSjose borrego 
352c8ec8eeaSjose borrego 	if (fgets(buf, SMBADM_ANSBUFSIZ, stdin) == NULL)
353c8ec8eeaSjose borrego 		return (-1);
354c8ec8eeaSjose borrego 
355c8ec8eeaSjose borrego 	if ((p = strchr(buf, '\n')) != NULL)
356c8ec8eeaSjose borrego 		*p = '\0';
357c8ec8eeaSjose borrego 
358c8ec8eeaSjose borrego 	if (*buf == '\0')
359c8ec8eeaSjose borrego 		(void) strlcpy(answer, dflt, SMBADM_ANSBUFSIZ);
360c8ec8eeaSjose borrego 	else
361c8ec8eeaSjose borrego 		(void) strlcpy(answer, buf, SMBADM_ANSBUFSIZ);
362c8ec8eeaSjose borrego 
363c8ec8eeaSjose borrego 	return (0);
364c8ec8eeaSjose borrego }
365c8ec8eeaSjose borrego 
366c8ec8eeaSjose borrego /*
367c8ec8eeaSjose borrego  * smbadm_confirm
368c8ec8eeaSjose borrego  *
369c8ec8eeaSjose borrego  * Ask a question that requires a yes/no answer.
370c8ec8eeaSjose borrego  * A default response must be specified.
371c8ec8eeaSjose borrego  */
372c8ec8eeaSjose borrego static boolean_t
373c8ec8eeaSjose borrego smbadm_confirm(const char *prompt, const char *dflt)
374c8ec8eeaSjose borrego {
375c8ec8eeaSjose borrego 	char buf[SMBADM_ANSBUFSIZ];
376c8ec8eeaSjose borrego 
377c8ec8eeaSjose borrego 	for (;;) {
378c8ec8eeaSjose borrego 		if (smbadm_answer_prompt(prompt, buf, dflt) < 0)
379c8ec8eeaSjose borrego 			return (B_FALSE);
380c8ec8eeaSjose borrego 
381c8ec8eeaSjose borrego 		if (smbadm_strcasecmplist(buf, "n", "no", 0) >= 0)
382c8ec8eeaSjose borrego 			return (B_FALSE);
383c8ec8eeaSjose borrego 
384c8ec8eeaSjose borrego 		if (smbadm_strcasecmplist(buf, "y", "yes", 0) >= 0)
385c8ec8eeaSjose borrego 			return (B_TRUE);
386c8ec8eeaSjose borrego 
387c8ec8eeaSjose borrego 		(void) printf(gettext("Please answer yes or no.\n"));
388c8ec8eeaSjose borrego 	}
389c8ec8eeaSjose borrego }
390c8ec8eeaSjose borrego 
391c8ec8eeaSjose borrego static boolean_t
3928d7e4166Sjose borrego smbadm_join_prompt(const char *domain)
393c8ec8eeaSjose borrego {
3948d7e4166Sjose borrego 	(void) printf(gettext("After joining %s the smb service will be "
3958d7e4166Sjose borrego 	    "restarted automatically.\n"), domain);
396c8ec8eeaSjose borrego 
3978d7e4166Sjose borrego 	return (smbadm_confirm("Would you like to continue?", "no"));
398c8ec8eeaSjose borrego }
399c8ec8eeaSjose borrego 
4008d7e4166Sjose borrego static void
4018d7e4166Sjose borrego smbadm_restart_service(void)
4028d7e4166Sjose borrego {
4038d7e4166Sjose borrego 	if (smb_smf_restart_service() != 0) {
4048d7e4166Sjose borrego 		(void) fprintf(stderr,
4058d7e4166Sjose borrego 		    gettext("Unable to restart smb service. "
4068d7e4166Sjose borrego 		    "Run 'svcs -xv smb/server' for more information."));
4078d7e4166Sjose borrego 	}
408c8ec8eeaSjose borrego }
409c8ec8eeaSjose borrego 
410c8ec8eeaSjose borrego /*
411da6c28aaSamw  * smbadm_join
412da6c28aaSamw  *
4138d7e4166Sjose borrego  * Join a domain or workgroup.
4148d7e4166Sjose borrego  *
4158d7e4166Sjose borrego  * When joining a domain, we may receive the username, password and
4168d7e4166Sjose borrego  * domain name in any of the following combinations.  Note that the
4178d7e4166Sjose borrego  * password is optional on the command line: if it is not provided,
4188d7e4166Sjose borrego  * we will prompt for it later.
4198d7e4166Sjose borrego  *
4208d7e4166Sjose borrego  *	username+password domain
4218d7e4166Sjose borrego  *	domain\username+password
4228d7e4166Sjose borrego  *	domain/username+password
4238d7e4166Sjose borrego  *	username@domain
4248d7e4166Sjose borrego  *
4258d7e4166Sjose borrego  * We allow domain\name+password or domain/name+password but not
4268d7e4166Sjose borrego  * name+password@domain because @ is a valid password character.
4278d7e4166Sjose borrego  *
4288d7e4166Sjose borrego  * If the username and domain name are passed as separate command
4298d7e4166Sjose borrego  * line arguments, we process them directly.  Otherwise we separate
4308d7e4166Sjose borrego  * them and continue as if they were separate command line arguments.
431da6c28aaSamw  */
432da6c28aaSamw static int
433da6c28aaSamw smbadm_join(int argc, char **argv)
434da6c28aaSamw {
4358d7e4166Sjose borrego 	char buf[MAXHOSTNAMELEN * 2];
4368d7e4166Sjose borrego 	char *domain = NULL;
4378d7e4166Sjose borrego 	char *username = NULL;
4388d7e4166Sjose borrego 	uint32_t mode = 0;
439da6c28aaSamw 	char option;
440da6c28aaSamw 
441da6c28aaSamw 	while ((option = getopt(argc, argv, "u:w:")) != -1) {
442da6c28aaSamw 		switch (option) {
443da6c28aaSamw 		case 'w':
4448d7e4166Sjose borrego 			if (mode != 0) {
4458d7e4166Sjose borrego 				(void) fprintf(stderr,
4468d7e4166Sjose borrego 				    gettext("-u and -w must only appear "
4478d7e4166Sjose borrego 				    "once and are mutually exclusive\n"));
4488d7e4166Sjose borrego 				smbadm_usage(B_FALSE);
4498d7e4166Sjose borrego 			}
4508d7e4166Sjose borrego 
4518d7e4166Sjose borrego 			mode = SMB_SECMODE_WORKGRP;
4528d7e4166Sjose borrego 			domain = optarg;
453da6c28aaSamw 			break;
454da6c28aaSamw 
455da6c28aaSamw 		case 'u':
4568d7e4166Sjose borrego 			if (mode != 0) {
4578d7e4166Sjose borrego 				(void) fprintf(stderr,
4588d7e4166Sjose borrego 				    gettext("-u and -w must only appear "
4598d7e4166Sjose borrego 				    "once and are mutually exclusive\n"));
4608d7e4166Sjose borrego 				smbadm_usage(B_FALSE);
4618d7e4166Sjose borrego 			}
4628d7e4166Sjose borrego 
4638d7e4166Sjose borrego 			mode = SMB_SECMODE_DOMAIN;
4648d7e4166Sjose borrego 			username = optarg;
4658d7e4166Sjose borrego 
4668d7e4166Sjose borrego 			if ((domain = argv[optind]) == NULL) {
4678d7e4166Sjose borrego 				/*
4688d7e4166Sjose borrego 				 * The domain was not specified as a separate
4698d7e4166Sjose borrego 				 * argument, check for the combination forms.
4708d7e4166Sjose borrego 				 */
4718d7e4166Sjose borrego 				(void) strlcpy(buf, username, sizeof (buf));
4728d7e4166Sjose borrego 				smbadm_extract_domain(buf, &username, &domain);
4738d7e4166Sjose borrego 			}
4748d7e4166Sjose borrego 
4758d7e4166Sjose borrego 			if ((username == NULL) || (*username == '\0')) {
4768d7e4166Sjose borrego 				(void) fprintf(stderr,
4778d7e4166Sjose borrego 				    gettext("missing username\n"));
4788d7e4166Sjose borrego 				smbadm_usage(B_FALSE);
4798d7e4166Sjose borrego 			}
480da6c28aaSamw 			break;
481da6c28aaSamw 
482da6c28aaSamw 		default:
483da6c28aaSamw 			smbadm_usage(B_FALSE);
4848d7e4166Sjose borrego 			break;
485da6c28aaSamw 		}
486da6c28aaSamw 	}
487da6c28aaSamw 
4888d7e4166Sjose borrego 	if ((domain == NULL) || (*domain == '\0')) {
489da6c28aaSamw 		(void) fprintf(stderr, gettext("missing %s name\n"),
4908d7e4166Sjose borrego 		    (mode == SMB_SECMODE_WORKGRP) ? "workgroup" : "domain");
491da6c28aaSamw 		smbadm_usage(B_FALSE);
492da6c28aaSamw 	}
493da6c28aaSamw 
4948d7e4166Sjose borrego 	if (mode == SMB_SECMODE_WORKGRP)
4958d7e4166Sjose borrego 		return (smbadm_join_workgroup(domain));
4968d7e4166Sjose borrego 	else
4978d7e4166Sjose borrego 		return (smbadm_join_domain(domain, username));
4988d7e4166Sjose borrego }
4998d7e4166Sjose borrego 
5008d7e4166Sjose borrego /*
5018d7e4166Sjose borrego  * Workgroups comprise a collection of standalone, independently administered
5028d7e4166Sjose borrego  * computers that use a common workgroup name.  This is a peer-to-peer model
5038d7e4166Sjose borrego  * with no formal membership mechanism.
5048d7e4166Sjose borrego  */
5058d7e4166Sjose borrego static int
5068d7e4166Sjose borrego smbadm_join_workgroup(const char *workgroup)
5078d7e4166Sjose borrego {
5088d7e4166Sjose borrego 	smb_joininfo_t jdi;
5098d7e4166Sjose borrego 	uint32_t status;
5108d7e4166Sjose borrego 
5118d7e4166Sjose borrego 	bzero(&jdi, sizeof (jdi));
5128d7e4166Sjose borrego 	jdi.mode = SMB_SECMODE_WORKGRP;
5138d7e4166Sjose borrego 	(void) strlcpy(jdi.domain_name, workgroup, sizeof (jdi.domain_name));
5148d7e4166Sjose borrego 	(void) strtrim(jdi.domain_name, " \t\n");
5158d7e4166Sjose borrego 
516fe1c642dSBill Krier 	if (smb_name_validate_workgroup(jdi.domain_name) != ERROR_SUCCESS) {
5178d7e4166Sjose borrego 		(void) fprintf(stderr, gettext("workgroup name is invalid\n"));
518da6c28aaSamw 		smbadm_usage(B_FALSE);
519da6c28aaSamw 	}
520da6c28aaSamw 
5218d7e4166Sjose borrego 	if (!smbadm_join_prompt(jdi.domain_name))
522c8ec8eeaSjose borrego 		return (0);
523c8ec8eeaSjose borrego 
5248d7e4166Sjose borrego 	if ((status = smb_join(&jdi)) != NT_STATUS_SUCCESS) {
5258d7e4166Sjose borrego 		(void) fprintf(stderr, gettext("failed to join %s: %s\n"),
526da6c28aaSamw 		    jdi.domain_name, xlate_nt_status(status));
527da6c28aaSamw 		return (1);
528da6c28aaSamw 	}
529da6c28aaSamw 
5308d7e4166Sjose borrego 	(void) printf(gettext("Successfully joined %s\n"), jdi.domain_name);
5318d7e4166Sjose borrego 	smbadm_restart_service();
532faa1795aSjb150015 	return (0);
533faa1795aSjb150015 }
5348d7e4166Sjose borrego 
5358d7e4166Sjose borrego /*
5368d7e4166Sjose borrego  * Domains comprise a centrally administered group of computers and accounts
5378d7e4166Sjose borrego  * that share a common security and administration policy and database.
5388d7e4166Sjose borrego  * Computers must join a domain and become domain members, which requires
5398d7e4166Sjose borrego  * an administrator level account name.
5408d7e4166Sjose borrego  *
5418d7e4166Sjose borrego  * The '+' character is invalid within a username.  We allow the password
5428d7e4166Sjose borrego  * to be appended to the username using '+' as a scripting convenience.
5438d7e4166Sjose borrego  */
5448d7e4166Sjose borrego static int
5458d7e4166Sjose borrego smbadm_join_domain(const char *domain, const char *username)
5468d7e4166Sjose borrego {
5478d7e4166Sjose borrego 	smb_joininfo_t jdi;
5488d7e4166Sjose borrego 	uint32_t status;
5498d7e4166Sjose borrego 	char *prompt;
5508d7e4166Sjose borrego 	char *p;
5518d7e4166Sjose borrego 	int len;
5528d7e4166Sjose borrego 
5538d7e4166Sjose borrego 	bzero(&jdi, sizeof (jdi));
5548d7e4166Sjose borrego 	jdi.mode = SMB_SECMODE_DOMAIN;
5558d7e4166Sjose borrego 	(void) strlcpy(jdi.domain_name, domain, sizeof (jdi.domain_name));
5568d7e4166Sjose borrego 	(void) strtrim(jdi.domain_name, " \t\n");
5578d7e4166Sjose borrego 
558fe1c642dSBill Krier 	if (smb_name_validate_domain(jdi.domain_name) != ERROR_SUCCESS) {
5598d7e4166Sjose borrego 		(void) fprintf(stderr, gettext("domain name is invalid\n"));
5608d7e4166Sjose borrego 		smbadm_usage(B_FALSE);
561faa1795aSjb150015 	}
562faa1795aSjb150015 
5638d7e4166Sjose borrego 	if (!smbadm_join_prompt(jdi.domain_name))
564c8ec8eeaSjose borrego 		return (0);
565c8ec8eeaSjose borrego 
5668d7e4166Sjose borrego 	if ((p = strchr(username, '+')) != NULL) {
5678d7e4166Sjose borrego 		++p;
5688d7e4166Sjose borrego 
5698d7e4166Sjose borrego 		len = (int)(p - username);
5708d7e4166Sjose borrego 		if (len > sizeof (jdi.domain_name))
5718d7e4166Sjose borrego 			len = sizeof (jdi.domain_name);
5728d7e4166Sjose borrego 
5738d7e4166Sjose borrego 		(void) strlcpy(jdi.domain_username, username, len);
5748d7e4166Sjose borrego 		(void) strlcpy(jdi.domain_passwd, p,
5758d7e4166Sjose borrego 		    sizeof (jdi.domain_passwd));
5768d7e4166Sjose borrego 	} else {
5778d7e4166Sjose borrego 		(void) strlcpy(jdi.domain_username, username,
5788d7e4166Sjose borrego 		    sizeof (jdi.domain_username));
5798d7e4166Sjose borrego 	}
5808d7e4166Sjose borrego 
581fe1c642dSBill Krier 	if (smb_name_validate_account(jdi.domain_username) != ERROR_SUCCESS) {
5828d7e4166Sjose borrego 		(void) fprintf(stderr,
5838d7e4166Sjose borrego 		    gettext("username contains invalid characters\n"));
5848d7e4166Sjose borrego 		smbadm_usage(B_FALSE);
5858d7e4166Sjose borrego 	}
5868d7e4166Sjose borrego 
587da6c28aaSamw 	if (*jdi.domain_passwd == '\0') {
5888d7e4166Sjose borrego 		prompt = gettext("Enter domain password: ");
5898d7e4166Sjose borrego 
5908d7e4166Sjose borrego 		if ((p = getpassphrase(prompt)) == NULL) {
591da6c28aaSamw 			(void) fprintf(stderr, gettext("missing password\n"));
592da6c28aaSamw 			smbadm_usage(B_FALSE);
593da6c28aaSamw 		}
594da6c28aaSamw 
595da6c28aaSamw 		(void) strlcpy(jdi.domain_passwd, p,
596da6c28aaSamw 		    sizeof (jdi.domain_passwd));
597da6c28aaSamw 	}
598da6c28aaSamw 
5998d7e4166Sjose borrego 	(void) printf(gettext("Joining %s ... this may take a minute ...\n"),
600da6c28aaSamw 	    jdi.domain_name);
601da6c28aaSamw 
602da6c28aaSamw 	status = smb_join(&jdi);
603da6c28aaSamw 
604da6c28aaSamw 	switch (status) {
605da6c28aaSamw 	case NT_STATUS_SUCCESS:
6068d7e4166Sjose borrego 		(void) printf(gettext("Successfully joined %s\n"),
607da6c28aaSamw 		    jdi.domain_name);
6088d7e4166Sjose borrego 		bzero(&jdi, sizeof (jdi));
6098d7e4166Sjose borrego 		smbadm_restart_service();
610da6c28aaSamw 		return (0);
611da6c28aaSamw 
612da6c28aaSamw 	case NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND:
6138d7e4166Sjose borrego 		(void) fprintf(stderr,
6148d7e4166Sjose borrego 		    gettext("failed to find any domain controllers for %s\n"),
615da6c28aaSamw 		    jdi.domain_name);
6168d7e4166Sjose borrego 		bzero(&jdi, sizeof (jdi));
6178d7e4166Sjose borrego 		return (1);
618da6c28aaSamw 
619da6c28aaSamw 	default:
6208d7e4166Sjose borrego 		(void) fprintf(stderr, gettext("failed to join %s: %s\n"),
621da6c28aaSamw 		    jdi.domain_name, xlate_nt_status(status));
622fc724630SAlan Wright 		(void) fprintf(stderr, gettext("Please refer to the system log"
623fc724630SAlan Wright 		    " for more information.\n"));
6248d7e4166Sjose borrego 		bzero(&jdi, sizeof (jdi));
6258d7e4166Sjose borrego 		return (1);
6268d7e4166Sjose borrego 	}
627da6c28aaSamw }
628da6c28aaSamw 
6298d7e4166Sjose borrego /*
6308d7e4166Sjose borrego  * We want to process the user and domain names as separate strings.
6318d7e4166Sjose borrego  * Check for names of the forms below and separate the components as
6328d7e4166Sjose borrego  * required.
6338d7e4166Sjose borrego  *
6348d7e4166Sjose borrego  *	name@domain
6358d7e4166Sjose borrego  *	domain\name
6368d7e4166Sjose borrego  *	domain/name
6378d7e4166Sjose borrego  *
6388d7e4166Sjose borrego  * If we encounter any of the forms above in arg, the @, / or \
6398d7e4166Sjose borrego  * separator is replaced by \0 and the username and domain pointers
6408d7e4166Sjose borrego  * are changed to point to the appropriate components (in arg).
6418d7e4166Sjose borrego  *
6428d7e4166Sjose borrego  * If none of the separators are encountered, the username and domain
6438d7e4166Sjose borrego  * pointers remain unchanged.
6448d7e4166Sjose borrego  */
6458d7e4166Sjose borrego static void
6468d7e4166Sjose borrego smbadm_extract_domain(char *arg, char **username, char **domain)
6478d7e4166Sjose borrego {
6488d7e4166Sjose borrego 	char *p;
6498d7e4166Sjose borrego 
6508d7e4166Sjose borrego 	if ((p = strpbrk(arg, "/\\@")) != NULL) {
6518d7e4166Sjose borrego 		if (*p == '@') {
6528d7e4166Sjose borrego 			*p = '\0';
6538d7e4166Sjose borrego 			++p;
6548d7e4166Sjose borrego 
6558d7e4166Sjose borrego 			if (strchr(arg, '+') != NULL)
6568d7e4166Sjose borrego 				return;
6578d7e4166Sjose borrego 
6588d7e4166Sjose borrego 			*domain = p;
6598d7e4166Sjose borrego 			*username = arg;
6608d7e4166Sjose borrego 		} else {
6618d7e4166Sjose borrego 			*p = '\0';
6628d7e4166Sjose borrego 			++p;
6638d7e4166Sjose borrego 			*username = p;
6648d7e4166Sjose borrego 			*domain = arg;
6658d7e4166Sjose borrego 		}
6668d7e4166Sjose borrego 	}
6678d7e4166Sjose borrego }
6688d7e4166Sjose borrego 
6698d7e4166Sjose borrego /*
670da6c28aaSamw  * smbadm_list
671da6c28aaSamw  *
672da6c28aaSamw  * Displays current security mode and domain/workgroup name.
673da6c28aaSamw  */
674da6c28aaSamw /*ARGSUSED*/
675da6c28aaSamw static int
676da6c28aaSamw smbadm_list(int argc, char **argv)
677da6c28aaSamw {
678faa1795aSjb150015 	char domain[MAXHOSTNAMELEN];
6798d7e4166Sjose borrego 	char fqdn[MAXHOSTNAMELEN];
6808d7e4166Sjose borrego 	char srvname[MAXHOSTNAMELEN];
681faa1795aSjb150015 	char modename[16];
682faa1795aSjb150015 	int rc;
6837f667e74Sjose borrego 	smb_inaddr_t srvipaddr;
684c8ec8eeaSjose borrego 	char ipstr[INET6_ADDRSTRLEN];
685da6c28aaSamw 
686faa1795aSjb150015 	rc = smb_config_getstr(SMB_CI_SECURITY, modename, sizeof (modename));
687faa1795aSjb150015 	if (rc != SMBD_SMF_OK) {
688da6c28aaSamw 		(void) fprintf(stderr,
68989dc44ceSjose borrego 		    gettext("cannot determine the operational mode\n"));
690da6c28aaSamw 		return (1);
691da6c28aaSamw 	}
692da6c28aaSamw 
693faa1795aSjb150015 	if (smb_getdomainname(domain, sizeof (domain)) != 0) {
694faa1795aSjb150015 		(void) fprintf(stderr, gettext("failed to get the %s name\n"),
695faa1795aSjb150015 		    modename);
696da6c28aaSamw 		return (1);
697da6c28aaSamw 	}
69889dc44ceSjose borrego 
699c8ec8eeaSjose borrego 	if (strcmp(modename, "workgroup") == 0) {
70089dc44ceSjose borrego 		(void) printf(gettext("[*] [%s]\n"), domain);
701c8ec8eeaSjose borrego 		return (0);
702c8ec8eeaSjose borrego 	}
70389dc44ceSjose borrego 
70489dc44ceSjose borrego 	(void) printf(gettext("[*] [%s]\n"), domain);
7058d7e4166Sjose borrego 	if ((smb_getfqdomainname(fqdn, sizeof (fqdn)) == 0) && (*fqdn != '\0'))
70689dc44ceSjose borrego 		(void) printf(gettext("[*] [%s]\n"), fqdn);
707da6c28aaSamw 
7088d7e4166Sjose borrego 	if ((smb_get_dcinfo(srvname, MAXHOSTNAMELEN, &srvipaddr)
7098d7e4166Sjose borrego 	    == NT_STATUS_SUCCESS) && (*srvname != '\0') &&
7107f667e74Sjose borrego 	    (!smb_inet_iszero(&srvipaddr))) {
7117f667e74Sjose borrego 		(void) smb_inet_ntop(&srvipaddr, ipstr,
7127f667e74Sjose borrego 		    SMB_IPSTRLEN(srvipaddr.a_family));
71389dc44ceSjose borrego 		(void) printf(gettext("\t[+%s.%s] [%s]\n"),
71489dc44ceSjose borrego 		    srvname, fqdn, ipstr);
715c8ec8eeaSjose borrego 	}
71689dc44ceSjose borrego 
717a0aa776eSAlan Wright 	smb_domain_show();
718da6c28aaSamw 	return (0);
719da6c28aaSamw }
720da6c28aaSamw 
721da6c28aaSamw /*
722da6c28aaSamw  * smbadm_group_create
723da6c28aaSamw  *
724da6c28aaSamw  * Creates a local SMB group
725da6c28aaSamw  */
726da6c28aaSamw static int
727da6c28aaSamw smbadm_group_create(int argc, char **argv)
728da6c28aaSamw {
729da6c28aaSamw 	char *gname = NULL;
730da6c28aaSamw 	char *desc = NULL;
731da6c28aaSamw 	char option;
732dc20a302Sas200622 	int status;
733da6c28aaSamw 
734da6c28aaSamw 	while ((option = getopt(argc, argv, "d:")) != -1) {
735da6c28aaSamw 		switch (option) {
736da6c28aaSamw 		case 'd':
737da6c28aaSamw 			desc = optarg;
738da6c28aaSamw 			break;
739da6c28aaSamw 
740da6c28aaSamw 		default:
741da6c28aaSamw 			smbadm_usage(B_FALSE);
742da6c28aaSamw 		}
743da6c28aaSamw 	}
744da6c28aaSamw 
745da6c28aaSamw 	gname = argv[optind];
746da6c28aaSamw 	if (optind >= argc || gname == NULL || *gname == '\0') {
747da6c28aaSamw 		(void) fprintf(stderr, gettext("missing group name\n"));
748da6c28aaSamw 		smbadm_usage(B_FALSE);
749da6c28aaSamw 	}
750da6c28aaSamw 
751da6c28aaSamw 	if (getgrnam(gname) == NULL) {
752da6c28aaSamw 		(void) fprintf(stderr,
753dc20a302Sas200622 		    gettext("failed to get the Solaris group '%s'\n"), gname);
754da6c28aaSamw 		(void) fprintf(stderr,
755dc20a302Sas200622 		    gettext("use 'groupadd' to add '%s'\n"), gname);
756da6c28aaSamw 		return (1);
757da6c28aaSamw 	}
758da6c28aaSamw 
759dc20a302Sas200622 	status = smb_lgrp_add(gname, desc);
760dc20a302Sas200622 	if (status != SMB_LGRP_SUCCESS) {
761da6c28aaSamw 		(void) fprintf(stderr,
762*96a62adaSjoyce mcintosh 		    gettext("failed to create %s (%s)\n"), gname,
763dc20a302Sas200622 		    smb_lgrp_strerror(status));
764da6c28aaSamw 	} else {
765*96a62adaSjoyce mcintosh 		(void) printf(gettext("%s created\n"), gname);
766da6c28aaSamw 	}
767da6c28aaSamw 
768da6c28aaSamw 	return (status);
769da6c28aaSamw }
770da6c28aaSamw 
771da6c28aaSamw /*
772da6c28aaSamw  * smbadm_group_dump_members
773da6c28aaSamw  *
774da6c28aaSamw  * Dump group members details.
775da6c28aaSamw  */
776da6c28aaSamw static void
777dc20a302Sas200622 smbadm_group_dump_members(smb_gsid_t *members, int num)
778da6c28aaSamw {
7796537f381Sas200622 	char		sidstr[SMB_SID_STRSZ];
780fe1c642dSBill Krier 	lsa_account_t	acct;
781da6c28aaSamw 	int		i;
782da6c28aaSamw 
783dc20a302Sas200622 	if (num == 0) {
784da6c28aaSamw 		(void) printf(gettext("\tNo members\n"));
785da6c28aaSamw 		return;
786da6c28aaSamw 	}
787da6c28aaSamw 
788da6c28aaSamw 	(void) printf(gettext("\tMembers:\n"));
789dc20a302Sas200622 	for (i = 0; i < num; i++) {
790fe1c642dSBill Krier 		smb_sid_tostr(members[i].gs_sid, sidstr);
791fe1c642dSBill Krier 
792fe1c642dSBill Krier 		if (smb_lookup_sid(sidstr, &acct) == 0) {
793fe1c642dSBill Krier 			if (acct.a_status == NT_STATUS_SUCCESS)
794fe1c642dSBill Krier 				smbadm_group_show_name(acct.a_domain,
795fe1c642dSBill Krier 				    acct.a_name);
7968c10a865Sas200622 			else
797fe1c642dSBill Krier 				(void) printf(gettext("\t\t%s [%s]\n"),
798fe1c642dSBill Krier 				    sidstr, xlate_nt_status(acct.a_status));
799fe1c642dSBill Krier 		} else {
800fe1c642dSBill Krier 			(void) printf(gettext("\t\t%s\n"), sidstr);
801da6c28aaSamw 		}
802da6c28aaSamw 	}
803fe1c642dSBill Krier }
804fe1c642dSBill Krier 
805fe1c642dSBill Krier static void
806fe1c642dSBill Krier smbadm_group_show_name(const char *domain, const char *name)
807fe1c642dSBill Krier {
808fe1c642dSBill Krier 	if (strchr(domain, '.') != NULL)
809fe1c642dSBill Krier 		(void) printf(gettext("\t\t%s@%s\n"), name, domain);
810fe1c642dSBill Krier 	else
811fe1c642dSBill Krier 		(void) printf(gettext("\t\t%s\\%s\n"), domain, name);
812fe1c642dSBill Krier }
813da6c28aaSamw 
814da6c28aaSamw /*
815da6c28aaSamw  * smbadm_group_dump_privs
816da6c28aaSamw  *
817da6c28aaSamw  * Dump group privilege details.
818da6c28aaSamw  */
819da6c28aaSamw static void
820dc20a302Sas200622 smbadm_group_dump_privs(smb_privset_t *privs)
821da6c28aaSamw {
822dc20a302Sas200622 	smb_privinfo_t *pinfo;
823dc20a302Sas200622 	char *pstatus;
824da6c28aaSamw 	int i;
825da6c28aaSamw 
826da6c28aaSamw 	(void) printf(gettext("\tPrivileges: \n"));
827da6c28aaSamw 
828dc20a302Sas200622 	for (i = 0; i < privs->priv_cnt; i++) {
829dc20a302Sas200622 		pinfo = smb_priv_getbyvalue(privs->priv[i].luid.lo_part);
830dc20a302Sas200622 		if ((pinfo == NULL) || (pinfo->flags & PF_PRESENTABLE) == 0)
831da6c28aaSamw 			continue;
832da6c28aaSamw 
833dc20a302Sas200622 		switch (privs->priv[i].attrs) {
834dc20a302Sas200622 		case SE_PRIVILEGE_ENABLED:
835dc20a302Sas200622 			pstatus = "On";
836dc20a302Sas200622 			break;
837dc20a302Sas200622 		case SE_PRIVILEGE_DISABLED:
838dc20a302Sas200622 			pstatus = "Off";
839dc20a302Sas200622 			break;
840dc20a302Sas200622 		default:
841dc20a302Sas200622 			pstatus = "Unknown";
842dc20a302Sas200622 			break;
843dc20a302Sas200622 		}
844dc20a302Sas200622 		(void) printf(gettext("\t\t%s: %s\n"), pinfo->name, pstatus);
845da6c28aaSamw 	}
846da6c28aaSamw 
847dc20a302Sas200622 	if (privs->priv_cnt == 0)
848da6c28aaSamw 		(void) printf(gettext("\t\tNo privileges\n"));
849da6c28aaSamw }
850da6c28aaSamw 
851da6c28aaSamw /*
852da6c28aaSamw  * smbadm_group_dump
853da6c28aaSamw  *
854da6c28aaSamw  * Dump group details.
855da6c28aaSamw  */
856dc20a302Sas200622 static void
857dc20a302Sas200622 smbadm_group_dump(smb_group_t *grp, boolean_t show_mem, boolean_t show_privs)
858da6c28aaSamw {
8596537f381Sas200622 	char sidstr[SMB_SID_STRSZ];
860da6c28aaSamw 
861dc20a302Sas200622 	(void) printf(gettext("%s (%s)\n"), grp->sg_name, grp->sg_cmnt);
862da6c28aaSamw 
8636537f381Sas200622 	smb_sid_tostr(grp->sg_id.gs_sid, sidstr);
864dc20a302Sas200622 	(void) printf(gettext("\tSID: %s\n"), sidstr);
865da6c28aaSamw 
866da6c28aaSamw 	if (show_privs)
867dc20a302Sas200622 		smbadm_group_dump_privs(grp->sg_privs);
868da6c28aaSamw 
869da6c28aaSamw 	if (show_mem)
870dc20a302Sas200622 		smbadm_group_dump_members(grp->sg_members, grp->sg_nmembers);
871da6c28aaSamw }
872da6c28aaSamw 
873da6c28aaSamw /*
874da6c28aaSamw  * smbadm_group_show
875da6c28aaSamw  *
876da6c28aaSamw  */
877da6c28aaSamw static int
878da6c28aaSamw smbadm_group_show(int argc, char **argv)
879da6c28aaSamw {
880da6c28aaSamw 	char *gname = NULL;
881da6c28aaSamw 	boolean_t show_privs;
882da6c28aaSamw 	boolean_t show_members;
883da6c28aaSamw 	char option;
884dc20a302Sas200622 	int status;
885dc20a302Sas200622 	smb_group_t grp;
886dc20a302Sas200622 	smb_giter_t gi;
887da6c28aaSamw 
888da6c28aaSamw 	show_privs = show_members = B_FALSE;
889da6c28aaSamw 
890da6c28aaSamw 	while ((option = getopt(argc, argv, "mp")) != -1) {
891da6c28aaSamw 		switch (option) {
892da6c28aaSamw 		case 'm':
893da6c28aaSamw 			show_members = B_TRUE;
894da6c28aaSamw 			break;
895da6c28aaSamw 		case 'p':
896da6c28aaSamw 			show_privs = B_TRUE;
897da6c28aaSamw 			break;
898da6c28aaSamw 
899da6c28aaSamw 		default:
900da6c28aaSamw 			smbadm_usage(B_FALSE);
901da6c28aaSamw 		}
902da6c28aaSamw 	}
903da6c28aaSamw 
904da6c28aaSamw 	gname = argv[optind];
905da6c28aaSamw 	if (optind >= argc || gname == NULL || *gname == '\0')
906da6c28aaSamw 		gname = "*";
907da6c28aaSamw 
908dc20a302Sas200622 	if (strcmp(gname, "*")) {
909dc20a302Sas200622 		status = smb_lgrp_getbyname(gname, &grp);
910dc20a302Sas200622 		if (status == SMB_LGRP_SUCCESS) {
911dc20a302Sas200622 			smbadm_group_dump(&grp, show_members, show_privs);
912dc20a302Sas200622 			smb_lgrp_free(&grp);
913dc20a302Sas200622 		} else {
914da6c28aaSamw 			(void) fprintf(stderr,
9158d7e4166Sjose borrego 			    gettext("failed to find %s (%s)\n"),
916dc20a302Sas200622 			    gname, smb_lgrp_strerror(status));
917dc20a302Sas200622 		}
918dc20a302Sas200622 		return (status);
919da6c28aaSamw 	}
920da6c28aaSamw 
9216537f381Sas200622 	if ((status = smb_lgrp_iteropen(&gi)) != SMB_LGRP_SUCCESS) {
9228d7e4166Sjose borrego 		(void) fprintf(stderr, gettext("failed to list groups (%s)\n"),
923dc20a302Sas200622 		    smb_lgrp_strerror(status));
924dc20a302Sas200622 		return (status);
925da6c28aaSamw 	}
926da6c28aaSamw 
9276537f381Sas200622 	while ((status = smb_lgrp_iterate(&gi, &grp)) == SMB_LGRP_SUCCESS) {
928dc20a302Sas200622 		smbadm_group_dump(&grp, show_members, show_privs);
929dc20a302Sas200622 		smb_lgrp_free(&grp);
930da6c28aaSamw 	}
9316537f381Sas200622 
932dc20a302Sas200622 	smb_lgrp_iterclose(&gi);
933da6c28aaSamw 
9346537f381Sas200622 	if (status != SMB_LGRP_NO_MORE) {
9356537f381Sas200622 		(void) fprintf(stderr,
9366537f381Sas200622 		    gettext("failed to get all the groups (%s)\n"),
9376537f381Sas200622 		    smb_lgrp_strerror(status));
9386537f381Sas200622 		return (status);
9396537f381Sas200622 	}
9406537f381Sas200622 
941dc20a302Sas200622 	return (0);
942da6c28aaSamw }
943da6c28aaSamw 
944da6c28aaSamw /*
945da6c28aaSamw  * smbadm_group_delete
946da6c28aaSamw  */
947da6c28aaSamw static int
948da6c28aaSamw smbadm_group_delete(int argc, char **argv)
949da6c28aaSamw {
950da6c28aaSamw 	char *gname = NULL;
951dc20a302Sas200622 	int status;
952da6c28aaSamw 
953da6c28aaSamw 	gname = argv[optind];
954da6c28aaSamw 	if (optind >= argc || gname == NULL || *gname == '\0') {
955da6c28aaSamw 		(void) fprintf(stderr, gettext("missing group name\n"));
956da6c28aaSamw 		smbadm_usage(B_FALSE);
957da6c28aaSamw 	}
958da6c28aaSamw 
959dc20a302Sas200622 	status = smb_lgrp_delete(gname);
960dc20a302Sas200622 	if (status != SMB_LGRP_SUCCESS) {
961da6c28aaSamw 		(void) fprintf(stderr,
9628d7e4166Sjose borrego 		    gettext("failed to delete %s (%s)\n"), gname,
963dc20a302Sas200622 		    smb_lgrp_strerror(status));
964da6c28aaSamw 	} else {
965*96a62adaSjoyce mcintosh 		(void) printf(gettext("%s deleted\n"), gname);
966da6c28aaSamw 	}
967da6c28aaSamw 
968da6c28aaSamw 	return (status);
969da6c28aaSamw }
970da6c28aaSamw 
971da6c28aaSamw /*
972da6c28aaSamw  * smbadm_group_rename
973da6c28aaSamw  */
974da6c28aaSamw static int
975da6c28aaSamw smbadm_group_rename(int argc, char **argv)
976da6c28aaSamw {
977da6c28aaSamw 	char *gname = NULL;
978da6c28aaSamw 	char *ngname = NULL;
979dc20a302Sas200622 	int status;
980da6c28aaSamw 
981da6c28aaSamw 	gname = argv[optind];
982da6c28aaSamw 	if (optind++ >= argc || gname == NULL || *gname == '\0') {
983da6c28aaSamw 		(void) fprintf(stderr, gettext("missing group name\n"));
984da6c28aaSamw 		smbadm_usage(B_FALSE);
985da6c28aaSamw 	}
986da6c28aaSamw 
987da6c28aaSamw 	ngname = argv[optind];
988da6c28aaSamw 	if (optind >= argc || ngname == NULL || *ngname == '\0') {
989da6c28aaSamw 		(void) fprintf(stderr, gettext("missing new group name\n"));
990da6c28aaSamw 		smbadm_usage(B_FALSE);
991da6c28aaSamw 	}
992da6c28aaSamw 
993dc20a302Sas200622 	if (getgrnam(ngname) == NULL) {
994da6c28aaSamw 		(void) fprintf(stderr,
995dc20a302Sas200622 		    gettext("failed to get the Solaris group '%s'\n"), ngname);
996da6c28aaSamw 		(void) fprintf(stderr,
997dc20a302Sas200622 		    gettext("use 'groupadd' to add '%s'\n"), ngname);
998da6c28aaSamw 		return (1);
999da6c28aaSamw 	}
1000da6c28aaSamw 
1001dc20a302Sas200622 	status = smb_lgrp_rename(gname, ngname);
1002dc20a302Sas200622 	if (status != SMB_LGRP_SUCCESS) {
1003dc20a302Sas200622 		if (status == SMB_LGRP_EXISTS)
1004da6c28aaSamw 			(void) fprintf(stderr,
1005dc20a302Sas200622 			    gettext("failed to rename '%s' (%s already "
1006dc20a302Sas200622 			    "exists)\n"), gname, ngname);
1007dc20a302Sas200622 		else
1008dc20a302Sas200622 			(void) fprintf(stderr,
1009dc20a302Sas200622 			    gettext("failed to rename '%s' (%s)\n"), gname,
1010dc20a302Sas200622 			    smb_lgrp_strerror(status));
1011da6c28aaSamw 	} else {
1012dc20a302Sas200622 		(void) printf(gettext("'%s' renamed to '%s'\n"), gname, ngname);
1013da6c28aaSamw 	}
1014da6c28aaSamw 
1015da6c28aaSamw 	return (status);
1016da6c28aaSamw }
1017da6c28aaSamw 
1018da6c28aaSamw /*
1019da6c28aaSamw  * smbadm_group_setprop
1020da6c28aaSamw  *
1021da6c28aaSamw  * Set the group properties.
1022da6c28aaSamw  */
1023da6c28aaSamw static int
1024da6c28aaSamw smbadm_group_setprop(int argc, char **argv)
1025da6c28aaSamw {
1026da6c28aaSamw 	char *gname = NULL;
1027da6c28aaSamw 	smbadm_prop_t props[SMBADM_NPROP];
1028da6c28aaSamw 	smbadm_prop_handle_t *phandle;
1029da6c28aaSamw 	char option;
1030da6c28aaSamw 	int pcnt = 0;
1031da6c28aaSamw 	int ret;
1032da6c28aaSamw 	int p;
1033da6c28aaSamw 
1034da6c28aaSamw 	bzero(props, SMBADM_NPROP * sizeof (smbadm_prop_t));
1035da6c28aaSamw 
1036da6c28aaSamw 	while ((option = getopt(argc, argv, "p:")) != -1) {
1037da6c28aaSamw 		switch (option) {
1038da6c28aaSamw 		case 'p':
1039da6c28aaSamw 			if (pcnt >= SMBADM_NPROP) {
1040da6c28aaSamw 				(void) fprintf(stderr,
1041da6c28aaSamw 				    gettext("exceeded number of supported"
1042da6c28aaSamw 				    " properties\n"));
1043da6c28aaSamw 				smbadm_usage(B_FALSE);
1044da6c28aaSamw 			}
1045da6c28aaSamw 
1046dc20a302Sas200622 			if (smbadm_prop_parse(optarg, &props[pcnt++]) != 0)
1047da6c28aaSamw 				smbadm_usage(B_FALSE);
1048da6c28aaSamw 			break;
1049da6c28aaSamw 
1050da6c28aaSamw 		default:
1051da6c28aaSamw 			smbadm_usage(B_FALSE);
1052da6c28aaSamw 		}
1053da6c28aaSamw 	}
1054da6c28aaSamw 
1055da6c28aaSamw 	if (pcnt == 0) {
1056da6c28aaSamw 		(void) fprintf(stderr,
1057da6c28aaSamw 		    gettext("missing property=value argument\n"));
1058da6c28aaSamw 		smbadm_usage(B_FALSE);
1059da6c28aaSamw 	}
1060da6c28aaSamw 
1061da6c28aaSamw 	gname = argv[optind];
1062da6c28aaSamw 	if (optind >= argc || gname == NULL || *gname == '\0') {
1063da6c28aaSamw 		(void) fprintf(stderr, gettext("missing group name\n"));
1064da6c28aaSamw 		smbadm_usage(B_FALSE);
1065da6c28aaSamw 	}
1066da6c28aaSamw 
1067da6c28aaSamw 	for (p = 0; p < pcnt; p++) {
1068da6c28aaSamw 		phandle = smbadm_prop_gethandle(props[p].p_name);
1069da6c28aaSamw 		if (phandle) {
1070da6c28aaSamw 			if (phandle->p_setfn(gname, &props[p]) != 0)
1071da6c28aaSamw 				ret = 1;
1072da6c28aaSamw 		}
1073da6c28aaSamw 	}
1074da6c28aaSamw 
1075da6c28aaSamw 	return (ret);
1076da6c28aaSamw }
1077da6c28aaSamw 
1078da6c28aaSamw /*
1079da6c28aaSamw  * smbadm_group_getprop
1080da6c28aaSamw  *
1081da6c28aaSamw  * Get the group properties.
1082da6c28aaSamw  */
1083da6c28aaSamw static int
1084da6c28aaSamw smbadm_group_getprop(int argc, char **argv)
1085da6c28aaSamw {
1086da6c28aaSamw 	char *gname = NULL;
1087da6c28aaSamw 	smbadm_prop_t props[SMBADM_NPROP];
1088da6c28aaSamw 	smbadm_prop_handle_t *phandle;
1089da6c28aaSamw 	char option;
1090da6c28aaSamw 	int pcnt = 0;
1091da6c28aaSamw 	int ret;
1092da6c28aaSamw 	int p;
1093da6c28aaSamw 
1094da6c28aaSamw 	bzero(props, SMBADM_NPROP * sizeof (smbadm_prop_t));
1095da6c28aaSamw 
1096da6c28aaSamw 	while ((option = getopt(argc, argv, "p:")) != -1) {
1097da6c28aaSamw 		switch (option) {
1098da6c28aaSamw 		case 'p':
1099da6c28aaSamw 			if (pcnt >= SMBADM_NPROP) {
1100da6c28aaSamw 				(void) fprintf(stderr,
1101da6c28aaSamw 				    gettext("exceeded number of supported"
1102da6c28aaSamw 				    " properties\n"));
1103da6c28aaSamw 				smbadm_usage(B_FALSE);
1104da6c28aaSamw 			}
1105da6c28aaSamw 
1106dc20a302Sas200622 			if (smbadm_prop_parse(optarg, &props[pcnt++]) != 0)
1107da6c28aaSamw 				smbadm_usage(B_FALSE);
1108da6c28aaSamw 			break;
1109da6c28aaSamw 
1110da6c28aaSamw 		default:
1111da6c28aaSamw 			smbadm_usage(B_FALSE);
1112da6c28aaSamw 		}
1113da6c28aaSamw 	}
1114da6c28aaSamw 
1115da6c28aaSamw 	gname = argv[optind];
1116da6c28aaSamw 	if (optind >= argc || gname == NULL || *gname == '\0') {
1117da6c28aaSamw 		(void) fprintf(stderr, gettext("missing group name\n"));
1118da6c28aaSamw 		smbadm_usage(B_FALSE);
1119da6c28aaSamw 	}
1120da6c28aaSamw 
1121da6c28aaSamw 	if (pcnt == 0) {
1122da6c28aaSamw 		/*
1123da6c28aaSamw 		 * If no property has be specified then get
1124da6c28aaSamw 		 * all the properties.
1125da6c28aaSamw 		 */
1126da6c28aaSamw 		pcnt = SMBADM_NPROP;
1127da6c28aaSamw 		for (p = 0; p < pcnt; p++)
1128da6c28aaSamw 			props[p].p_name = smbadm_ptable[p].p_name;
1129da6c28aaSamw 	}
1130da6c28aaSamw 
1131da6c28aaSamw 	for (p = 0; p < pcnt; p++) {
1132da6c28aaSamw 		phandle = smbadm_prop_gethandle(props[p].p_name);
1133da6c28aaSamw 		if (phandle) {
1134da6c28aaSamw 			if (phandle->p_getfn(gname, &props[p]) != 0)
1135da6c28aaSamw 				ret = 1;
1136da6c28aaSamw 		}
1137da6c28aaSamw 	}
1138da6c28aaSamw 
1139da6c28aaSamw 	return (ret);
1140da6c28aaSamw }
1141da6c28aaSamw 
1142da6c28aaSamw /*
1143da6c28aaSamw  * smbadm_group_addmember
1144da6c28aaSamw  *
1145da6c28aaSamw  */
1146da6c28aaSamw static int
1147da6c28aaSamw smbadm_group_addmember(int argc, char **argv)
1148da6c28aaSamw {
1149fe1c642dSBill Krier 	lsa_account_t	acct;
1150da6c28aaSamw 	char *gname = NULL;
1151da6c28aaSamw 	char **mname;
1152da6c28aaSamw 	char option;
1153dc20a302Sas200622 	smb_gsid_t msid;
1154dc20a302Sas200622 	int status;
1155da6c28aaSamw 	int mcnt = 0;
1156da6c28aaSamw 	int ret = 0;
1157da6c28aaSamw 	int i;
1158da6c28aaSamw 
1159da6c28aaSamw 
1160da6c28aaSamw 	mname = (char **)malloc(argc * sizeof (char *));
1161da6c28aaSamw 	if (mname == NULL) {
11628d7e4166Sjose borrego 		warn(gettext("failed to add group member"));
1163da6c28aaSamw 		return (1);
1164da6c28aaSamw 	}
1165da6c28aaSamw 	bzero(mname, argc * sizeof (char *));
1166da6c28aaSamw 
1167da6c28aaSamw 	while ((option = getopt(argc, argv, "m:")) != -1) {
1168da6c28aaSamw 		switch (option) {
1169da6c28aaSamw 		case 'm':
1170da6c28aaSamw 			mname[mcnt++] = optarg;
1171da6c28aaSamw 			break;
1172da6c28aaSamw 
1173da6c28aaSamw 		default:
1174da6c28aaSamw 			free(mname);
1175da6c28aaSamw 			smbadm_usage(B_FALSE);
1176da6c28aaSamw 		}
1177da6c28aaSamw 	}
1178da6c28aaSamw 
1179da6c28aaSamw 	if (mcnt == 0) {
1180da6c28aaSamw 		(void) fprintf(stderr, gettext("missing member name\n"));
1181da6c28aaSamw 		free(mname);
1182da6c28aaSamw 		smbadm_usage(B_FALSE);
1183da6c28aaSamw 	}
1184da6c28aaSamw 
1185da6c28aaSamw 	gname = argv[optind];
1186da6c28aaSamw 	if (optind >= argc || gname == NULL || *gname == 0) {
1187da6c28aaSamw 		(void) fprintf(stderr, gettext("missing group name\n"));
1188da6c28aaSamw 		free(mname);
1189da6c28aaSamw 		smbadm_usage(B_FALSE);
1190da6c28aaSamw 	}
1191da6c28aaSamw 
1192da6c28aaSamw 
1193da6c28aaSamw 	for (i = 0; i < mcnt; i++) {
1194fe1c642dSBill Krier 		ret = 0;
1195da6c28aaSamw 		if (mname[i] == NULL)
1196da6c28aaSamw 			continue;
1197da6c28aaSamw 
1198fe1c642dSBill Krier 		ret = smb_lookup_name(mname[i], SidTypeUnknown, &acct);
1199fe1c642dSBill Krier 		if ((ret != 0) || (acct.a_status != NT_STATUS_SUCCESS)) {
1200dc20a302Sas200622 			(void) fprintf(stderr,
12018d7e4166Sjose borrego 			    gettext("failed to add %s: unable to obtain SID\n"),
1202dc20a302Sas200622 			    mname[i]);
1203dc20a302Sas200622 			continue;
1204dc20a302Sas200622 		}
1205dc20a302Sas200622 
1206fe1c642dSBill Krier 		msid.gs_type = acct.a_sidtype;
1207fe1c642dSBill Krier 
1208fe1c642dSBill Krier 		if ((msid.gs_sid = smb_sid_fromstr(acct.a_sid)) == NULL) {
1209fe1c642dSBill Krier 			(void) fprintf(stderr,
1210fe1c642dSBill Krier 			    gettext("failed to add %s: no memory\n"), mname[i]);
1211fe1c642dSBill Krier 			continue;
1212fe1c642dSBill Krier 		}
1213fe1c642dSBill Krier 
1214dc20a302Sas200622 		status = smb_lgrp_add_member(gname, msid.gs_sid, msid.gs_type);
1215fe1c642dSBill Krier 		smb_sid_free(msid.gs_sid);
1216dc20a302Sas200622 		if (status != SMB_LGRP_SUCCESS) {
1217da6c28aaSamw 			(void) fprintf(stderr,
1218da6c28aaSamw 			    gettext("failed to add %s (%s)\n"),
1219dc20a302Sas200622 			    mname[i], smb_lgrp_strerror(status));
1220da6c28aaSamw 			ret = 1;
1221dc20a302Sas200622 		} else {
1222dc20a302Sas200622 			(void) printf(gettext("'%s' is now a member of '%s'\n"),
1223da6c28aaSamw 			    mname[i], gname);
1224da6c28aaSamw 		}
1225dc20a302Sas200622 	}
1226da6c28aaSamw 
1227da6c28aaSamw 	free(mname);
1228da6c28aaSamw 	return (ret);
1229da6c28aaSamw }
1230da6c28aaSamw 
1231da6c28aaSamw /*
1232da6c28aaSamw  * smbadm_group_delmember
1233da6c28aaSamw  */
1234da6c28aaSamw static int
1235da6c28aaSamw smbadm_group_delmember(int argc, char **argv)
1236da6c28aaSamw {
1237fe1c642dSBill Krier 	lsa_account_t	acct;
1238da6c28aaSamw 	char *gname = NULL;
1239da6c28aaSamw 	char **mname;
1240da6c28aaSamw 	char option;
1241dc20a302Sas200622 	smb_gsid_t msid;
1242dc20a302Sas200622 	int status;
1243da6c28aaSamw 	int mcnt = 0;
1244da6c28aaSamw 	int ret = 0;
1245da6c28aaSamw 	int i;
1246da6c28aaSamw 
1247da6c28aaSamw 	mname = (char **)malloc(argc * sizeof (char *));
1248da6c28aaSamw 	if (mname == NULL) {
12498d7e4166Sjose borrego 		warn(gettext("failed to delete group member"));
1250da6c28aaSamw 		return (1);
1251da6c28aaSamw 	}
1252da6c28aaSamw 	bzero(mname, argc * sizeof (char *));
1253da6c28aaSamw 
1254da6c28aaSamw 	while ((option = getopt(argc, argv, "m:")) != -1) {
1255da6c28aaSamw 		switch (option) {
1256da6c28aaSamw 		case 'm':
1257da6c28aaSamw 			mname[mcnt++] = optarg;
1258da6c28aaSamw 			break;
1259da6c28aaSamw 
1260da6c28aaSamw 		default:
1261da6c28aaSamw 			free(mname);
1262da6c28aaSamw 			smbadm_usage(B_FALSE);
1263da6c28aaSamw 		}
1264da6c28aaSamw 	}
1265da6c28aaSamw 
1266da6c28aaSamw 	if (mcnt == 0) {
1267da6c28aaSamw 		(void) fprintf(stderr, gettext("missing member name\n"));
1268da6c28aaSamw 		free(mname);
1269da6c28aaSamw 		smbadm_usage(B_FALSE);
1270da6c28aaSamw 	}
1271da6c28aaSamw 
1272da6c28aaSamw 	gname = argv[optind];
1273da6c28aaSamw 	if (optind >= argc || gname == NULL || *gname == 0) {
1274da6c28aaSamw 		(void) fprintf(stderr, gettext("missing group name\n"));
1275da6c28aaSamw 		free(mname);
1276da6c28aaSamw 		smbadm_usage(B_FALSE);
1277da6c28aaSamw 	}
1278da6c28aaSamw 
1279da6c28aaSamw 
1280da6c28aaSamw 	for (i = 0; i < mcnt; i++) {
1281fe1c642dSBill Krier 		ret = 0;
1282da6c28aaSamw 		if (mname[i] == NULL)
1283da6c28aaSamw 			continue;
1284da6c28aaSamw 
1285fe1c642dSBill Krier 		ret = smb_lookup_name(mname[i], SidTypeUnknown, &acct);
1286fe1c642dSBill Krier 		if ((ret != 0) || (acct.a_status != NT_STATUS_SUCCESS)) {
1287dc20a302Sas200622 			(void) fprintf(stderr,
12888d7e4166Sjose borrego 			    gettext("failed to remove %s: "
12898d7e4166Sjose borrego 			    "unable to obtain SID\n"),
1290dc20a302Sas200622 			    mname[i]);
1291dc20a302Sas200622 			continue;
1292dc20a302Sas200622 		}
1293dc20a302Sas200622 
1294fe1c642dSBill Krier 		msid.gs_type = acct.a_sidtype;
1295fe1c642dSBill Krier 
1296fe1c642dSBill Krier 		if ((msid.gs_sid = smb_sid_fromstr(acct.a_sid)) == NULL) {
1297fe1c642dSBill Krier 			(void) fprintf(stderr,
1298fe1c642dSBill Krier 			    gettext("failed to remove %s: no memory\n"),
1299fe1c642dSBill Krier 			    mname[i]);
1300fe1c642dSBill Krier 			continue;
1301fe1c642dSBill Krier 		}
1302fe1c642dSBill Krier 
1303dc20a302Sas200622 		status = smb_lgrp_del_member(gname, msid.gs_sid, msid.gs_type);
1304fe1c642dSBill Krier 		smb_sid_free(msid.gs_sid);
1305dc20a302Sas200622 		if (status != SMB_LGRP_SUCCESS) {
1306da6c28aaSamw 			(void) fprintf(stderr,
1307da6c28aaSamw 			    gettext("failed to remove %s (%s)\n"),
1308dc20a302Sas200622 			    mname[i], smb_lgrp_strerror(status));
1309da6c28aaSamw 			ret = 1;
1310da6c28aaSamw 		} else {
1311da6c28aaSamw 			(void) printf(
1312dc20a302Sas200622 			    gettext("'%s' has been removed from %s\n"),
1313da6c28aaSamw 			    mname[i], gname);
1314da6c28aaSamw 		}
1315da6c28aaSamw 	}
1316da6c28aaSamw 
1317da6c28aaSamw 	return (ret);
1318da6c28aaSamw }
1319da6c28aaSamw 
1320da6c28aaSamw static int
1321da6c28aaSamw smbadm_user_disable(int argc, char **argv)
1322da6c28aaSamw {
1323da6c28aaSamw 	int error;
1324da6c28aaSamw 	char *user = NULL;
1325da6c28aaSamw 
1326da6c28aaSamw 	user = argv[optind];
1327da6c28aaSamw 	if (optind >= argc || user == NULL || *user == '\0') {
1328da6c28aaSamw 		(void) fprintf(stderr, gettext("missing user name\n"));
1329da6c28aaSamw 		smbadm_usage(B_FALSE);
1330da6c28aaSamw 	}
1331da6c28aaSamw 
1332da6c28aaSamw 	error = smb_pwd_setcntl(user, SMB_PWC_DISABLE);
1333da6c28aaSamw 	if (error == SMB_PWE_SUCCESS)
1334da6c28aaSamw 		(void) printf(gettext("%s is disabled.\n"), user);
1335da6c28aaSamw 	else
1336da6c28aaSamw 		(void) fprintf(stderr, "%s\n", smbadm_pwd_strerror(error));
1337da6c28aaSamw 
1338da6c28aaSamw 	return (error);
1339da6c28aaSamw }
1340da6c28aaSamw 
1341da6c28aaSamw static int
1342da6c28aaSamw smbadm_user_enable(int argc, char **argv)
1343da6c28aaSamw {
1344da6c28aaSamw 	int error;
1345da6c28aaSamw 	char *user = NULL;
1346da6c28aaSamw 
1347da6c28aaSamw 	user = argv[optind];
1348da6c28aaSamw 	if (optind >= argc || user == NULL || *user == '\0') {
1349da6c28aaSamw 		(void) fprintf(stderr, gettext("missing user name\n"));
1350da6c28aaSamw 		smbadm_usage(B_FALSE);
1351da6c28aaSamw 	}
1352da6c28aaSamw 
1353da6c28aaSamw 	error = smb_pwd_setcntl(user, SMB_PWC_ENABLE);
1354da6c28aaSamw 	if (error == SMB_PWE_SUCCESS)
1355da6c28aaSamw 		(void) printf(gettext("%s is enabled.\n"), user);
1356da6c28aaSamw 	else
1357da6c28aaSamw 		(void) fprintf(stderr, "%s\n", smbadm_pwd_strerror(error));
1358da6c28aaSamw 
1359da6c28aaSamw 	return (error);
1360da6c28aaSamw }
1361da6c28aaSamw 
1362da6c28aaSamw 
1363da6c28aaSamw int
1364da6c28aaSamw main(int argc, char **argv)
1365da6c28aaSamw {
1366dc20a302Sas200622 	int ret;
1367da6c28aaSamw 	int i;
1368da6c28aaSamw 
1369*96a62adaSjoyce mcintosh 	(void) setlocale(LC_ALL, "");
1370*96a62adaSjoyce mcintosh 	(void) textdomain(TEXT_DOMAIN);
1371*96a62adaSjoyce mcintosh 
1372da6c28aaSamw 	(void) malloc(0);	/* satisfy libumem dependency */
1373da6c28aaSamw 
1374da6c28aaSamw 	progname = basename(argv[0]);
1375da6c28aaSamw 
1376da6c28aaSamw 	if (getzoneid() != GLOBAL_ZONEID) {
1377da6c28aaSamw 		(void) fprintf(stderr,
1378da6c28aaSamw 		    gettext("cannot execute in non-global zone\n"));
1379da6c28aaSamw 		return (0);
1380da6c28aaSamw 	}
1381da6c28aaSamw 
1382da6c28aaSamw 	if (is_system_labeled()) {
1383da6c28aaSamw 		(void) fprintf(stderr,
1384da6c28aaSamw 		    gettext("Trusted Extensions not supported\n"));
1385da6c28aaSamw 		return (0);
1386da6c28aaSamw 	}
1387da6c28aaSamw 
1388da6c28aaSamw 	if (argc < 2) {
1389da6c28aaSamw 		(void) fprintf(stderr, gettext("missing command\n"));
1390da6c28aaSamw 		smbadm_usage(B_FALSE);
1391da6c28aaSamw 	}
1392da6c28aaSamw 
1393da6c28aaSamw 	/*
1394da6c28aaSamw 	 * Special case "cmd --help/-?"
1395da6c28aaSamw 	 */
1396da6c28aaSamw 	if (strcmp(argv[1], "-?") == 0 ||
1397da6c28aaSamw 	    strcmp(argv[1], "--help") == 0 ||
1398da6c28aaSamw 	    strcmp(argv[1], "-h") == 0)
1399da6c28aaSamw 		smbadm_usage(B_TRUE);
1400da6c28aaSamw 
1401da6c28aaSamw 	for (i = 0; i < SMBADM_NCMD; ++i) {
1402da6c28aaSamw 		curcmd = &smbadm_cmdtable[i];
1403da6c28aaSamw 		if (strcasecmp(argv[1], curcmd->name) == 0) {
1404da6c28aaSamw 			if (argc > 2) {
1405da6c28aaSamw 				/* cmd subcmd --help/-? */
1406da6c28aaSamw 				if (strcmp(argv[2], "-?") == 0 ||
1407da6c28aaSamw 				    strcmp(argv[2], "--help") == 0 ||
1408da6c28aaSamw 				    strcmp(argv[2], "-h") == 0)
1409da6c28aaSamw 					smbadm_usage(B_TRUE);
1410da6c28aaSamw 			}
1411da6c28aaSamw 
1412*96a62adaSjoyce mcintosh 			if (!smbadm_checkauth(curcmd->auth)) {
1413*96a62adaSjoyce mcintosh 				(void) fprintf(stderr,
1414*96a62adaSjoyce mcintosh 				    gettext("%s: %s: authorization denied\n"),
1415*96a62adaSjoyce mcintosh 				    progname, curcmd->name);
1416*96a62adaSjoyce mcintosh 				return (1);
1417*96a62adaSjoyce mcintosh 			}
1418*96a62adaSjoyce mcintosh 
14193db3f65cSamw 			if ((ret = smbadm_init()) != 0)
1420faa1795aSjb150015 				return (ret);
1421dc20a302Sas200622 
1422dc20a302Sas200622 			ret = curcmd->func(argc - 1, &argv[1]);
1423faa1795aSjb150015 
14243db3f65cSamw 			smbadm_fini();
1425dc20a302Sas200622 			return (ret);
1426da6c28aaSamw 		}
1427da6c28aaSamw 	}
1428da6c28aaSamw 
1429da6c28aaSamw 	curcmd = NULL;
1430da6c28aaSamw 	(void) fprintf(stderr, gettext("unknown subcommand (%s)\n"), argv[1]);
1431da6c28aaSamw 	smbadm_usage(B_FALSE);
1432da6c28aaSamw 	return (2);
1433da6c28aaSamw }
1434da6c28aaSamw 
1435faa1795aSjb150015 static int
14363db3f65cSamw smbadm_init(void)
1437faa1795aSjb150015 {
1438faa1795aSjb150015 	int rc;
1439faa1795aSjb150015 
14403db3f65cSamw 	switch (curcmd->flags & SMBADM_CMDF_TYPEMASK) {
14413db3f65cSamw 	case SMBADM_CMDF_GROUP:
1442faa1795aSjb150015 		if (smb_idmap_start() != 0) {
1443faa1795aSjb150015 			(void) fprintf(stderr,
1444faa1795aSjb150015 			    gettext("failed to contact idmap service\n"));
1445faa1795aSjb150015 			return (1);
1446faa1795aSjb150015 		}
1447faa1795aSjb150015 
1448faa1795aSjb150015 		if ((rc = smb_lgrp_start()) != SMB_LGRP_SUCCESS) {
1449faa1795aSjb150015 			(void) fprintf(stderr,
1450faa1795aSjb150015 			    gettext("failed to initialize (%s)\n"),
1451faa1795aSjb150015 			    smb_lgrp_strerror(rc));
1452faa1795aSjb150015 			smb_idmap_stop();
1453faa1795aSjb150015 			return (1);
1454faa1795aSjb150015 		}
14553db3f65cSamw 		break;
14563db3f65cSamw 
14573db3f65cSamw 	case SMBADM_CMDF_USER:
14583db3f65cSamw 		smb_pwd_init(B_FALSE);
14593db3f65cSamw 		break;
14603db3f65cSamw 
14613db3f65cSamw 	default:
14623db3f65cSamw 		break;
1463faa1795aSjb150015 	}
1464faa1795aSjb150015 
1465faa1795aSjb150015 	return (0);
1466faa1795aSjb150015 }
1467faa1795aSjb150015 
1468faa1795aSjb150015 static void
14693db3f65cSamw smbadm_fini(void)
1470faa1795aSjb150015 {
14713db3f65cSamw 	switch (curcmd->flags & SMBADM_CMDF_TYPEMASK) {
14723db3f65cSamw 	case SMBADM_CMDF_GROUP:
1473faa1795aSjb150015 		smb_lgrp_stop();
1474faa1795aSjb150015 		smb_idmap_stop();
14753db3f65cSamw 		break;
14763db3f65cSamw 
14773db3f65cSamw 	case SMBADM_CMDF_USER:
14783db3f65cSamw 		smb_pwd_fini();
14793db3f65cSamw 		break;
14803db3f65cSamw 
14813db3f65cSamw 	default:
14823db3f65cSamw 		break;
1483faa1795aSjb150015 	}
1484faa1795aSjb150015 }
1485faa1795aSjb150015 
1486da6c28aaSamw static boolean_t
1487*96a62adaSjoyce mcintosh smbadm_checkauth(const char *auth)
1488*96a62adaSjoyce mcintosh {
1489*96a62adaSjoyce mcintosh 	struct passwd *pw;
1490*96a62adaSjoyce mcintosh 
1491*96a62adaSjoyce mcintosh 	if ((pw = getpwuid(getuid())) == NULL)
1492*96a62adaSjoyce mcintosh 		return (B_FALSE);
1493*96a62adaSjoyce mcintosh 
1494*96a62adaSjoyce mcintosh 	if (chkauthattr(auth, pw->pw_name) == 0)
1495*96a62adaSjoyce mcintosh 		return (B_FALSE);
1496*96a62adaSjoyce mcintosh 
1497*96a62adaSjoyce mcintosh 	return (B_TRUE);
1498*96a62adaSjoyce mcintosh }
1499*96a62adaSjoyce mcintosh 
1500*96a62adaSjoyce mcintosh static boolean_t
1501da6c28aaSamw smbadm_prop_validate(smbadm_prop_t *prop, boolean_t chkval)
1502da6c28aaSamw {
1503da6c28aaSamw 	smbadm_prop_handle_t *pinfo;
1504da6c28aaSamw 	int i;
1505da6c28aaSamw 
1506da6c28aaSamw 	for (i = 0; i < SMBADM_NPROP; i++) {
1507da6c28aaSamw 		pinfo = &smbadm_ptable[i];
1508da6c28aaSamw 		if (strcmp(pinfo->p_name, prop->p_name) == 0) {
1509da6c28aaSamw 			if (pinfo->p_chkfn && chkval)
1510da6c28aaSamw 				return (pinfo->p_chkfn(prop));
1511da6c28aaSamw 
1512da6c28aaSamw 			return (B_TRUE);
1513da6c28aaSamw 		}
1514da6c28aaSamw 	}
1515da6c28aaSamw 
15168d7e4166Sjose borrego 	(void) fprintf(stderr, gettext("unrecognized property '%s'\n"),
15178d7e4166Sjose borrego 	    prop->p_name);
1518da6c28aaSamw 
1519da6c28aaSamw 	return (B_FALSE);
1520da6c28aaSamw }
1521da6c28aaSamw 
1522da6c28aaSamw static int
1523da6c28aaSamw smbadm_prop_parse(char *arg, smbadm_prop_t *prop)
1524da6c28aaSamw {
1525da6c28aaSamw 	boolean_t parse_value;
1526da6c28aaSamw 	char *equal;
1527da6c28aaSamw 
1528da6c28aaSamw 	if (arg == NULL)
1529da6c28aaSamw 		return (2);
1530da6c28aaSamw 
1531da6c28aaSamw 	prop->p_name = prop->p_value = NULL;
1532da6c28aaSamw 
1533da6c28aaSamw 	if (strcmp(curcmd->name, "set") == 0)
1534da6c28aaSamw 		parse_value = B_TRUE;
1535da6c28aaSamw 	else
1536da6c28aaSamw 		parse_value = B_FALSE;
1537da6c28aaSamw 
1538da6c28aaSamw 	prop->p_name = arg;
1539da6c28aaSamw 
1540da6c28aaSamw 	if (parse_value) {
1541da6c28aaSamw 		equal = strchr(arg, '=');
1542da6c28aaSamw 		if (equal == NULL)
1543da6c28aaSamw 			return (2);
1544da6c28aaSamw 
1545da6c28aaSamw 		*equal++ = '\0';
1546da6c28aaSamw 		prop->p_value = equal;
1547da6c28aaSamw 	}
1548da6c28aaSamw 
1549da6c28aaSamw 	if (smbadm_prop_validate(prop, parse_value) == B_FALSE)
1550da6c28aaSamw 		return (2);
1551da6c28aaSamw 
1552da6c28aaSamw 	return (0);
1553da6c28aaSamw }
1554da6c28aaSamw 
1555da6c28aaSamw static smbadm_prop_handle_t *
1556da6c28aaSamw smbadm_prop_gethandle(char *pname)
1557da6c28aaSamw {
1558da6c28aaSamw 	int i;
1559da6c28aaSamw 
1560da6c28aaSamw 	for (i = 0; i < SMBADM_NPROP; i++)
1561da6c28aaSamw 		if (strcmp(pname, smbadm_ptable[i].p_name) == 0)
1562da6c28aaSamw 			return (&smbadm_ptable[i]);
1563da6c28aaSamw 
1564da6c28aaSamw 	return (NULL);
1565da6c28aaSamw }
1566da6c28aaSamw 
1567da6c28aaSamw static int
1568da6c28aaSamw smbadm_setprop_desc(char *gname, smbadm_prop_t *prop)
1569da6c28aaSamw {
1570dc20a302Sas200622 	int status;
1571da6c28aaSamw 
1572dc20a302Sas200622 	status = smb_lgrp_setcmnt(gname, prop->p_value);
1573dc20a302Sas200622 	if (status != SMB_LGRP_SUCCESS) {
1574da6c28aaSamw 		(void) fprintf(stderr,
1575da6c28aaSamw 		    gettext("failed to modify the group description (%s)\n"),
1576dc20a302Sas200622 		    smb_lgrp_strerror(status));
1577da6c28aaSamw 		return (1);
1578da6c28aaSamw 	}
1579da6c28aaSamw 
15808d7e4166Sjose borrego 	(void) printf(gettext("%s: description modified\n"), gname);
1581da6c28aaSamw 	return (0);
1582da6c28aaSamw }
1583da6c28aaSamw 
1584da6c28aaSamw static int
1585da6c28aaSamw smbadm_getprop_desc(char *gname, smbadm_prop_t *prop)
1586da6c28aaSamw {
1587dc20a302Sas200622 	char *cmnt = NULL;
1588dc20a302Sas200622 	int status;
1589da6c28aaSamw 
1590dc20a302Sas200622 	status = smb_lgrp_getcmnt(gname, &cmnt);
1591dc20a302Sas200622 	if (status != SMB_LGRP_SUCCESS) {
1592da6c28aaSamw 		(void) fprintf(stderr,
1593dc20a302Sas200622 		    gettext("failed to get the group description (%s)\n"),
1594dc20a302Sas200622 		    smb_lgrp_strerror(status));
1595da6c28aaSamw 		return (1);
1596da6c28aaSamw 	}
1597da6c28aaSamw 
1598dc20a302Sas200622 	(void) printf(gettext("\t%s: %s\n"), prop->p_name, cmnt);
1599dc20a302Sas200622 	free(cmnt);
1600da6c28aaSamw 	return (0);
1601da6c28aaSamw }
1602da6c28aaSamw 
1603da6c28aaSamw static int
1604dc20a302Sas200622 smbadm_group_setpriv(char *gname, uint8_t priv_id, smbadm_prop_t *prop)
1605da6c28aaSamw {
1606dc20a302Sas200622 	boolean_t enable;
1607dc20a302Sas200622 	int status;
1608da6c28aaSamw 	int ret;
1609da6c28aaSamw 
1610da6c28aaSamw 	if (strcasecmp(prop->p_value, "on") == 0) {
1611da6c28aaSamw 		(void) printf(gettext("Enabling %s privilege "), prop->p_name);
1612dc20a302Sas200622 		enable = B_TRUE;
1613da6c28aaSamw 	} else {
1614da6c28aaSamw 		(void) printf(gettext("Disabling %s privilege "), prop->p_name);
1615dc20a302Sas200622 		enable = B_FALSE;
1616da6c28aaSamw 	}
1617da6c28aaSamw 
1618dc20a302Sas200622 	status = smb_lgrp_setpriv(gname, priv_id, enable);
1619dc20a302Sas200622 	if (status == SMB_LGRP_SUCCESS) {
1620da6c28aaSamw 		(void) printf(gettext("succeeded\n"));
1621da6c28aaSamw 		ret = 0;
1622da6c28aaSamw 	} else {
1623dc20a302Sas200622 		(void) printf(gettext("failed: %s\n"),
1624dc20a302Sas200622 		    smb_lgrp_strerror(status));
1625da6c28aaSamw 		ret = 1;
1626da6c28aaSamw 	}
1627da6c28aaSamw 
1628da6c28aaSamw 	return (ret);
1629da6c28aaSamw }
1630da6c28aaSamw 
1631da6c28aaSamw static int
1632dc20a302Sas200622 smbadm_group_getpriv(char *gname, uint8_t priv_id, smbadm_prop_t *prop)
1633da6c28aaSamw {
1634dc20a302Sas200622 	boolean_t enable;
1635dc20a302Sas200622 	int status;
1636da6c28aaSamw 
1637dc20a302Sas200622 	status = smb_lgrp_getpriv(gname, priv_id, &enable);
1638dc20a302Sas200622 	if (status != SMB_LGRP_SUCCESS) {
1639da6c28aaSamw 		(void) fprintf(stderr, gettext("failed to get %s (%s)\n"),
1640dc20a302Sas200622 		    prop->p_name, smb_lgrp_strerror(status));
1641da6c28aaSamw 		return (1);
1642da6c28aaSamw 	}
1643da6c28aaSamw 
1644dc20a302Sas200622 	(void) printf(gettext("\t%s: %s\n"), prop->p_name,
1645dc20a302Sas200622 	    (enable) ? "On" : "Off");
1646da6c28aaSamw 
1647da6c28aaSamw 	return (0);
1648da6c28aaSamw }
1649da6c28aaSamw 
1650da6c28aaSamw static int
1651da6c28aaSamw smbadm_setprop_tkowner(char *gname, smbadm_prop_t *prop)
1652da6c28aaSamw {
1653da6c28aaSamw 	return (smbadm_group_setpriv(gname, SE_TAKE_OWNERSHIP_LUID, prop));
1654da6c28aaSamw }
1655da6c28aaSamw 
1656da6c28aaSamw static int
1657da6c28aaSamw smbadm_getprop_tkowner(char *gname, smbadm_prop_t *prop)
1658da6c28aaSamw {
1659da6c28aaSamw 	return (smbadm_group_getpriv(gname, SE_TAKE_OWNERSHIP_LUID, prop));
1660da6c28aaSamw }
1661da6c28aaSamw 
1662da6c28aaSamw static int
1663da6c28aaSamw smbadm_setprop_backup(char *gname, smbadm_prop_t *prop)
1664da6c28aaSamw {
1665da6c28aaSamw 	return (smbadm_group_setpriv(gname, SE_BACKUP_LUID, prop));
1666da6c28aaSamw }
1667da6c28aaSamw 
1668da6c28aaSamw static int
1669da6c28aaSamw smbadm_getprop_backup(char *gname, smbadm_prop_t *prop)
1670da6c28aaSamw {
1671da6c28aaSamw 	return (smbadm_group_getpriv(gname, SE_BACKUP_LUID, prop));
1672da6c28aaSamw }
1673da6c28aaSamw 
1674da6c28aaSamw static int
1675da6c28aaSamw smbadm_setprop_restore(char *gname, smbadm_prop_t *prop)
1676da6c28aaSamw {
1677da6c28aaSamw 	return (smbadm_group_setpriv(gname, SE_RESTORE_LUID, prop));
1678da6c28aaSamw }
1679da6c28aaSamw 
1680da6c28aaSamw static int
1681da6c28aaSamw smbadm_getprop_restore(char *gname, smbadm_prop_t *prop)
1682da6c28aaSamw {
1683da6c28aaSamw 	return (smbadm_group_getpriv(gname, SE_RESTORE_LUID, prop));
1684da6c28aaSamw }
1685da6c28aaSamw 
1686da6c28aaSamw static boolean_t
1687da6c28aaSamw smbadm_chkprop_priv(smbadm_prop_t *prop)
1688da6c28aaSamw {
1689da6c28aaSamw 	if (prop->p_value == NULL || *prop->p_value == '\0') {
1690da6c28aaSamw 		(void) fprintf(stderr,
1691da6c28aaSamw 		    gettext("missing value for '%s'\n"), prop->p_name);
1692da6c28aaSamw 		return (B_FALSE);
1693da6c28aaSamw 	}
1694da6c28aaSamw 
1695da6c28aaSamw 	if (strcasecmp(prop->p_value, "on") == 0)
1696da6c28aaSamw 		return (B_TRUE);
1697da6c28aaSamw 
1698da6c28aaSamw 	if (strcasecmp(prop->p_value, "off") == 0)
1699da6c28aaSamw 		return (B_TRUE);
1700da6c28aaSamw 
1701da6c28aaSamw 	(void) fprintf(stderr,
1702da6c28aaSamw 	    gettext("%s: unrecognized value for '%s' property\n"),
1703da6c28aaSamw 	    prop->p_value, prop->p_name);
1704da6c28aaSamw 
1705da6c28aaSamw 	return (B_FALSE);
1706da6c28aaSamw }
1707da6c28aaSamw 
1708da6c28aaSamw static const char *
1709da6c28aaSamw smbadm_pwd_strerror(int error)
1710da6c28aaSamw {
1711da6c28aaSamw 	switch (error) {
1712da6c28aaSamw 	case SMB_PWE_SUCCESS:
1713da6c28aaSamw 		return (gettext("Success."));
1714da6c28aaSamw 
1715da6c28aaSamw 	case SMB_PWE_USER_UNKNOWN:
1716da6c28aaSamw 		return (gettext("User does not exist."));
1717da6c28aaSamw 
1718da6c28aaSamw 	case SMB_PWE_USER_DISABLE:
17198d7e4166Sjose borrego 		return (gettext("User is disabled."));
1720da6c28aaSamw 
1721da6c28aaSamw 	case SMB_PWE_CLOSE_FAILED:
1722da6c28aaSamw 	case SMB_PWE_OPEN_FAILED:
1723da6c28aaSamw 	case SMB_PWE_WRITE_FAILED:
1724da6c28aaSamw 	case SMB_PWE_UPDATE_FAILED:
1725da6c28aaSamw 		return (gettext("Unexpected failure. "
1726da6c28aaSamw 		    "SMB password database unchanged."));
1727da6c28aaSamw 
1728da6c28aaSamw 	case SMB_PWE_STAT_FAILED:
1729da6c28aaSamw 		return (gettext("stat of SMB password file failed."));
1730da6c28aaSamw 
1731da6c28aaSamw 	case SMB_PWE_BUSY:
1732da6c28aaSamw 		return (gettext("SMB password database busy. "
1733da6c28aaSamw 		    "Try again later."));
1734da6c28aaSamw 
1735da6c28aaSamw 	case SMB_PWE_DENIED:
1736da6c28aaSamw 		return (gettext("Operation not permitted."));
1737da6c28aaSamw 
1738da6c28aaSamw 	case SMB_PWE_SYSTEM_ERROR:
1739da6c28aaSamw 		return (gettext("System error."));
17403db3f65cSamw 
17413db3f65cSamw 	default:
17423db3f65cSamw 		break;
1743da6c28aaSamw 	}
1744da6c28aaSamw 
1745da6c28aaSamw 	return (gettext("Unknown error code."));
1746da6c28aaSamw }
1747da6c28aaSamw 
1748da6c28aaSamw /*
1749da6c28aaSamw  * Enable libumem debugging by default on DEBUG builds.
1750da6c28aaSamw  */
1751da6c28aaSamw #ifdef DEBUG
1752da6c28aaSamw const char *
1753da6c28aaSamw _umem_debug_init(void)
1754da6c28aaSamw {
1755da6c28aaSamw 	return ("default,verbose"); /* $UMEM_DEBUG setting */
1756da6c28aaSamw }
1757da6c28aaSamw 
1758da6c28aaSamw const char *
1759da6c28aaSamw _umem_logging_init(void)
1760da6c28aaSamw {
1761da6c28aaSamw 	return ("fail,contents"); /* $UMEM_LOGGING setting */
1762da6c28aaSamw }
1763da6c28aaSamw #endif
1764