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 /*
22148c5f43SAlan Wright * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23*b819cea2SGordon Ross * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
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>
3496a62adaSjoyce 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>
4296a62adaSjoyce mcintosh #include <pwd.h>
43da6c28aaSamw #include <grp.h>
44da6c28aaSamw #include <libgen.h>
45c8ec8eeaSjose borrego #include <netinet/in.h>
4696a62adaSjoyce mcintosh #include <auth_attr.h>
4796a62adaSjoyce mcintosh #include <locale.h>
48da6c28aaSamw #include <smbsrv/libsmb.h>
49da6c28aaSamw
5096a62adaSjoyce mcintosh #if !defined(TEXT_DOMAIN)
5196a62adaSjoyce mcintosh #define TEXT_DOMAIN "SYS_TEST"
5296a62adaSjoyce mcintosh #endif
5396a62adaSjoyce 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,
6236a00406SGordon Ross HELP_LOOKUP,
63da6c28aaSamw HELP_RENAME,
64da6c28aaSamw HELP_SET,
65da6c28aaSamw HELP_SHOW,
663db3f65cSamw HELP_USER_DISABLE,
673db3f65cSamw HELP_USER_ENABLE
68da6c28aaSamw } smbadm_help_t;
69da6c28aaSamw
7096a62adaSjoyce mcintosh #define SMBADM_CMDF_NONE 0x00
713db3f65cSamw #define SMBADM_CMDF_USER 0x01
723db3f65cSamw #define SMBADM_CMDF_GROUP 0x02
733db3f65cSamw #define SMBADM_CMDF_TYPEMASK 0x0F
74faa1795aSjb150015
7536a00406SGordon Ross typedef enum {
7636a00406SGordon Ross SMBADM_GRP_ADDMEMBER = 0,
7736a00406SGordon Ross SMBADM_GRP_DELMEMBER,
7836a00406SGordon Ross } smbadm_grp_action_t;
7936a00406SGordon Ross
80c8ec8eeaSjose borrego #define SMBADM_ANSBUFSIZ 64
81c8ec8eeaSjose borrego
82da6c28aaSamw typedef struct smbadm_cmdinfo {
83da6c28aaSamw char *name;
84da6c28aaSamw int (*func)(int, char **);
85da6c28aaSamw smbadm_help_t usage;
86faa1795aSjb150015 uint32_t flags;
8796a62adaSjoyce mcintosh char *auth;
88da6c28aaSamw } smbadm_cmdinfo_t;
89da6c28aaSamw
90da6c28aaSamw smbadm_cmdinfo_t *curcmd;
91da6c28aaSamw static char *progname;
92da6c28aaSamw
9396a62adaSjoyce mcintosh #define SMBADM_ACTION_AUTH "solaris.smf.manage.smb"
9496a62adaSjoyce mcintosh #define SMBADM_VALUE_AUTH "solaris.smf.value.smb"
9596a62adaSjoyce mcintosh #define SMBADM_BASIC_AUTH "solaris.network.hosts.read"
9696a62adaSjoyce mcintosh
9796a62adaSjoyce mcintosh static boolean_t smbadm_checkauth(const char *);
9896a62adaSjoyce mcintosh
998d7e4166Sjose borrego static void smbadm_usage(boolean_t);
1008d7e4166Sjose borrego static int smbadm_join_workgroup(const char *);
1018d7e4166Sjose borrego static int smbadm_join_domain(const char *, const char *);
1028d7e4166Sjose borrego static void smbadm_extract_domain(char *, char **, char **);
1038d7e4166Sjose borrego
104da6c28aaSamw static int smbadm_join(int, char **);
105da6c28aaSamw static int smbadm_list(int, char **);
10636a00406SGordon Ross static int smbadm_lookup(int, char **);
10736a00406SGordon Ross static void smbadm_lookup_name(char *);
10836a00406SGordon Ross static void smbadm_lookup_sid(char *);
109da6c28aaSamw static int smbadm_group_create(int, char **);
110da6c28aaSamw static int smbadm_group_delete(int, char **);
111da6c28aaSamw static int smbadm_group_rename(int, char **);
112da6c28aaSamw static int smbadm_group_show(int, char **);
113fe1c642dSBill Krier static void smbadm_group_show_name(const char *, const char *);
114da6c28aaSamw static int smbadm_group_getprop(int, char **);
115da6c28aaSamw static int smbadm_group_setprop(int, char **);
116da6c28aaSamw static int smbadm_group_addmember(int, char **);
117da6c28aaSamw static int smbadm_group_delmember(int, char **);
11836a00406SGordon Ross static int smbadm_group_add_del_member(char *, char *, smbadm_grp_action_t);
11936a00406SGordon Ross
120da6c28aaSamw static int smbadm_user_disable(int, char **);
121da6c28aaSamw static int smbadm_user_enable(int, char **);
122da6c28aaSamw
123da6c28aaSamw static smbadm_cmdinfo_t smbadm_cmdtable[] =
124da6c28aaSamw {
125faa1795aSjb150015 { "add-member", smbadm_group_addmember, HELP_ADD_MEMBER,
12696a62adaSjoyce mcintosh SMBADM_CMDF_GROUP, SMBADM_ACTION_AUTH },
127faa1795aSjb150015 { "create", smbadm_group_create, HELP_CREATE,
12896a62adaSjoyce mcintosh SMBADM_CMDF_GROUP, SMBADM_ACTION_AUTH },
129faa1795aSjb150015 { "delete", smbadm_group_delete, HELP_DELETE,
13096a62adaSjoyce mcintosh SMBADM_CMDF_GROUP, SMBADM_ACTION_AUTH },
1313db3f65cSamw { "disable-user", smbadm_user_disable, HELP_USER_DISABLE,
13296a62adaSjoyce mcintosh SMBADM_CMDF_USER, SMBADM_ACTION_AUTH },
1333db3f65cSamw { "enable-user", smbadm_user_enable, HELP_USER_ENABLE,
13496a62adaSjoyce mcintosh SMBADM_CMDF_USER, SMBADM_ACTION_AUTH },
135faa1795aSjb150015 { "get", smbadm_group_getprop, HELP_GET,
13696a62adaSjoyce mcintosh SMBADM_CMDF_GROUP, SMBADM_ACTION_AUTH },
13796a62adaSjoyce mcintosh { "join", smbadm_join, HELP_JOIN,
13896a62adaSjoyce mcintosh SMBADM_CMDF_NONE, SMBADM_VALUE_AUTH },
13996a62adaSjoyce mcintosh { "list", smbadm_list, HELP_LIST,
14096a62adaSjoyce mcintosh SMBADM_CMDF_NONE, SMBADM_BASIC_AUTH },
14136a00406SGordon Ross { "lookup", smbadm_lookup, HELP_LOOKUP,
14236a00406SGordon Ross SMBADM_CMDF_NONE, SMBADM_BASIC_AUTH },
143faa1795aSjb150015 { "remove-member", smbadm_group_delmember, HELP_DEL_MEMBER,
14496a62adaSjoyce mcintosh SMBADM_CMDF_GROUP, SMBADM_ACTION_AUTH },
145faa1795aSjb150015 { "rename", smbadm_group_rename, HELP_RENAME,
14696a62adaSjoyce mcintosh SMBADM_CMDF_GROUP, SMBADM_ACTION_AUTH },
147faa1795aSjb150015 { "set", smbadm_group_setprop, HELP_SET,
14896a62adaSjoyce mcintosh SMBADM_CMDF_GROUP, SMBADM_ACTION_AUTH },
149faa1795aSjb150015 { "show", smbadm_group_show, HELP_SHOW,
15096a62adaSjoyce mcintosh SMBADM_CMDF_GROUP, SMBADM_ACTION_AUTH },
151da6c28aaSamw };
152da6c28aaSamw
153da6c28aaSamw #define SMBADM_NCMD (sizeof (smbadm_cmdtable) / sizeof (smbadm_cmdtable[0]))
154da6c28aaSamw
155da6c28aaSamw typedef struct smbadm_prop {
156da6c28aaSamw char *p_name;
157da6c28aaSamw char *p_value;
158da6c28aaSamw } smbadm_prop_t;
159da6c28aaSamw
160da6c28aaSamw typedef struct smbadm_prop_handle {
161da6c28aaSamw char *p_name;
162da6c28aaSamw char *p_dispvalue;
163da6c28aaSamw int (*p_setfn)(char *, smbadm_prop_t *);
164da6c28aaSamw int (*p_getfn)(char *, smbadm_prop_t *);
165da6c28aaSamw boolean_t (*p_chkfn)(smbadm_prop_t *);
166da6c28aaSamw } smbadm_prop_handle_t;
167da6c28aaSamw
168da6c28aaSamw static boolean_t smbadm_prop_validate(smbadm_prop_t *prop, boolean_t chkval);
169da6c28aaSamw static int smbadm_prop_parse(char *arg, smbadm_prop_t *prop);
170da6c28aaSamw static smbadm_prop_handle_t *smbadm_prop_gethandle(char *pname);
171da6c28aaSamw
172da6c28aaSamw static boolean_t smbadm_chkprop_priv(smbadm_prop_t *prop);
173da6c28aaSamw static int smbadm_setprop_tkowner(char *gname, smbadm_prop_t *prop);
174da6c28aaSamw static int smbadm_getprop_tkowner(char *gname, smbadm_prop_t *prop);
175da6c28aaSamw static int smbadm_setprop_backup(char *gname, smbadm_prop_t *prop);
176da6c28aaSamw static int smbadm_getprop_backup(char *gname, smbadm_prop_t *prop);
177da6c28aaSamw static int smbadm_setprop_restore(char *gname, smbadm_prop_t *prop);
178da6c28aaSamw static int smbadm_getprop_restore(char *gname, smbadm_prop_t *prop);
179da6c28aaSamw static int smbadm_setprop_desc(char *gname, smbadm_prop_t *prop);
180da6c28aaSamw static int smbadm_getprop_desc(char *gname, smbadm_prop_t *prop);
181da6c28aaSamw
182da6c28aaSamw static smbadm_prop_handle_t smbadm_ptable[] = {
183da6c28aaSamw {"backup", "on | off", smbadm_setprop_backup,
184da6c28aaSamw smbadm_getprop_backup, smbadm_chkprop_priv },
185da6c28aaSamw {"restore", "on | off", smbadm_setprop_restore,
186da6c28aaSamw smbadm_getprop_restore, smbadm_chkprop_priv },
187da6c28aaSamw {"take-ownership", "on | off", smbadm_setprop_tkowner,
188da6c28aaSamw smbadm_getprop_tkowner, smbadm_chkprop_priv },
189da6c28aaSamw {"description", "<string>", smbadm_setprop_desc,
190da6c28aaSamw smbadm_getprop_desc, NULL },
191da6c28aaSamw };
192da6c28aaSamw
1933db3f65cSamw static int smbadm_init(void);
1943db3f65cSamw static void smbadm_fini(void);
195da6c28aaSamw static const char *smbadm_pwd_strerror(int error);
196da6c28aaSamw
197da6c28aaSamw /*
198da6c28aaSamw * Number of supported properties
199da6c28aaSamw */
200da6c28aaSamw #define SMBADM_NPROP (sizeof (smbadm_ptable) / sizeof (smbadm_ptable[0]))
201da6c28aaSamw
202da6c28aaSamw static void
smbadm_cmdusage(FILE * fp,smbadm_cmdinfo_t * cmd)203da6c28aaSamw smbadm_cmdusage(FILE *fp, smbadm_cmdinfo_t *cmd)
204da6c28aaSamw {
205da6c28aaSamw switch (cmd->usage) {
206da6c28aaSamw case HELP_ADD_MEMBER:
207da6c28aaSamw (void) fprintf(fp,
208da6c28aaSamw gettext("\t%s -m member [[-m member] ...] group\n"),
209da6c28aaSamw cmd->name);
210da6c28aaSamw return;
211da6c28aaSamw
212da6c28aaSamw case HELP_CREATE:
213da6c28aaSamw (void) fprintf(fp, gettext("\t%s [-d description] group\n"),
214da6c28aaSamw cmd->name);
215da6c28aaSamw return;
216da6c28aaSamw
217da6c28aaSamw case HELP_DELETE:
218da6c28aaSamw (void) fprintf(fp, gettext("\t%s group\n"), cmd->name);
219da6c28aaSamw return;
220da6c28aaSamw
2213db3f65cSamw case HELP_USER_DISABLE:
2223db3f65cSamw case HELP_USER_ENABLE:
223da6c28aaSamw (void) fprintf(fp, gettext("\t%s user\n"), cmd->name);
224da6c28aaSamw return;
225da6c28aaSamw
226da6c28aaSamw case HELP_GET:
227da6c28aaSamw (void) fprintf(fp, gettext("\t%s [[-p property] ...] group\n"),
228da6c28aaSamw cmd->name);
229da6c28aaSamw return;
230da6c28aaSamw
231da6c28aaSamw case HELP_JOIN:
2321ed6b69aSGordon Ross #if 0 /* Don't document "-p" yet, still needs work (NX 11960) */
2331ed6b69aSGordon Ross (void) fprintf(fp, gettext("\t%s -p domain\n"
2341ed6b69aSGordon Ross "\t%s -u username domain\n\t%s -w workgroup\n"),
2351ed6b69aSGordon Ross cmd->name, cmd->name, cmd->name);
2361ed6b69aSGordon Ross #else
237da6c28aaSamw (void) fprintf(fp, gettext("\t%s -u username domain\n"
238da6c28aaSamw "\t%s -w workgroup\n"), cmd->name, cmd->name);
2391ed6b69aSGordon Ross #endif
240da6c28aaSamw return;
241da6c28aaSamw
242da6c28aaSamw case HELP_LIST:
243da6c28aaSamw (void) fprintf(fp, gettext("\t%s\n"), cmd->name);
24489dc44ceSjose borrego (void) fprintf(fp,
24589dc44ceSjose borrego gettext("\t\t[*] primary domain\n"));
24689dc44ceSjose borrego (void) fprintf(fp, gettext("\t\t[.] local domain\n"));
24789dc44ceSjose borrego (void) fprintf(fp, gettext("\t\t[-] other domains\n"));
24889dc44ceSjose borrego (void) fprintf(fp,
24989dc44ceSjose borrego gettext("\t\t[+] selected domain controller\n"));
250da6c28aaSamw return;
251da6c28aaSamw
25236a00406SGordon Ross case HELP_LOOKUP:
25336a00406SGordon Ross (void) fprintf(fp,
25436a00406SGordon Ross gettext("\t%s user-or-group-name\n"),
25536a00406SGordon Ross cmd->name);
25636a00406SGordon Ross return;
25736a00406SGordon Ross
258da6c28aaSamw case HELP_DEL_MEMBER:
259da6c28aaSamw (void) fprintf(fp,
260da6c28aaSamw gettext("\t%s -m member [[-m member] ...] group\n"),
261da6c28aaSamw cmd->name);
262da6c28aaSamw return;
263da6c28aaSamw
264da6c28aaSamw case HELP_RENAME:
265da6c28aaSamw (void) fprintf(fp, gettext("\t%s group new-group\n"),
266da6c28aaSamw cmd->name);
267da6c28aaSamw return;
268da6c28aaSamw
269da6c28aaSamw case HELP_SET:
270da6c28aaSamw (void) fprintf(fp, gettext("\t%s -p property=value "
271da6c28aaSamw "[[-p property=value] ...] group\n"), cmd->name);
272da6c28aaSamw return;
273da6c28aaSamw
274da6c28aaSamw case HELP_SHOW:
275da6c28aaSamw (void) fprintf(fp, gettext("\t%s [-m] [-p] [group]\n"),
276da6c28aaSamw cmd->name);
277da6c28aaSamw return;
278da6c28aaSamw
2793db3f65cSamw default:
2803db3f65cSamw break;
281da6c28aaSamw }
282da6c28aaSamw
283da6c28aaSamw abort();
284da6c28aaSamw /* NOTREACHED */
285da6c28aaSamw }
286da6c28aaSamw
287da6c28aaSamw static void
smbadm_usage(boolean_t requested)288da6c28aaSamw smbadm_usage(boolean_t requested)
289da6c28aaSamw {
290da6c28aaSamw FILE *fp = requested ? stdout : stderr;
291da6c28aaSamw boolean_t show_props = B_FALSE;
292da6c28aaSamw int i;
293da6c28aaSamw
294da6c28aaSamw if (curcmd == NULL) {
295da6c28aaSamw (void) fprintf(fp,
296da6c28aaSamw gettext("usage: %s [-h | <command> [options]]\n"),
297da6c28aaSamw progname);
298da6c28aaSamw (void) fprintf(fp,
299da6c28aaSamw gettext("where 'command' is one of the following:\n\n"));
300da6c28aaSamw
301da6c28aaSamw for (i = 0; i < SMBADM_NCMD; i++)
302da6c28aaSamw smbadm_cmdusage(fp, &smbadm_cmdtable[i]);
303da6c28aaSamw
304da6c28aaSamw (void) fprintf(fp,
305da6c28aaSamw gettext("\nFor property list, run %s %s|%s\n"),
306da6c28aaSamw progname, "get", "set");
307da6c28aaSamw
308da6c28aaSamw exit(requested ? 0 : 2);
309da6c28aaSamw }
310da6c28aaSamw
311da6c28aaSamw (void) fprintf(fp, gettext("usage:\n"));
312da6c28aaSamw smbadm_cmdusage(fp, curcmd);
313da6c28aaSamw
314da6c28aaSamw if (strcmp(curcmd->name, "get") == 0 ||
315da6c28aaSamw strcmp(curcmd->name, "set") == 0)
316da6c28aaSamw show_props = B_TRUE;
317da6c28aaSamw
318da6c28aaSamw if (show_props) {
319da6c28aaSamw (void) fprintf(fp,
320da6c28aaSamw gettext("\nThe following properties are supported:\n"));
321da6c28aaSamw
322da6c28aaSamw (void) fprintf(fp, "\n\t%-16s %s\n\n",
323da6c28aaSamw "PROPERTY", "VALUES");
324da6c28aaSamw
325da6c28aaSamw for (i = 0; i < SMBADM_NPROP; i++) {
326da6c28aaSamw (void) fprintf(fp, "\t%-16s %s\n",
327da6c28aaSamw smbadm_ptable[i].p_name,
328da6c28aaSamw smbadm_ptable[i].p_dispvalue);
329da6c28aaSamw }
330da6c28aaSamw }
331da6c28aaSamw
332da6c28aaSamw exit(requested ? 0 : 2);
333da6c28aaSamw }
334da6c28aaSamw
335da6c28aaSamw /*
336c8ec8eeaSjose borrego * smbadm_strcasecmplist
337c8ec8eeaSjose borrego *
338c8ec8eeaSjose borrego * Find a string 's' within a list of strings.
339c8ec8eeaSjose borrego *
340c8ec8eeaSjose borrego * Returns the index of the matching string or -1 if there is no match.
341c8ec8eeaSjose borrego */
342c8ec8eeaSjose borrego static int
smbadm_strcasecmplist(const char * s,...)343c8ec8eeaSjose borrego smbadm_strcasecmplist(const char *s, ...)
344c8ec8eeaSjose borrego {
345c8ec8eeaSjose borrego va_list ap;
346c8ec8eeaSjose borrego char *p;
347c8ec8eeaSjose borrego int ndx;
348c8ec8eeaSjose borrego
349c8ec8eeaSjose borrego va_start(ap, s);
350c8ec8eeaSjose borrego
351c8ec8eeaSjose borrego for (ndx = 0; ((p = va_arg(ap, char *)) != NULL); ++ndx) {
352c8ec8eeaSjose borrego if (strcasecmp(s, p) == 0) {
353c8ec8eeaSjose borrego va_end(ap);
354c8ec8eeaSjose borrego return (ndx);
355c8ec8eeaSjose borrego }
356c8ec8eeaSjose borrego }
357c8ec8eeaSjose borrego
358c8ec8eeaSjose borrego va_end(ap);
359c8ec8eeaSjose borrego return (-1);
360c8ec8eeaSjose borrego }
361c8ec8eeaSjose borrego
362c8ec8eeaSjose borrego /*
363c8ec8eeaSjose borrego * smbadm_answer_prompt
364c8ec8eeaSjose borrego *
365c8ec8eeaSjose borrego * Prompt for the answer to a question. A default response must be
366c8ec8eeaSjose borrego * specified, which will be used if the user presses <enter> without
367c8ec8eeaSjose borrego * answering the question.
368c8ec8eeaSjose borrego */
369c8ec8eeaSjose borrego static int
smbadm_answer_prompt(const char * prompt,char * answer,const char * dflt)370c8ec8eeaSjose borrego smbadm_answer_prompt(const char *prompt, char *answer, const char *dflt)
371c8ec8eeaSjose borrego {
372c8ec8eeaSjose borrego char buf[SMBADM_ANSBUFSIZ];
373c8ec8eeaSjose borrego char *p;
374c8ec8eeaSjose borrego
375c8ec8eeaSjose borrego (void) printf(gettext("%s [%s]: "), prompt, dflt);
376c8ec8eeaSjose borrego
377c8ec8eeaSjose borrego if (fgets(buf, SMBADM_ANSBUFSIZ, stdin) == NULL)
378c8ec8eeaSjose borrego return (-1);
379c8ec8eeaSjose borrego
380c8ec8eeaSjose borrego if ((p = strchr(buf, '\n')) != NULL)
381c8ec8eeaSjose borrego *p = '\0';
382c8ec8eeaSjose borrego
383c8ec8eeaSjose borrego if (*buf == '\0')
384c8ec8eeaSjose borrego (void) strlcpy(answer, dflt, SMBADM_ANSBUFSIZ);
385c8ec8eeaSjose borrego else
386c8ec8eeaSjose borrego (void) strlcpy(answer, buf, SMBADM_ANSBUFSIZ);
387c8ec8eeaSjose borrego
388c8ec8eeaSjose borrego return (0);
389c8ec8eeaSjose borrego }
390c8ec8eeaSjose borrego
391c8ec8eeaSjose borrego /*
392c8ec8eeaSjose borrego * smbadm_confirm
393c8ec8eeaSjose borrego *
394c8ec8eeaSjose borrego * Ask a question that requires a yes/no answer.
395c8ec8eeaSjose borrego * A default response must be specified.
396c8ec8eeaSjose borrego */
397c8ec8eeaSjose borrego static boolean_t
smbadm_confirm(const char * prompt,const char * dflt)398c8ec8eeaSjose borrego smbadm_confirm(const char *prompt, const char *dflt)
399c8ec8eeaSjose borrego {
400c8ec8eeaSjose borrego char buf[SMBADM_ANSBUFSIZ];
401c8ec8eeaSjose borrego
402c8ec8eeaSjose borrego for (;;) {
403c8ec8eeaSjose borrego if (smbadm_answer_prompt(prompt, buf, dflt) < 0)
404c8ec8eeaSjose borrego return (B_FALSE);
405c8ec8eeaSjose borrego
406c8ec8eeaSjose borrego if (smbadm_strcasecmplist(buf, "n", "no", 0) >= 0)
407c8ec8eeaSjose borrego return (B_FALSE);
408c8ec8eeaSjose borrego
409c8ec8eeaSjose borrego if (smbadm_strcasecmplist(buf, "y", "yes", 0) >= 0)
410c8ec8eeaSjose borrego return (B_TRUE);
411c8ec8eeaSjose borrego
412c8ec8eeaSjose borrego (void) printf(gettext("Please answer yes or no.\n"));
413c8ec8eeaSjose borrego }
414c8ec8eeaSjose borrego }
415c8ec8eeaSjose borrego
416c8ec8eeaSjose borrego static boolean_t
smbadm_join_prompt(const char * domain)4178d7e4166Sjose borrego smbadm_join_prompt(const char *domain)
418c8ec8eeaSjose borrego {
4198d7e4166Sjose borrego (void) printf(gettext("After joining %s the smb service will be "
4208d7e4166Sjose borrego "restarted automatically.\n"), domain);
421c8ec8eeaSjose borrego
4228d7e4166Sjose borrego return (smbadm_confirm("Would you like to continue?", "no"));
423c8ec8eeaSjose borrego }
424c8ec8eeaSjose borrego
4258d7e4166Sjose borrego static void
smbadm_restart_service(void)4268d7e4166Sjose borrego smbadm_restart_service(void)
4278d7e4166Sjose borrego {
4288d7e4166Sjose borrego if (smb_smf_restart_service() != 0) {
4298d7e4166Sjose borrego (void) fprintf(stderr,
4308d7e4166Sjose borrego gettext("Unable to restart smb service. "
4318d7e4166Sjose borrego "Run 'svcs -xv smb/server' for more information."));
4328d7e4166Sjose borrego }
433c8ec8eeaSjose borrego }
434c8ec8eeaSjose borrego
435c8ec8eeaSjose borrego /*
436da6c28aaSamw * smbadm_join
437da6c28aaSamw *
4388d7e4166Sjose borrego * Join a domain or workgroup.
4398d7e4166Sjose borrego *
4408d7e4166Sjose borrego * When joining a domain, we may receive the username, password and
4418d7e4166Sjose borrego * domain name in any of the following combinations. Note that the
4428d7e4166Sjose borrego * password is optional on the command line: if it is not provided,
4438d7e4166Sjose borrego * we will prompt for it later.
4448d7e4166Sjose borrego *
4458d7e4166Sjose borrego * username+password domain
4468d7e4166Sjose borrego * domain\username+password
4478d7e4166Sjose borrego * domain/username+password
4488d7e4166Sjose borrego * username@domain
4498d7e4166Sjose borrego *
4508d7e4166Sjose borrego * We allow domain\name+password or domain/name+password but not
4518d7e4166Sjose borrego * name+password@domain because @ is a valid password character.
4528d7e4166Sjose borrego *
4538d7e4166Sjose borrego * If the username and domain name are passed as separate command
4548d7e4166Sjose borrego * line arguments, we process them directly. Otherwise we separate
4558d7e4166Sjose borrego * them and continue as if they were separate command line arguments.
456da6c28aaSamw */
457da6c28aaSamw static int
smbadm_join(int argc,char ** argv)458da6c28aaSamw smbadm_join(int argc, char **argv)
459da6c28aaSamw {
4608d7e4166Sjose borrego char buf[MAXHOSTNAMELEN * 2];
4618d7e4166Sjose borrego char *domain = NULL;
4628d7e4166Sjose borrego char *username = NULL;
4638d7e4166Sjose borrego uint32_t mode = 0;
464da6c28aaSamw char option;
465da6c28aaSamw
4661ed6b69aSGordon Ross while ((option = getopt(argc, argv, "pu:w")) != -1) {
4678d7e4166Sjose borrego if (mode != 0) {
4681ed6b69aSGordon Ross (void) fprintf(stderr, gettext(
4691ed6b69aSGordon Ross "join options are mutually exclusive\n"));
4708d7e4166Sjose borrego smbadm_usage(B_FALSE);
4718d7e4166Sjose borrego }
4721ed6b69aSGordon Ross switch (option) {
4731ed6b69aSGordon Ross case 'p':
4741ed6b69aSGordon Ross mode = SMB_SECMODE_DOMAIN;
4751ed6b69aSGordon Ross /* leave username = NULL */
476da6c28aaSamw break;
477da6c28aaSamw
478da6c28aaSamw case 'u':
4798d7e4166Sjose borrego mode = SMB_SECMODE_DOMAIN;
4808d7e4166Sjose borrego username = optarg;
4811ed6b69aSGordon Ross break;
4828d7e4166Sjose borrego
4831ed6b69aSGordon Ross case 'w':
4841ed6b69aSGordon Ross mode = SMB_SECMODE_WORKGRP;
485da6c28aaSamw break;
486da6c28aaSamw
487da6c28aaSamw default:
488da6c28aaSamw smbadm_usage(B_FALSE);
4898d7e4166Sjose borrego break;
490da6c28aaSamw }
491da6c28aaSamw }
492da6c28aaSamw
4931ed6b69aSGordon Ross if (optind < argc)
4941ed6b69aSGordon Ross domain = argv[optind];
4951ed6b69aSGordon Ross
4961ed6b69aSGordon Ross if (username != NULL && domain == NULL) {
4971ed6b69aSGordon Ross /*
4981ed6b69aSGordon Ross * The domain was not specified as a separate
4991ed6b69aSGordon Ross * argument, check for the combination forms.
5001ed6b69aSGordon Ross */
5011ed6b69aSGordon Ross (void) strlcpy(buf, username, sizeof (buf));
5021ed6b69aSGordon Ross smbadm_extract_domain(buf, &username, &domain);
5031ed6b69aSGordon Ross }
5041ed6b69aSGordon Ross
5058d7e4166Sjose borrego if ((domain == NULL) || (*domain == '\0')) {
506da6c28aaSamw (void) fprintf(stderr, gettext("missing %s name\n"),
5078d7e4166Sjose borrego (mode == SMB_SECMODE_WORKGRP) ? "workgroup" : "domain");
508da6c28aaSamw smbadm_usage(B_FALSE);
509da6c28aaSamw }
510da6c28aaSamw
5111ed6b69aSGordon Ross if (mode == SMB_SECMODE_WORKGRP) {
5128d7e4166Sjose borrego return (smbadm_join_workgroup(domain));
5131ed6b69aSGordon Ross }
5148d7e4166Sjose borrego return (smbadm_join_domain(domain, username));
5158d7e4166Sjose borrego }
5168d7e4166Sjose borrego
5178d7e4166Sjose borrego /*
5188d7e4166Sjose borrego * Workgroups comprise a collection of standalone, independently administered
5198d7e4166Sjose borrego * computers that use a common workgroup name. This is a peer-to-peer model
5208d7e4166Sjose borrego * with no formal membership mechanism.
5218d7e4166Sjose borrego */
5228d7e4166Sjose borrego static int
smbadm_join_workgroup(const char * workgroup)5238d7e4166Sjose borrego smbadm_join_workgroup(const char *workgroup)
5248d7e4166Sjose borrego {
5258d7e4166Sjose borrego smb_joininfo_t jdi;
5268d7e4166Sjose borrego uint32_t status;
5278d7e4166Sjose borrego
5288d7e4166Sjose borrego bzero(&jdi, sizeof (jdi));
5298d7e4166Sjose borrego jdi.mode = SMB_SECMODE_WORKGRP;
5308d7e4166Sjose borrego (void) strlcpy(jdi.domain_name, workgroup, sizeof (jdi.domain_name));
5318d7e4166Sjose borrego (void) strtrim(jdi.domain_name, " \t\n");
5328d7e4166Sjose borrego
533fe1c642dSBill Krier if (smb_name_validate_workgroup(jdi.domain_name) != ERROR_SUCCESS) {
5348d7e4166Sjose borrego (void) fprintf(stderr, gettext("workgroup name is invalid\n"));
535da6c28aaSamw smbadm_usage(B_FALSE);
536da6c28aaSamw }
537da6c28aaSamw
5388d7e4166Sjose borrego if (!smbadm_join_prompt(jdi.domain_name))
539c8ec8eeaSjose borrego return (0);
540c8ec8eeaSjose borrego
5418d7e4166Sjose borrego if ((status = smb_join(&jdi)) != NT_STATUS_SUCCESS) {
5428d7e4166Sjose borrego (void) fprintf(stderr, gettext("failed to join %s: %s\n"),
543da6c28aaSamw jdi.domain_name, xlate_nt_status(status));
544da6c28aaSamw return (1);
545da6c28aaSamw }
546da6c28aaSamw
5478d7e4166Sjose borrego (void) printf(gettext("Successfully joined %s\n"), jdi.domain_name);
5488d7e4166Sjose borrego smbadm_restart_service();
549faa1795aSjb150015 return (0);
550faa1795aSjb150015 }
5518d7e4166Sjose borrego
5528d7e4166Sjose borrego /*
5538d7e4166Sjose borrego * Domains comprise a centrally administered group of computers and accounts
5548d7e4166Sjose borrego * that share a common security and administration policy and database.
5558d7e4166Sjose borrego * Computers must join a domain and become domain members, which requires
5568d7e4166Sjose borrego * an administrator level account name.
5578d7e4166Sjose borrego *
5588d7e4166Sjose borrego * The '+' character is invalid within a username. We allow the password
5598d7e4166Sjose borrego * to be appended to the username using '+' as a scripting convenience.
5608d7e4166Sjose borrego */
5618d7e4166Sjose borrego static int
smbadm_join_domain(const char * domain,const char * username)5628d7e4166Sjose borrego smbadm_join_domain(const char *domain, const char *username)
5638d7e4166Sjose borrego {
5648d7e4166Sjose borrego smb_joininfo_t jdi;
5658d7e4166Sjose borrego uint32_t status;
5668d7e4166Sjose borrego char *prompt;
5678d7e4166Sjose borrego char *p;
5688d7e4166Sjose borrego int len;
5698d7e4166Sjose borrego
5708d7e4166Sjose borrego bzero(&jdi, sizeof (jdi));
5718d7e4166Sjose borrego jdi.mode = SMB_SECMODE_DOMAIN;
5728d7e4166Sjose borrego (void) strlcpy(jdi.domain_name, domain, sizeof (jdi.domain_name));
5738d7e4166Sjose borrego (void) strtrim(jdi.domain_name, " \t\n");
5748d7e4166Sjose borrego
575fe1c642dSBill Krier if (smb_name_validate_domain(jdi.domain_name) != ERROR_SUCCESS) {
5768d7e4166Sjose borrego (void) fprintf(stderr, gettext("domain name is invalid\n"));
5778d7e4166Sjose borrego smbadm_usage(B_FALSE);
578faa1795aSjb150015 }
579faa1795aSjb150015
5808d7e4166Sjose borrego if (!smbadm_join_prompt(jdi.domain_name))
581c8ec8eeaSjose borrego return (0);
582c8ec8eeaSjose borrego
5831ed6b69aSGordon Ross /*
5841ed6b69aSGordon Ross * Note: username is null for "unsecure join"
5851ed6b69aSGordon Ross * (join using a pre-created computer account)
5861ed6b69aSGordon Ross * No password either.
5871ed6b69aSGordon Ross */
5881ed6b69aSGordon Ross if (username != NULL) {
5898d7e4166Sjose borrego if ((p = strchr(username, '+')) != NULL) {
5908d7e4166Sjose borrego ++p;
5918d7e4166Sjose borrego
5928d7e4166Sjose borrego len = (int)(p - username);
5938d7e4166Sjose borrego if (len > sizeof (jdi.domain_name))
5948d7e4166Sjose borrego len = sizeof (jdi.domain_name);
5958d7e4166Sjose borrego
5968d7e4166Sjose borrego (void) strlcpy(jdi.domain_username, username, len);
5978d7e4166Sjose borrego (void) strlcpy(jdi.domain_passwd, p,
5988d7e4166Sjose borrego sizeof (jdi.domain_passwd));
5998d7e4166Sjose borrego } else {
6008d7e4166Sjose borrego (void) strlcpy(jdi.domain_username, username,
6018d7e4166Sjose borrego sizeof (jdi.domain_username));
6028d7e4166Sjose borrego }
6038d7e4166Sjose borrego
6041ed6b69aSGordon Ross if (smb_name_validate_account(jdi.domain_username)
6051ed6b69aSGordon Ross != ERROR_SUCCESS) {
6068d7e4166Sjose borrego (void) fprintf(stderr,
6078d7e4166Sjose borrego gettext("username contains invalid characters\n"));
6088d7e4166Sjose borrego smbadm_usage(B_FALSE);
6098d7e4166Sjose borrego }
6108d7e4166Sjose borrego
611da6c28aaSamw if (*jdi.domain_passwd == '\0') {
6128d7e4166Sjose borrego prompt = gettext("Enter domain password: ");
6138d7e4166Sjose borrego
6148d7e4166Sjose borrego if ((p = getpassphrase(prompt)) == NULL) {
6151ed6b69aSGordon Ross (void) fprintf(stderr, gettext(
6161ed6b69aSGordon Ross "missing password\n"));
617da6c28aaSamw smbadm_usage(B_FALSE);
618da6c28aaSamw }
619da6c28aaSamw
620da6c28aaSamw (void) strlcpy(jdi.domain_passwd, p,
621da6c28aaSamw sizeof (jdi.domain_passwd));
622da6c28aaSamw }
6231ed6b69aSGordon Ross }
624da6c28aaSamw
6258d7e4166Sjose borrego (void) printf(gettext("Joining %s ... this may take a minute ...\n"),
626da6c28aaSamw jdi.domain_name);
627da6c28aaSamw
628da6c28aaSamw status = smb_join(&jdi);
629da6c28aaSamw
630da6c28aaSamw switch (status) {
631da6c28aaSamw case NT_STATUS_SUCCESS:
6328d7e4166Sjose borrego (void) printf(gettext("Successfully joined %s\n"),
633da6c28aaSamw jdi.domain_name);
6348d7e4166Sjose borrego bzero(&jdi, sizeof (jdi));
6358d7e4166Sjose borrego smbadm_restart_service();
636da6c28aaSamw return (0);
637da6c28aaSamw
638da6c28aaSamw case NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND:
6398d7e4166Sjose borrego (void) fprintf(stderr,
6408d7e4166Sjose borrego gettext("failed to find any domain controllers for %s\n"),
641da6c28aaSamw jdi.domain_name);
6428d7e4166Sjose borrego bzero(&jdi, sizeof (jdi));
6438d7e4166Sjose borrego return (1);
644da6c28aaSamw
6451ed6b69aSGordon Ross case NT_STATUS_BAD_NETWORK_PATH:
6461ed6b69aSGordon Ross (void) fprintf(stderr,
6471ed6b69aSGordon Ross gettext("failed to resolve domain controller name\n"));
6481ed6b69aSGordon Ross bzero(&jdi, sizeof (jdi));
6491ed6b69aSGordon Ross return (1);
6501ed6b69aSGordon Ross
6511ed6b69aSGordon Ross case NT_STATUS_NETWORK_ACCESS_DENIED:
6521ed6b69aSGordon Ross case NT_STATUS_BAD_NETWORK_NAME:
6531ed6b69aSGordon Ross (void) fprintf(stderr,
6541ed6b69aSGordon Ross gettext("failed connecting to domain controller\n"));
6551ed6b69aSGordon Ross bzero(&jdi, sizeof (jdi));
6561ed6b69aSGordon Ross return (1);
6571ed6b69aSGordon Ross
658da6c28aaSamw default:
6598d7e4166Sjose borrego (void) fprintf(stderr, gettext("failed to join %s: %s\n"),
660da6c28aaSamw jdi.domain_name, xlate_nt_status(status));
661fc724630SAlan Wright (void) fprintf(stderr, gettext("Please refer to the system log"
662fc724630SAlan Wright " for more information.\n"));
6638d7e4166Sjose borrego bzero(&jdi, sizeof (jdi));
6648d7e4166Sjose borrego return (1);
6658d7e4166Sjose borrego }
666da6c28aaSamw }
667da6c28aaSamw
6688d7e4166Sjose borrego /*
6698d7e4166Sjose borrego * We want to process the user and domain names as separate strings.
6708d7e4166Sjose borrego * Check for names of the forms below and separate the components as
6718d7e4166Sjose borrego * required.
6728d7e4166Sjose borrego *
6738d7e4166Sjose borrego * name@domain
6748d7e4166Sjose borrego * domain\name
6758d7e4166Sjose borrego * domain/name
6768d7e4166Sjose borrego *
6778d7e4166Sjose borrego * If we encounter any of the forms above in arg, the @, / or \
6788d7e4166Sjose borrego * separator is replaced by \0 and the username and domain pointers
6798d7e4166Sjose borrego * are changed to point to the appropriate components (in arg).
6808d7e4166Sjose borrego *
6818d7e4166Sjose borrego * If none of the separators are encountered, the username and domain
6828d7e4166Sjose borrego * pointers remain unchanged.
6838d7e4166Sjose borrego */
6848d7e4166Sjose borrego static void
smbadm_extract_domain(char * arg,char ** username,char ** domain)6858d7e4166Sjose borrego smbadm_extract_domain(char *arg, char **username, char **domain)
6868d7e4166Sjose borrego {
6878d7e4166Sjose borrego char *p;
6888d7e4166Sjose borrego
6898d7e4166Sjose borrego if ((p = strpbrk(arg, "/\\@")) != NULL) {
6908d7e4166Sjose borrego if (*p == '@') {
6918d7e4166Sjose borrego *p = '\0';
6928d7e4166Sjose borrego ++p;
6938d7e4166Sjose borrego
6948d7e4166Sjose borrego if (strchr(arg, '+') != NULL)
6958d7e4166Sjose borrego return;
6968d7e4166Sjose borrego
6978d7e4166Sjose borrego *domain = p;
6988d7e4166Sjose borrego *username = arg;
6998d7e4166Sjose borrego } else {
7008d7e4166Sjose borrego *p = '\0';
7018d7e4166Sjose borrego ++p;
7028d7e4166Sjose borrego *username = p;
7038d7e4166Sjose borrego *domain = arg;
7048d7e4166Sjose borrego }
7058d7e4166Sjose borrego }
7068d7e4166Sjose borrego }
7078d7e4166Sjose borrego
7088d7e4166Sjose borrego /*
709da6c28aaSamw * smbadm_list
710da6c28aaSamw *
711da6c28aaSamw * Displays current security mode and domain/workgroup name.
712da6c28aaSamw */
713da6c28aaSamw /*ARGSUSED*/
714da6c28aaSamw static int
smbadm_list(int argc,char ** argv)715da6c28aaSamw smbadm_list(int argc, char **argv)
716da6c28aaSamw {
717faa1795aSjb150015 char domain[MAXHOSTNAMELEN];
7188d7e4166Sjose borrego char fqdn[MAXHOSTNAMELEN];
7198d7e4166Sjose borrego char srvname[MAXHOSTNAMELEN];
720faa1795aSjb150015 char modename[16];
721faa1795aSjb150015 int rc;
7227f667e74Sjose borrego smb_inaddr_t srvipaddr;
723c8ec8eeaSjose borrego char ipstr[INET6_ADDRSTRLEN];
724da6c28aaSamw
725faa1795aSjb150015 rc = smb_config_getstr(SMB_CI_SECURITY, modename, sizeof (modename));
726faa1795aSjb150015 if (rc != SMBD_SMF_OK) {
727da6c28aaSamw (void) fprintf(stderr,
72889dc44ceSjose borrego gettext("cannot determine the operational mode\n"));
729da6c28aaSamw return (1);
730da6c28aaSamw }
731da6c28aaSamw
732faa1795aSjb150015 if (smb_getdomainname(domain, sizeof (domain)) != 0) {
733faa1795aSjb150015 (void) fprintf(stderr, gettext("failed to get the %s name\n"),
734faa1795aSjb150015 modename);
735da6c28aaSamw return (1);
736da6c28aaSamw }
73789dc44ceSjose borrego
738c8ec8eeaSjose borrego if (strcmp(modename, "workgroup") == 0) {
73989dc44ceSjose borrego (void) printf(gettext("[*] [%s]\n"), domain);
740c8ec8eeaSjose borrego return (0);
741c8ec8eeaSjose borrego }
74289dc44ceSjose borrego
74389dc44ceSjose borrego (void) printf(gettext("[*] [%s]\n"), domain);
7448d7e4166Sjose borrego if ((smb_getfqdomainname(fqdn, sizeof (fqdn)) == 0) && (*fqdn != '\0'))
74589dc44ceSjose borrego (void) printf(gettext("[*] [%s]\n"), fqdn);
746da6c28aaSamw
7478d7e4166Sjose borrego if ((smb_get_dcinfo(srvname, MAXHOSTNAMELEN, &srvipaddr)
7488d7e4166Sjose borrego == NT_STATUS_SUCCESS) && (*srvname != '\0') &&
7497f667e74Sjose borrego (!smb_inet_iszero(&srvipaddr))) {
7507f667e74Sjose borrego (void) smb_inet_ntop(&srvipaddr, ipstr,
7517f667e74Sjose borrego SMB_IPSTRLEN(srvipaddr.a_family));
75289dc44ceSjose borrego (void) printf(gettext("\t[+%s.%s] [%s]\n"),
75389dc44ceSjose borrego srvname, fqdn, ipstr);
754c8ec8eeaSjose borrego }
75589dc44ceSjose borrego
756a0aa776eSAlan Wright smb_domain_show();
757da6c28aaSamw return (0);
758da6c28aaSamw }
759da6c28aaSamw
760da6c28aaSamw /*
76136a00406SGordon Ross * smbadm_lookup
76236a00406SGordon Ross *
76336a00406SGordon Ross * Lookup the SID for a given account (user or group)
76436a00406SGordon Ross */
76536a00406SGordon Ross static int
smbadm_lookup(int argc,char ** argv)76636a00406SGordon Ross smbadm_lookup(int argc, char **argv)
76736a00406SGordon Ross {
76836a00406SGordon Ross int i;
76936a00406SGordon Ross
77036a00406SGordon Ross if (argc < 2) {
77136a00406SGordon Ross (void) fprintf(stderr, gettext("missing account name\n"));
77236a00406SGordon Ross smbadm_usage(B_FALSE);
77336a00406SGordon Ross }
77436a00406SGordon Ross
77536a00406SGordon Ross for (i = 1; i < argc; i++) {
77636a00406SGordon Ross if (strncmp(argv[i], "S-1-", 4) == 0)
77736a00406SGordon Ross smbadm_lookup_sid(argv[i]);
77836a00406SGordon Ross else
77936a00406SGordon Ross smbadm_lookup_name(argv[i]);
78036a00406SGordon Ross }
78136a00406SGordon Ross return (0);
78236a00406SGordon Ross }
78336a00406SGordon Ross
78436a00406SGordon Ross static void
smbadm_lookup_name(char * name)78536a00406SGordon Ross smbadm_lookup_name(char *name)
78636a00406SGordon Ross {
78736a00406SGordon Ross lsa_account_t acct;
78836a00406SGordon Ross int rc;
78936a00406SGordon Ross
79036a00406SGordon Ross if ((rc = smb_lookup_name(name, SidTypeUnknown, &acct)) != 0) {
79136a00406SGordon Ross (void) fprintf(stderr, gettext(
79236a00406SGordon Ross "\t\t%s: lookup name failed, rc=%d\n"),
79336a00406SGordon Ross name, rc);
79436a00406SGordon Ross return;
79536a00406SGordon Ross }
79636a00406SGordon Ross if (acct.a_status != NT_STATUS_SUCCESS) {
79736a00406SGordon Ross (void) fprintf(stderr, gettext("\t\t%s [%s]\n"),
79836a00406SGordon Ross name, xlate_nt_status(acct.a_status));
79936a00406SGordon Ross return;
80036a00406SGordon Ross }
80136a00406SGordon Ross (void) printf("\t%s\n", acct.a_sid);
80236a00406SGordon Ross }
80336a00406SGordon Ross
80436a00406SGordon Ross static void
smbadm_lookup_sid(char * sidstr)80536a00406SGordon Ross smbadm_lookup_sid(char *sidstr)
80636a00406SGordon Ross {
80736a00406SGordon Ross lsa_account_t acct;
80836a00406SGordon Ross int rc;
80936a00406SGordon Ross
81036a00406SGordon Ross if ((rc = smb_lookup_sid(sidstr, &acct)) != 0) {
81136a00406SGordon Ross (void) fprintf(stderr, gettext(
81236a00406SGordon Ross "\t\t%s: lookup SID failed, rc=%d\n"),
81336a00406SGordon Ross sidstr, rc);
81436a00406SGordon Ross return;
81536a00406SGordon Ross }
81636a00406SGordon Ross if (acct.a_status != NT_STATUS_SUCCESS) {
81736a00406SGordon Ross (void) fprintf(stderr, gettext("\t\t%s [%s]\n"),
81836a00406SGordon Ross sidstr, xlate_nt_status(acct.a_status));
81936a00406SGordon Ross return;
82036a00406SGordon Ross }
82136a00406SGordon Ross (void) printf("\t%s\\%s\n", acct.a_domain, acct.a_name);
82236a00406SGordon Ross }
82336a00406SGordon Ross
82436a00406SGordon Ross /*
825da6c28aaSamw * smbadm_group_create
826da6c28aaSamw *
827da6c28aaSamw * Creates a local SMB group
828da6c28aaSamw */
829da6c28aaSamw static int
smbadm_group_create(int argc,char ** argv)830da6c28aaSamw smbadm_group_create(int argc, char **argv)
831da6c28aaSamw {
832da6c28aaSamw char *gname = NULL;
833da6c28aaSamw char *desc = NULL;
834da6c28aaSamw char option;
835dc20a302Sas200622 int status;
836da6c28aaSamw
837da6c28aaSamw while ((option = getopt(argc, argv, "d:")) != -1) {
838da6c28aaSamw switch (option) {
839da6c28aaSamw case 'd':
840da6c28aaSamw desc = optarg;
841da6c28aaSamw break;
842da6c28aaSamw
843da6c28aaSamw default:
844da6c28aaSamw smbadm_usage(B_FALSE);
845da6c28aaSamw }
846da6c28aaSamw }
847da6c28aaSamw
848da6c28aaSamw gname = argv[optind];
849da6c28aaSamw if (optind >= argc || gname == NULL || *gname == '\0') {
850da6c28aaSamw (void) fprintf(stderr, gettext("missing group name\n"));
851da6c28aaSamw smbadm_usage(B_FALSE);
852da6c28aaSamw }
853da6c28aaSamw
854dc20a302Sas200622 status = smb_lgrp_add(gname, desc);
855dc20a302Sas200622 if (status != SMB_LGRP_SUCCESS) {
856da6c28aaSamw (void) fprintf(stderr,
85796a62adaSjoyce mcintosh gettext("failed to create %s (%s)\n"), gname,
858dc20a302Sas200622 smb_lgrp_strerror(status));
859da6c28aaSamw } else {
86096a62adaSjoyce mcintosh (void) printf(gettext("%s created\n"), gname);
861da6c28aaSamw }
862da6c28aaSamw
863da6c28aaSamw return (status);
864da6c28aaSamw }
865da6c28aaSamw
866da6c28aaSamw /*
867da6c28aaSamw * smbadm_group_dump_members
868da6c28aaSamw *
869da6c28aaSamw * Dump group members details.
870da6c28aaSamw */
871da6c28aaSamw static void
smbadm_group_dump_members(smb_gsid_t * members,int num)872dc20a302Sas200622 smbadm_group_dump_members(smb_gsid_t *members, int num)
873da6c28aaSamw {
8746537f381Sas200622 char sidstr[SMB_SID_STRSZ];
875fe1c642dSBill Krier lsa_account_t acct;
876da6c28aaSamw int i;
877da6c28aaSamw
878dc20a302Sas200622 if (num == 0) {
879da6c28aaSamw (void) printf(gettext("\tNo members\n"));
880da6c28aaSamw return;
881da6c28aaSamw }
882da6c28aaSamw
883da6c28aaSamw (void) printf(gettext("\tMembers:\n"));
884dc20a302Sas200622 for (i = 0; i < num; i++) {
885fe1c642dSBill Krier smb_sid_tostr(members[i].gs_sid, sidstr);
886fe1c642dSBill Krier
887fe1c642dSBill Krier if (smb_lookup_sid(sidstr, &acct) == 0) {
888fe1c642dSBill Krier if (acct.a_status == NT_STATUS_SUCCESS)
889fe1c642dSBill Krier smbadm_group_show_name(acct.a_domain,
890fe1c642dSBill Krier acct.a_name);
8918c10a865Sas200622 else
892fe1c642dSBill Krier (void) printf(gettext("\t\t%s [%s]\n"),
893fe1c642dSBill Krier sidstr, xlate_nt_status(acct.a_status));
894fe1c642dSBill Krier } else {
895fe1c642dSBill Krier (void) printf(gettext("\t\t%s\n"), sidstr);
896da6c28aaSamw }
897da6c28aaSamw }
898fe1c642dSBill Krier }
899fe1c642dSBill Krier
900fe1c642dSBill Krier static void
smbadm_group_show_name(const char * domain,const char * name)901fe1c642dSBill Krier smbadm_group_show_name(const char *domain, const char *name)
902fe1c642dSBill Krier {
903fe1c642dSBill Krier if (strchr(domain, '.') != NULL)
90436a00406SGordon Ross (void) printf("\t\t%s@%s\n", name, domain);
905fe1c642dSBill Krier else
90636a00406SGordon Ross (void) printf("\t\t%s\\%s\n", domain, name);
907fe1c642dSBill Krier }
908da6c28aaSamw
909da6c28aaSamw /*
910da6c28aaSamw * smbadm_group_dump_privs
911da6c28aaSamw *
912da6c28aaSamw * Dump group privilege details.
913da6c28aaSamw */
914da6c28aaSamw static void
smbadm_group_dump_privs(smb_privset_t * privs)915dc20a302Sas200622 smbadm_group_dump_privs(smb_privset_t *privs)
916da6c28aaSamw {
917dc20a302Sas200622 smb_privinfo_t *pinfo;
918dc20a302Sas200622 char *pstatus;
919da6c28aaSamw int i;
920da6c28aaSamw
921da6c28aaSamw (void) printf(gettext("\tPrivileges: \n"));
922da6c28aaSamw
923dc20a302Sas200622 for (i = 0; i < privs->priv_cnt; i++) {
924dc20a302Sas200622 pinfo = smb_priv_getbyvalue(privs->priv[i].luid.lo_part);
925dc20a302Sas200622 if ((pinfo == NULL) || (pinfo->flags & PF_PRESENTABLE) == 0)
926da6c28aaSamw continue;
927da6c28aaSamw
928dc20a302Sas200622 switch (privs->priv[i].attrs) {
929dc20a302Sas200622 case SE_PRIVILEGE_ENABLED:
930dc20a302Sas200622 pstatus = "On";
931dc20a302Sas200622 break;
932dc20a302Sas200622 case SE_PRIVILEGE_DISABLED:
933dc20a302Sas200622 pstatus = "Off";
934dc20a302Sas200622 break;
935dc20a302Sas200622 default:
936dc20a302Sas200622 pstatus = "Unknown";
937dc20a302Sas200622 break;
938dc20a302Sas200622 }
939dc20a302Sas200622 (void) printf(gettext("\t\t%s: %s\n"), pinfo->name, pstatus);
940da6c28aaSamw }
941da6c28aaSamw
942dc20a302Sas200622 if (privs->priv_cnt == 0)
943da6c28aaSamw (void) printf(gettext("\t\tNo privileges\n"));
944da6c28aaSamw }
945da6c28aaSamw
946da6c28aaSamw /*
947da6c28aaSamw * smbadm_group_dump
948da6c28aaSamw *
949da6c28aaSamw * Dump group details.
950da6c28aaSamw */
951dc20a302Sas200622 static void
smbadm_group_dump(smb_group_t * grp,boolean_t show_mem,boolean_t show_privs)952dc20a302Sas200622 smbadm_group_dump(smb_group_t *grp, boolean_t show_mem, boolean_t show_privs)
953da6c28aaSamw {
9546537f381Sas200622 char sidstr[SMB_SID_STRSZ];
955da6c28aaSamw
956dc20a302Sas200622 (void) printf(gettext("%s (%s)\n"), grp->sg_name, grp->sg_cmnt);
957da6c28aaSamw
9586537f381Sas200622 smb_sid_tostr(grp->sg_id.gs_sid, sidstr);
959dc20a302Sas200622 (void) printf(gettext("\tSID: %s\n"), sidstr);
960da6c28aaSamw
961da6c28aaSamw if (show_privs)
962dc20a302Sas200622 smbadm_group_dump_privs(grp->sg_privs);
963da6c28aaSamw
964da6c28aaSamw if (show_mem)
965dc20a302Sas200622 smbadm_group_dump_members(grp->sg_members, grp->sg_nmembers);
966da6c28aaSamw }
967da6c28aaSamw
968da6c28aaSamw /*
969da6c28aaSamw * smbadm_group_show
970da6c28aaSamw *
971da6c28aaSamw */
972da6c28aaSamw static int
smbadm_group_show(int argc,char ** argv)973da6c28aaSamw smbadm_group_show(int argc, char **argv)
974da6c28aaSamw {
975da6c28aaSamw char *gname = NULL;
976da6c28aaSamw boolean_t show_privs;
977da6c28aaSamw boolean_t show_members;
978da6c28aaSamw char option;
979dc20a302Sas200622 int status;
980dc20a302Sas200622 smb_group_t grp;
981dc20a302Sas200622 smb_giter_t gi;
982da6c28aaSamw
983da6c28aaSamw show_privs = show_members = B_FALSE;
984da6c28aaSamw
985da6c28aaSamw while ((option = getopt(argc, argv, "mp")) != -1) {
986da6c28aaSamw switch (option) {
987da6c28aaSamw case 'm':
988da6c28aaSamw show_members = B_TRUE;
989da6c28aaSamw break;
990da6c28aaSamw case 'p':
991da6c28aaSamw show_privs = B_TRUE;
992da6c28aaSamw break;
993da6c28aaSamw
994da6c28aaSamw default:
995da6c28aaSamw smbadm_usage(B_FALSE);
996da6c28aaSamw }
997da6c28aaSamw }
998da6c28aaSamw
999da6c28aaSamw gname = argv[optind];
1000da6c28aaSamw if (optind >= argc || gname == NULL || *gname == '\0')
1001da6c28aaSamw gname = "*";
1002da6c28aaSamw
1003dc20a302Sas200622 if (strcmp(gname, "*")) {
1004dc20a302Sas200622 status = smb_lgrp_getbyname(gname, &grp);
1005dc20a302Sas200622 if (status == SMB_LGRP_SUCCESS) {
1006dc20a302Sas200622 smbadm_group_dump(&grp, show_members, show_privs);
1007dc20a302Sas200622 smb_lgrp_free(&grp);
1008dc20a302Sas200622 } else {
1009da6c28aaSamw (void) fprintf(stderr,
10108d7e4166Sjose borrego gettext("failed to find %s (%s)\n"),
1011dc20a302Sas200622 gname, smb_lgrp_strerror(status));
1012dc20a302Sas200622 }
1013dc20a302Sas200622 return (status);
1014da6c28aaSamw }
1015da6c28aaSamw
10166537f381Sas200622 if ((status = smb_lgrp_iteropen(&gi)) != SMB_LGRP_SUCCESS) {
10178d7e4166Sjose borrego (void) fprintf(stderr, gettext("failed to list groups (%s)\n"),
1018dc20a302Sas200622 smb_lgrp_strerror(status));
1019dc20a302Sas200622 return (status);
1020da6c28aaSamw }
1021da6c28aaSamw
10226537f381Sas200622 while ((status = smb_lgrp_iterate(&gi, &grp)) == SMB_LGRP_SUCCESS) {
1023dc20a302Sas200622 smbadm_group_dump(&grp, show_members, show_privs);
1024dc20a302Sas200622 smb_lgrp_free(&grp);
1025da6c28aaSamw }
10266537f381Sas200622
1027dc20a302Sas200622 smb_lgrp_iterclose(&gi);
1028da6c28aaSamw
10299fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if ((status != SMB_LGRP_NO_MORE) || smb_lgrp_itererror(&gi)) {
10309fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States if (status != SMB_LGRP_NO_MORE)
1031*b819cea2SGordon Ross smb_syslog(LOG_ERR, "smb_lgrp_iterate: %s",
10326537f381Sas200622 smb_lgrp_strerror(status));
10339fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States
10349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (void) fprintf(stderr,
10359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States gettext("\nAn error occurred while retrieving group data.\n"
10369fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States "Check the system log for more information.\n"));
10376537f381Sas200622 return (status);
10386537f381Sas200622 }
10396537f381Sas200622
1040dc20a302Sas200622 return (0);
1041da6c28aaSamw }
1042da6c28aaSamw
1043da6c28aaSamw /*
1044da6c28aaSamw * smbadm_group_delete
1045da6c28aaSamw */
1046da6c28aaSamw static int
smbadm_group_delete(int argc,char ** argv)1047da6c28aaSamw smbadm_group_delete(int argc, char **argv)
1048da6c28aaSamw {
1049da6c28aaSamw char *gname = NULL;
1050dc20a302Sas200622 int status;
1051da6c28aaSamw
1052da6c28aaSamw gname = argv[optind];
1053da6c28aaSamw if (optind >= argc || gname == NULL || *gname == '\0') {
1054da6c28aaSamw (void) fprintf(stderr, gettext("missing group name\n"));
1055da6c28aaSamw smbadm_usage(B_FALSE);
1056da6c28aaSamw }
1057da6c28aaSamw
1058dc20a302Sas200622 status = smb_lgrp_delete(gname);
1059dc20a302Sas200622 if (status != SMB_LGRP_SUCCESS) {
1060da6c28aaSamw (void) fprintf(stderr,
10618d7e4166Sjose borrego gettext("failed to delete %s (%s)\n"), gname,
1062dc20a302Sas200622 smb_lgrp_strerror(status));
1063da6c28aaSamw } else {
106496a62adaSjoyce mcintosh (void) printf(gettext("%s deleted\n"), gname);
1065da6c28aaSamw }
1066da6c28aaSamw
1067da6c28aaSamw return (status);
1068da6c28aaSamw }
1069da6c28aaSamw
1070da6c28aaSamw /*
1071da6c28aaSamw * smbadm_group_rename
1072da6c28aaSamw */
1073da6c28aaSamw static int
smbadm_group_rename(int argc,char ** argv)1074da6c28aaSamw smbadm_group_rename(int argc, char **argv)
1075da6c28aaSamw {
1076da6c28aaSamw char *gname = NULL;
1077da6c28aaSamw char *ngname = NULL;
1078dc20a302Sas200622 int status;
1079da6c28aaSamw
1080da6c28aaSamw gname = argv[optind];
1081da6c28aaSamw if (optind++ >= argc || gname == NULL || *gname == '\0') {
1082da6c28aaSamw (void) fprintf(stderr, gettext("missing group name\n"));
1083da6c28aaSamw smbadm_usage(B_FALSE);
1084da6c28aaSamw }
1085da6c28aaSamw
1086da6c28aaSamw ngname = argv[optind];
1087da6c28aaSamw if (optind >= argc || ngname == NULL || *ngname == '\0') {
1088da6c28aaSamw (void) fprintf(stderr, gettext("missing new group name\n"));
1089da6c28aaSamw smbadm_usage(B_FALSE);
1090da6c28aaSamw }
1091da6c28aaSamw
1092dc20a302Sas200622 status = smb_lgrp_rename(gname, ngname);
1093dc20a302Sas200622 if (status != SMB_LGRP_SUCCESS) {
1094dc20a302Sas200622 if (status == SMB_LGRP_EXISTS)
1095da6c28aaSamw (void) fprintf(stderr,
1096dc20a302Sas200622 gettext("failed to rename '%s' (%s already "
1097dc20a302Sas200622 "exists)\n"), gname, ngname);
1098dc20a302Sas200622 else
1099dc20a302Sas200622 (void) fprintf(stderr,
1100dc20a302Sas200622 gettext("failed to rename '%s' (%s)\n"), gname,
1101dc20a302Sas200622 smb_lgrp_strerror(status));
1102da6c28aaSamw } else {
1103dc20a302Sas200622 (void) printf(gettext("'%s' renamed to '%s'\n"), gname, ngname);
1104da6c28aaSamw }
1105da6c28aaSamw
1106da6c28aaSamw return (status);
1107da6c28aaSamw }
1108da6c28aaSamw
1109da6c28aaSamw /*
1110da6c28aaSamw * smbadm_group_setprop
1111da6c28aaSamw *
1112da6c28aaSamw * Set the group properties.
1113da6c28aaSamw */
1114da6c28aaSamw static int
smbadm_group_setprop(int argc,char ** argv)1115da6c28aaSamw smbadm_group_setprop(int argc, char **argv)
1116da6c28aaSamw {
1117da6c28aaSamw char *gname = NULL;
1118da6c28aaSamw smbadm_prop_t props[SMBADM_NPROP];
1119da6c28aaSamw smbadm_prop_handle_t *phandle;
1120da6c28aaSamw char option;
1121da6c28aaSamw int pcnt = 0;
1122da6c28aaSamw int ret;
1123da6c28aaSamw int p;
1124da6c28aaSamw
1125da6c28aaSamw bzero(props, SMBADM_NPROP * sizeof (smbadm_prop_t));
1126da6c28aaSamw
1127da6c28aaSamw while ((option = getopt(argc, argv, "p:")) != -1) {
1128da6c28aaSamw switch (option) {
1129da6c28aaSamw case 'p':
1130da6c28aaSamw if (pcnt >= SMBADM_NPROP) {
1131da6c28aaSamw (void) fprintf(stderr,
1132da6c28aaSamw gettext("exceeded number of supported"
1133da6c28aaSamw " properties\n"));
1134da6c28aaSamw smbadm_usage(B_FALSE);
1135da6c28aaSamw }
1136da6c28aaSamw
1137dc20a302Sas200622 if (smbadm_prop_parse(optarg, &props[pcnt++]) != 0)
1138da6c28aaSamw smbadm_usage(B_FALSE);
1139da6c28aaSamw break;
1140da6c28aaSamw
1141da6c28aaSamw default:
1142da6c28aaSamw smbadm_usage(B_FALSE);
1143da6c28aaSamw }
1144da6c28aaSamw }
1145da6c28aaSamw
1146da6c28aaSamw if (pcnt == 0) {
1147da6c28aaSamw (void) fprintf(stderr,
1148da6c28aaSamw gettext("missing property=value argument\n"));
1149da6c28aaSamw smbadm_usage(B_FALSE);
1150da6c28aaSamw }
1151da6c28aaSamw
1152da6c28aaSamw gname = argv[optind];
1153da6c28aaSamw if (optind >= argc || gname == NULL || *gname == '\0') {
1154da6c28aaSamw (void) fprintf(stderr, gettext("missing group name\n"));
1155da6c28aaSamw smbadm_usage(B_FALSE);
1156da6c28aaSamw }
1157da6c28aaSamw
1158da6c28aaSamw for (p = 0; p < pcnt; p++) {
1159da6c28aaSamw phandle = smbadm_prop_gethandle(props[p].p_name);
1160da6c28aaSamw if (phandle) {
1161da6c28aaSamw if (phandle->p_setfn(gname, &props[p]) != 0)
1162da6c28aaSamw ret = 1;
1163da6c28aaSamw }
1164da6c28aaSamw }
1165da6c28aaSamw
1166da6c28aaSamw return (ret);
1167da6c28aaSamw }
1168da6c28aaSamw
1169da6c28aaSamw /*
1170da6c28aaSamw * smbadm_group_getprop
1171da6c28aaSamw *
1172da6c28aaSamw * Get the group properties.
1173da6c28aaSamw */
1174da6c28aaSamw static int
smbadm_group_getprop(int argc,char ** argv)1175da6c28aaSamw smbadm_group_getprop(int argc, char **argv)
1176da6c28aaSamw {
1177da6c28aaSamw char *gname = NULL;
1178da6c28aaSamw smbadm_prop_t props[SMBADM_NPROP];
1179da6c28aaSamw smbadm_prop_handle_t *phandle;
1180da6c28aaSamw char option;
1181da6c28aaSamw int pcnt = 0;
1182da6c28aaSamw int ret;
1183da6c28aaSamw int p;
1184da6c28aaSamw
1185da6c28aaSamw bzero(props, SMBADM_NPROP * sizeof (smbadm_prop_t));
1186da6c28aaSamw
1187da6c28aaSamw while ((option = getopt(argc, argv, "p:")) != -1) {
1188da6c28aaSamw switch (option) {
1189da6c28aaSamw case 'p':
1190da6c28aaSamw if (pcnt >= SMBADM_NPROP) {
1191da6c28aaSamw (void) fprintf(stderr,
1192da6c28aaSamw gettext("exceeded number of supported"
1193da6c28aaSamw " properties\n"));
1194da6c28aaSamw smbadm_usage(B_FALSE);
1195da6c28aaSamw }
1196da6c28aaSamw
1197dc20a302Sas200622 if (smbadm_prop_parse(optarg, &props[pcnt++]) != 0)
1198da6c28aaSamw smbadm_usage(B_FALSE);
1199da6c28aaSamw break;
1200da6c28aaSamw
1201da6c28aaSamw default:
1202da6c28aaSamw smbadm_usage(B_FALSE);
1203da6c28aaSamw }
1204da6c28aaSamw }
1205da6c28aaSamw
1206da6c28aaSamw gname = argv[optind];
1207da6c28aaSamw if (optind >= argc || gname == NULL || *gname == '\0') {
1208da6c28aaSamw (void) fprintf(stderr, gettext("missing group name\n"));
1209da6c28aaSamw smbadm_usage(B_FALSE);
1210da6c28aaSamw }
1211da6c28aaSamw
1212da6c28aaSamw if (pcnt == 0) {
1213da6c28aaSamw /*
1214da6c28aaSamw * If no property has be specified then get
1215da6c28aaSamw * all the properties.
1216da6c28aaSamw */
1217da6c28aaSamw pcnt = SMBADM_NPROP;
1218da6c28aaSamw for (p = 0; p < pcnt; p++)
1219da6c28aaSamw props[p].p_name = smbadm_ptable[p].p_name;
1220da6c28aaSamw }
1221da6c28aaSamw
1222da6c28aaSamw for (p = 0; p < pcnt; p++) {
1223da6c28aaSamw phandle = smbadm_prop_gethandle(props[p].p_name);
1224da6c28aaSamw if (phandle) {
1225da6c28aaSamw if (phandle->p_getfn(gname, &props[p]) != 0)
1226da6c28aaSamw ret = 1;
1227da6c28aaSamw }
1228da6c28aaSamw }
1229da6c28aaSamw
1230da6c28aaSamw return (ret);
1231da6c28aaSamw }
1232da6c28aaSamw
1233da6c28aaSamw /*
1234da6c28aaSamw * smbadm_group_addmember
1235da6c28aaSamw *
1236da6c28aaSamw */
1237da6c28aaSamw static int
smbadm_group_addmember(int argc,char ** argv)1238da6c28aaSamw smbadm_group_addmember(int argc, char **argv)
1239da6c28aaSamw {
1240da6c28aaSamw char *gname = NULL;
1241da6c28aaSamw char **mname;
1242da6c28aaSamw char option;
1243da6c28aaSamw int mcnt = 0;
1244da6c28aaSamw int ret = 0;
1245da6c28aaSamw int i;
1246da6c28aaSamw
1247da6c28aaSamw
1248da6c28aaSamw mname = (char **)malloc(argc * sizeof (char *));
1249da6c28aaSamw if (mname == NULL) {
12508d7e4166Sjose borrego warn(gettext("failed to add group member"));
1251da6c28aaSamw return (1);
1252da6c28aaSamw }
1253da6c28aaSamw bzero(mname, argc * sizeof (char *));
1254da6c28aaSamw
1255da6c28aaSamw while ((option = getopt(argc, argv, "m:")) != -1) {
1256da6c28aaSamw switch (option) {
1257da6c28aaSamw case 'm':
1258da6c28aaSamw mname[mcnt++] = optarg;
1259da6c28aaSamw break;
1260da6c28aaSamw
1261da6c28aaSamw default:
1262da6c28aaSamw free(mname);
1263da6c28aaSamw smbadm_usage(B_FALSE);
1264da6c28aaSamw }
1265da6c28aaSamw }
1266da6c28aaSamw
1267da6c28aaSamw if (mcnt == 0) {
1268da6c28aaSamw (void) fprintf(stderr, gettext("missing member name\n"));
1269da6c28aaSamw free(mname);
1270da6c28aaSamw smbadm_usage(B_FALSE);
1271da6c28aaSamw }
1272da6c28aaSamw
1273da6c28aaSamw gname = argv[optind];
1274da6c28aaSamw if (optind >= argc || gname == NULL || *gname == 0) {
1275da6c28aaSamw (void) fprintf(stderr, gettext("missing group name\n"));
1276da6c28aaSamw free(mname);
1277da6c28aaSamw smbadm_usage(B_FALSE);
1278da6c28aaSamw }
1279da6c28aaSamw
1280da6c28aaSamw for (i = 0; i < mcnt; i++) {
1281da6c28aaSamw if (mname[i] == NULL)
1282da6c28aaSamw continue;
128336a00406SGordon Ross ret |= smbadm_group_add_del_member(
128436a00406SGordon Ross gname, mname[i], SMBADM_GRP_ADDMEMBER);
1285dc20a302Sas200622 }
1286da6c28aaSamw
1287da6c28aaSamw free(mname);
1288da6c28aaSamw return (ret);
1289da6c28aaSamw }
1290da6c28aaSamw
1291da6c28aaSamw /*
1292da6c28aaSamw * smbadm_group_delmember
1293da6c28aaSamw */
1294da6c28aaSamw static int
smbadm_group_delmember(int argc,char ** argv)1295da6c28aaSamw smbadm_group_delmember(int argc, char **argv)
1296da6c28aaSamw {
1297da6c28aaSamw char *gname = NULL;
1298da6c28aaSamw char **mname;
1299da6c28aaSamw char option;
1300da6c28aaSamw int mcnt = 0;
1301da6c28aaSamw int ret = 0;
1302da6c28aaSamw int i;
1303da6c28aaSamw
1304da6c28aaSamw mname = (char **)malloc(argc * sizeof (char *));
1305da6c28aaSamw if (mname == NULL) {
13068d7e4166Sjose borrego warn(gettext("failed to delete group member"));
1307da6c28aaSamw return (1);
1308da6c28aaSamw }
1309da6c28aaSamw bzero(mname, argc * sizeof (char *));
1310da6c28aaSamw
1311da6c28aaSamw while ((option = getopt(argc, argv, "m:")) != -1) {
1312da6c28aaSamw switch (option) {
1313da6c28aaSamw case 'm':
1314da6c28aaSamw mname[mcnt++] = optarg;
1315da6c28aaSamw break;
1316da6c28aaSamw
1317da6c28aaSamw default:
1318da6c28aaSamw free(mname);
1319da6c28aaSamw smbadm_usage(B_FALSE);
1320da6c28aaSamw }
1321da6c28aaSamw }
1322da6c28aaSamw
1323da6c28aaSamw if (mcnt == 0) {
1324da6c28aaSamw (void) fprintf(stderr, gettext("missing member name\n"));
1325da6c28aaSamw free(mname);
1326da6c28aaSamw smbadm_usage(B_FALSE);
1327da6c28aaSamw }
1328da6c28aaSamw
1329da6c28aaSamw gname = argv[optind];
1330da6c28aaSamw if (optind >= argc || gname == NULL || *gname == 0) {
1331da6c28aaSamw (void) fprintf(stderr, gettext("missing group name\n"));
1332da6c28aaSamw free(mname);
1333da6c28aaSamw smbadm_usage(B_FALSE);
1334da6c28aaSamw }
1335da6c28aaSamw
1336da6c28aaSamw
1337da6c28aaSamw for (i = 0; i < mcnt; i++) {
1338fe1c642dSBill Krier ret = 0;
1339da6c28aaSamw if (mname[i] == NULL)
1340da6c28aaSamw continue;
134136a00406SGordon Ross ret |= smbadm_group_add_del_member(
134236a00406SGordon Ross gname, mname[i], SMBADM_GRP_DELMEMBER);
134336a00406SGordon Ross }
1344da6c28aaSamw
134536a00406SGordon Ross free(mname);
134636a00406SGordon Ross return (ret);
134736a00406SGordon Ross }
134836a00406SGordon Ross
134936a00406SGordon Ross static int
smbadm_group_add_del_member(char * gname,char * mname,smbadm_grp_action_t act)135036a00406SGordon Ross smbadm_group_add_del_member(char *gname, char *mname,
135136a00406SGordon Ross smbadm_grp_action_t act)
135236a00406SGordon Ross {
135336a00406SGordon Ross lsa_account_t acct;
135436a00406SGordon Ross smb_gsid_t msid;
135536a00406SGordon Ross char *sidstr;
135636a00406SGordon Ross char *act_str;
135736a00406SGordon Ross int rc;
135836a00406SGordon Ross
135936a00406SGordon Ross if (strncmp(mname, "S-1-", 4) == 0) {
136036a00406SGordon Ross /*
136136a00406SGordon Ross * We are given a SID. Just use it.
136236a00406SGordon Ross *
136336a00406SGordon Ross * We'e like the real account type if we can get it,
136436a00406SGordon Ross * but don't want to error out if we can't get it.
136536a00406SGordon Ross */
136636a00406SGordon Ross sidstr = mname;
136736a00406SGordon Ross rc = smb_lookup_sid(sidstr, &acct);
136836a00406SGordon Ross if ((rc != 0) || (acct.a_status != NT_STATUS_SUCCESS))
136936a00406SGordon Ross acct.a_sidtype = SidTypeUnknown;
137036a00406SGordon Ross } else {
137136a00406SGordon Ross rc = smb_lookup_name(mname, SidTypeUnknown, &acct);
137236a00406SGordon Ross if ((rc != 0) || (acct.a_status != NT_STATUS_SUCCESS)) {
1373dc20a302Sas200622 (void) fprintf(stderr,
137436a00406SGordon Ross gettext("%s: name lookup failed\n"), mname);
137536a00406SGordon Ross return (1);
137636a00406SGordon Ross }
137736a00406SGordon Ross sidstr = acct.a_sid;
1378dc20a302Sas200622 }
1379dc20a302Sas200622
1380fe1c642dSBill Krier msid.gs_type = acct.a_sidtype;
138136a00406SGordon Ross if ((msid.gs_sid = smb_sid_fromstr(sidstr)) == NULL) {
1382fe1c642dSBill Krier (void) fprintf(stderr,
138336a00406SGordon Ross gettext("%s: no memory for SID\n"), sidstr);
138436a00406SGordon Ross return (1);
1385fe1c642dSBill Krier }
1386fe1c642dSBill Krier
138736a00406SGordon Ross switch (act) {
138836a00406SGordon Ross case SMBADM_GRP_ADDMEMBER:
138936a00406SGordon Ross act_str = gettext("add");
139036a00406SGordon Ross rc = smb_lgrp_add_member(gname,
139136a00406SGordon Ross msid.gs_sid, msid.gs_type);
139236a00406SGordon Ross break;
139336a00406SGordon Ross case SMBADM_GRP_DELMEMBER:
139436a00406SGordon Ross act_str = gettext("remove");
139536a00406SGordon Ross rc = smb_lgrp_del_member(gname,
139636a00406SGordon Ross msid.gs_sid, msid.gs_type);
139736a00406SGordon Ross break;
139836a00406SGordon Ross default:
139936a00406SGordon Ross rc = SMB_LGRP_INTERNAL_ERROR;
140036a00406SGordon Ross break;
140136a00406SGordon Ross }
140236a00406SGordon Ross
1403fe1c642dSBill Krier smb_sid_free(msid.gs_sid);
1404da6c28aaSamw
140536a00406SGordon Ross if (rc != SMB_LGRP_SUCCESS) {
140636a00406SGordon Ross (void) fprintf(stderr,
140736a00406SGordon Ross gettext("failed to %s %s (%s)\n"),
140836a00406SGordon Ross act_str, mname, smb_lgrp_strerror(rc));
140936a00406SGordon Ross return (1);
141036a00406SGordon Ross }
141136a00406SGordon Ross return (0);
1412da6c28aaSamw }
1413da6c28aaSamw
1414da6c28aaSamw static int
smbadm_user_disable(int argc,char ** argv)1415da6c28aaSamw smbadm_user_disable(int argc, char **argv)
1416da6c28aaSamw {
1417da6c28aaSamw int error;
1418da6c28aaSamw char *user = NULL;
1419da6c28aaSamw
1420da6c28aaSamw user = argv[optind];
1421da6c28aaSamw if (optind >= argc || user == NULL || *user == '\0') {
1422da6c28aaSamw (void) fprintf(stderr, gettext("missing user name\n"));
1423da6c28aaSamw smbadm_usage(B_FALSE);
1424da6c28aaSamw }
1425da6c28aaSamw
1426da6c28aaSamw error = smb_pwd_setcntl(user, SMB_PWC_DISABLE);
1427da6c28aaSamw if (error == SMB_PWE_SUCCESS)
1428da6c28aaSamw (void) printf(gettext("%s is disabled.\n"), user);
1429da6c28aaSamw else
1430da6c28aaSamw (void) fprintf(stderr, "%s\n", smbadm_pwd_strerror(error));
1431da6c28aaSamw
1432da6c28aaSamw return (error);
1433da6c28aaSamw }
1434da6c28aaSamw
1435da6c28aaSamw static int
smbadm_user_enable(int argc,char ** argv)1436da6c28aaSamw smbadm_user_enable(int argc, char **argv)
1437da6c28aaSamw {
1438da6c28aaSamw int error;
1439da6c28aaSamw char *user = NULL;
1440da6c28aaSamw
1441da6c28aaSamw user = argv[optind];
1442da6c28aaSamw if (optind >= argc || user == NULL || *user == '\0') {
1443da6c28aaSamw (void) fprintf(stderr, gettext("missing user name\n"));
1444da6c28aaSamw smbadm_usage(B_FALSE);
1445da6c28aaSamw }
1446da6c28aaSamw
1447da6c28aaSamw error = smb_pwd_setcntl(user, SMB_PWC_ENABLE);
1448da6c28aaSamw if (error == SMB_PWE_SUCCESS)
1449da6c28aaSamw (void) printf(gettext("%s is enabled.\n"), user);
1450da6c28aaSamw else
1451da6c28aaSamw (void) fprintf(stderr, "%s\n", smbadm_pwd_strerror(error));
1452da6c28aaSamw
1453da6c28aaSamw return (error);
1454da6c28aaSamw }
1455da6c28aaSamw
1456da6c28aaSamw
1457da6c28aaSamw int
main(int argc,char ** argv)1458da6c28aaSamw main(int argc, char **argv)
1459da6c28aaSamw {
1460dc20a302Sas200622 int ret;
1461da6c28aaSamw int i;
1462da6c28aaSamw
146396a62adaSjoyce mcintosh (void) setlocale(LC_ALL, "");
146496a62adaSjoyce mcintosh (void) textdomain(TEXT_DOMAIN);
146596a62adaSjoyce mcintosh
1466da6c28aaSamw (void) malloc(0); /* satisfy libumem dependency */
1467da6c28aaSamw
1468da6c28aaSamw progname = basename(argv[0]);
1469da6c28aaSamw
1470da6c28aaSamw if (is_system_labeled()) {
1471da6c28aaSamw (void) fprintf(stderr,
1472da6c28aaSamw gettext("Trusted Extensions not supported\n"));
14738622ec45SGordon Ross return (1);
1474da6c28aaSamw }
1475da6c28aaSamw
1476da6c28aaSamw if (argc < 2) {
1477da6c28aaSamw (void) fprintf(stderr, gettext("missing command\n"));
1478da6c28aaSamw smbadm_usage(B_FALSE);
1479da6c28aaSamw }
1480da6c28aaSamw
1481da6c28aaSamw /*
1482da6c28aaSamw * Special case "cmd --help/-?"
1483da6c28aaSamw */
1484da6c28aaSamw if (strcmp(argv[1], "-?") == 0 ||
1485da6c28aaSamw strcmp(argv[1], "--help") == 0 ||
1486da6c28aaSamw strcmp(argv[1], "-h") == 0)
1487da6c28aaSamw smbadm_usage(B_TRUE);
1488da6c28aaSamw
1489da6c28aaSamw for (i = 0; i < SMBADM_NCMD; ++i) {
1490da6c28aaSamw curcmd = &smbadm_cmdtable[i];
1491da6c28aaSamw if (strcasecmp(argv[1], curcmd->name) == 0) {
1492da6c28aaSamw if (argc > 2) {
1493da6c28aaSamw /* cmd subcmd --help/-? */
1494da6c28aaSamw if (strcmp(argv[2], "-?") == 0 ||
1495da6c28aaSamw strcmp(argv[2], "--help") == 0 ||
1496da6c28aaSamw strcmp(argv[2], "-h") == 0)
1497da6c28aaSamw smbadm_usage(B_TRUE);
1498da6c28aaSamw }
1499da6c28aaSamw
150096a62adaSjoyce mcintosh if (!smbadm_checkauth(curcmd->auth)) {
150196a62adaSjoyce mcintosh (void) fprintf(stderr,
150296a62adaSjoyce mcintosh gettext("%s: %s: authorization denied\n"),
150396a62adaSjoyce mcintosh progname, curcmd->name);
150496a62adaSjoyce mcintosh return (1);
150596a62adaSjoyce mcintosh }
150696a62adaSjoyce mcintosh
15073db3f65cSamw if ((ret = smbadm_init()) != 0)
1508faa1795aSjb150015 return (ret);
1509dc20a302Sas200622
1510dc20a302Sas200622 ret = curcmd->func(argc - 1, &argv[1]);
1511faa1795aSjb150015
15123db3f65cSamw smbadm_fini();
1513dc20a302Sas200622 return (ret);
1514da6c28aaSamw }
1515da6c28aaSamw }
1516da6c28aaSamw
1517da6c28aaSamw curcmd = NULL;
1518da6c28aaSamw (void) fprintf(stderr, gettext("unknown subcommand (%s)\n"), argv[1]);
1519da6c28aaSamw smbadm_usage(B_FALSE);
1520da6c28aaSamw return (2);
1521da6c28aaSamw }
1522da6c28aaSamw
1523faa1795aSjb150015 static int
smbadm_init(void)15243db3f65cSamw smbadm_init(void)
1525faa1795aSjb150015 {
1526faa1795aSjb150015 int rc;
1527faa1795aSjb150015
15283db3f65cSamw switch (curcmd->flags & SMBADM_CMDF_TYPEMASK) {
15293db3f65cSamw case SMBADM_CMDF_GROUP:
1530faa1795aSjb150015 if ((rc = smb_lgrp_start()) != SMB_LGRP_SUCCESS) {
1531faa1795aSjb150015 (void) fprintf(stderr,
1532faa1795aSjb150015 gettext("failed to initialize (%s)\n"),
1533faa1795aSjb150015 smb_lgrp_strerror(rc));
1534faa1795aSjb150015 return (1);
1535faa1795aSjb150015 }
15363db3f65cSamw break;
15373db3f65cSamw
15383db3f65cSamw case SMBADM_CMDF_USER:
15393db3f65cSamw smb_pwd_init(B_FALSE);
15403db3f65cSamw break;
15413db3f65cSamw
15423db3f65cSamw default:
15433db3f65cSamw break;
1544faa1795aSjb150015 }
1545faa1795aSjb150015
1546faa1795aSjb150015 return (0);
1547faa1795aSjb150015 }
1548faa1795aSjb150015
1549faa1795aSjb150015 static void
smbadm_fini(void)15503db3f65cSamw smbadm_fini(void)
1551faa1795aSjb150015 {
15523db3f65cSamw switch (curcmd->flags & SMBADM_CMDF_TYPEMASK) {
15533db3f65cSamw case SMBADM_CMDF_GROUP:
1554faa1795aSjb150015 smb_lgrp_stop();
15553db3f65cSamw break;
15563db3f65cSamw
15573db3f65cSamw case SMBADM_CMDF_USER:
15583db3f65cSamw smb_pwd_fini();
15593db3f65cSamw break;
15603db3f65cSamw
15613db3f65cSamw default:
15623db3f65cSamw break;
1563faa1795aSjb150015 }
1564faa1795aSjb150015 }
1565faa1795aSjb150015
1566da6c28aaSamw static boolean_t
smbadm_checkauth(const char * auth)156796a62adaSjoyce mcintosh smbadm_checkauth(const char *auth)
156896a62adaSjoyce mcintosh {
156996a62adaSjoyce mcintosh struct passwd *pw;
157096a62adaSjoyce mcintosh
157196a62adaSjoyce mcintosh if ((pw = getpwuid(getuid())) == NULL)
157296a62adaSjoyce mcintosh return (B_FALSE);
157396a62adaSjoyce mcintosh
157496a62adaSjoyce mcintosh if (chkauthattr(auth, pw->pw_name) == 0)
157596a62adaSjoyce mcintosh return (B_FALSE);
157696a62adaSjoyce mcintosh
157796a62adaSjoyce mcintosh return (B_TRUE);
157896a62adaSjoyce mcintosh }
157996a62adaSjoyce mcintosh
158096a62adaSjoyce mcintosh static boolean_t
smbadm_prop_validate(smbadm_prop_t * prop,boolean_t chkval)1581da6c28aaSamw smbadm_prop_validate(smbadm_prop_t *prop, boolean_t chkval)
1582da6c28aaSamw {
1583da6c28aaSamw smbadm_prop_handle_t *pinfo;
1584da6c28aaSamw int i;
1585da6c28aaSamw
1586da6c28aaSamw for (i = 0; i < SMBADM_NPROP; i++) {
1587da6c28aaSamw pinfo = &smbadm_ptable[i];
1588da6c28aaSamw if (strcmp(pinfo->p_name, prop->p_name) == 0) {
1589da6c28aaSamw if (pinfo->p_chkfn && chkval)
1590da6c28aaSamw return (pinfo->p_chkfn(prop));
1591da6c28aaSamw
1592da6c28aaSamw return (B_TRUE);
1593da6c28aaSamw }
1594da6c28aaSamw }
1595da6c28aaSamw
15968d7e4166Sjose borrego (void) fprintf(stderr, gettext("unrecognized property '%s'\n"),
15978d7e4166Sjose borrego prop->p_name);
1598da6c28aaSamw
1599da6c28aaSamw return (B_FALSE);
1600da6c28aaSamw }
1601da6c28aaSamw
1602da6c28aaSamw static int
smbadm_prop_parse(char * arg,smbadm_prop_t * prop)1603da6c28aaSamw smbadm_prop_parse(char *arg, smbadm_prop_t *prop)
1604da6c28aaSamw {
1605da6c28aaSamw boolean_t parse_value;
1606da6c28aaSamw char *equal;
1607da6c28aaSamw
1608da6c28aaSamw if (arg == NULL)
1609da6c28aaSamw return (2);
1610da6c28aaSamw
1611da6c28aaSamw prop->p_name = prop->p_value = NULL;
1612da6c28aaSamw
1613da6c28aaSamw if (strcmp(curcmd->name, "set") == 0)
1614da6c28aaSamw parse_value = B_TRUE;
1615da6c28aaSamw else
1616da6c28aaSamw parse_value = B_FALSE;
1617da6c28aaSamw
1618da6c28aaSamw prop->p_name = arg;
1619da6c28aaSamw
1620da6c28aaSamw if (parse_value) {
1621da6c28aaSamw equal = strchr(arg, '=');
1622da6c28aaSamw if (equal == NULL)
1623da6c28aaSamw return (2);
1624da6c28aaSamw
1625da6c28aaSamw *equal++ = '\0';
1626da6c28aaSamw prop->p_value = equal;
1627da6c28aaSamw }
1628da6c28aaSamw
1629da6c28aaSamw if (smbadm_prop_validate(prop, parse_value) == B_FALSE)
1630da6c28aaSamw return (2);
1631da6c28aaSamw
1632da6c28aaSamw return (0);
1633da6c28aaSamw }
1634da6c28aaSamw
1635da6c28aaSamw static smbadm_prop_handle_t *
smbadm_prop_gethandle(char * pname)1636da6c28aaSamw smbadm_prop_gethandle(char *pname)
1637da6c28aaSamw {
1638da6c28aaSamw int i;
1639da6c28aaSamw
1640da6c28aaSamw for (i = 0; i < SMBADM_NPROP; i++)
1641da6c28aaSamw if (strcmp(pname, smbadm_ptable[i].p_name) == 0)
1642da6c28aaSamw return (&smbadm_ptable[i]);
1643da6c28aaSamw
1644da6c28aaSamw return (NULL);
1645da6c28aaSamw }
1646da6c28aaSamw
1647da6c28aaSamw static int
smbadm_setprop_desc(char * gname,smbadm_prop_t * prop)1648da6c28aaSamw smbadm_setprop_desc(char *gname, smbadm_prop_t *prop)
1649da6c28aaSamw {
1650dc20a302Sas200622 int status;
1651da6c28aaSamw
1652dc20a302Sas200622 status = smb_lgrp_setcmnt(gname, prop->p_value);
1653dc20a302Sas200622 if (status != SMB_LGRP_SUCCESS) {
1654da6c28aaSamw (void) fprintf(stderr,
1655da6c28aaSamw gettext("failed to modify the group description (%s)\n"),
1656dc20a302Sas200622 smb_lgrp_strerror(status));
1657da6c28aaSamw return (1);
1658da6c28aaSamw }
1659da6c28aaSamw
16608d7e4166Sjose borrego (void) printf(gettext("%s: description modified\n"), gname);
1661da6c28aaSamw return (0);
1662da6c28aaSamw }
1663da6c28aaSamw
1664da6c28aaSamw static int
smbadm_getprop_desc(char * gname,smbadm_prop_t * prop)1665da6c28aaSamw smbadm_getprop_desc(char *gname, smbadm_prop_t *prop)
1666da6c28aaSamw {
1667dc20a302Sas200622 char *cmnt = NULL;
1668dc20a302Sas200622 int status;
1669da6c28aaSamw
1670dc20a302Sas200622 status = smb_lgrp_getcmnt(gname, &cmnt);
1671dc20a302Sas200622 if (status != SMB_LGRP_SUCCESS) {
1672da6c28aaSamw (void) fprintf(stderr,
1673dc20a302Sas200622 gettext("failed to get the group description (%s)\n"),
1674dc20a302Sas200622 smb_lgrp_strerror(status));
1675da6c28aaSamw return (1);
1676da6c28aaSamw }
1677da6c28aaSamw
1678dc20a302Sas200622 (void) printf(gettext("\t%s: %s\n"), prop->p_name, cmnt);
1679dc20a302Sas200622 free(cmnt);
1680da6c28aaSamw return (0);
1681da6c28aaSamw }
1682da6c28aaSamw
1683da6c28aaSamw static int
smbadm_group_setpriv(char * gname,uint8_t priv_id,smbadm_prop_t * prop)1684dc20a302Sas200622 smbadm_group_setpriv(char *gname, uint8_t priv_id, smbadm_prop_t *prop)
1685da6c28aaSamw {
1686dc20a302Sas200622 boolean_t enable;
1687dc20a302Sas200622 int status;
1688da6c28aaSamw int ret;
1689da6c28aaSamw
1690da6c28aaSamw if (strcasecmp(prop->p_value, "on") == 0) {
1691da6c28aaSamw (void) printf(gettext("Enabling %s privilege "), prop->p_name);
1692dc20a302Sas200622 enable = B_TRUE;
1693da6c28aaSamw } else {
1694da6c28aaSamw (void) printf(gettext("Disabling %s privilege "), prop->p_name);
1695dc20a302Sas200622 enable = B_FALSE;
1696da6c28aaSamw }
1697da6c28aaSamw
1698dc20a302Sas200622 status = smb_lgrp_setpriv(gname, priv_id, enable);
1699dc20a302Sas200622 if (status == SMB_LGRP_SUCCESS) {
1700da6c28aaSamw (void) printf(gettext("succeeded\n"));
1701da6c28aaSamw ret = 0;
1702da6c28aaSamw } else {
1703dc20a302Sas200622 (void) printf(gettext("failed: %s\n"),
1704dc20a302Sas200622 smb_lgrp_strerror(status));
1705da6c28aaSamw ret = 1;
1706da6c28aaSamw }
1707da6c28aaSamw
1708da6c28aaSamw return (ret);
1709da6c28aaSamw }
1710da6c28aaSamw
1711da6c28aaSamw static int
smbadm_group_getpriv(char * gname,uint8_t priv_id,smbadm_prop_t * prop)1712dc20a302Sas200622 smbadm_group_getpriv(char *gname, uint8_t priv_id, smbadm_prop_t *prop)
1713da6c28aaSamw {
1714dc20a302Sas200622 boolean_t enable;
1715dc20a302Sas200622 int status;
1716da6c28aaSamw
1717dc20a302Sas200622 status = smb_lgrp_getpriv(gname, priv_id, &enable);
1718dc20a302Sas200622 if (status != SMB_LGRP_SUCCESS) {
1719da6c28aaSamw (void) fprintf(stderr, gettext("failed to get %s (%s)\n"),
1720dc20a302Sas200622 prop->p_name, smb_lgrp_strerror(status));
1721da6c28aaSamw return (1);
1722da6c28aaSamw }
1723da6c28aaSamw
1724dc20a302Sas200622 (void) printf(gettext("\t%s: %s\n"), prop->p_name,
1725dc20a302Sas200622 (enable) ? "On" : "Off");
1726da6c28aaSamw
1727da6c28aaSamw return (0);
1728da6c28aaSamw }
1729da6c28aaSamw
1730da6c28aaSamw static int
smbadm_setprop_tkowner(char * gname,smbadm_prop_t * prop)1731da6c28aaSamw smbadm_setprop_tkowner(char *gname, smbadm_prop_t *prop)
1732da6c28aaSamw {
1733da6c28aaSamw return (smbadm_group_setpriv(gname, SE_TAKE_OWNERSHIP_LUID, prop));
1734da6c28aaSamw }
1735da6c28aaSamw
1736da6c28aaSamw static int
smbadm_getprop_tkowner(char * gname,smbadm_prop_t * prop)1737da6c28aaSamw smbadm_getprop_tkowner(char *gname, smbadm_prop_t *prop)
1738da6c28aaSamw {
1739da6c28aaSamw return (smbadm_group_getpriv(gname, SE_TAKE_OWNERSHIP_LUID, prop));
1740da6c28aaSamw }
1741da6c28aaSamw
1742da6c28aaSamw static int
smbadm_setprop_backup(char * gname,smbadm_prop_t * prop)1743da6c28aaSamw smbadm_setprop_backup(char *gname, smbadm_prop_t *prop)
1744da6c28aaSamw {
1745da6c28aaSamw return (smbadm_group_setpriv(gname, SE_BACKUP_LUID, prop));
1746da6c28aaSamw }
1747da6c28aaSamw
1748da6c28aaSamw static int
smbadm_getprop_backup(char * gname,smbadm_prop_t * prop)1749da6c28aaSamw smbadm_getprop_backup(char *gname, smbadm_prop_t *prop)
1750da6c28aaSamw {
1751da6c28aaSamw return (smbadm_group_getpriv(gname, SE_BACKUP_LUID, prop));
1752da6c28aaSamw }
1753da6c28aaSamw
1754da6c28aaSamw static int
smbadm_setprop_restore(char * gname,smbadm_prop_t * prop)1755da6c28aaSamw smbadm_setprop_restore(char *gname, smbadm_prop_t *prop)
1756da6c28aaSamw {
1757da6c28aaSamw return (smbadm_group_setpriv(gname, SE_RESTORE_LUID, prop));
1758da6c28aaSamw }
1759da6c28aaSamw
1760da6c28aaSamw static int
smbadm_getprop_restore(char * gname,smbadm_prop_t * prop)1761da6c28aaSamw smbadm_getprop_restore(char *gname, smbadm_prop_t *prop)
1762da6c28aaSamw {
1763da6c28aaSamw return (smbadm_group_getpriv(gname, SE_RESTORE_LUID, prop));
1764da6c28aaSamw }
1765da6c28aaSamw
1766da6c28aaSamw static boolean_t
smbadm_chkprop_priv(smbadm_prop_t * prop)1767da6c28aaSamw smbadm_chkprop_priv(smbadm_prop_t *prop)
1768da6c28aaSamw {
1769da6c28aaSamw if (prop->p_value == NULL || *prop->p_value == '\0') {
1770da6c28aaSamw (void) fprintf(stderr,
1771da6c28aaSamw gettext("missing value for '%s'\n"), prop->p_name);
1772da6c28aaSamw return (B_FALSE);
1773da6c28aaSamw }
1774da6c28aaSamw
1775da6c28aaSamw if (strcasecmp(prop->p_value, "on") == 0)
1776da6c28aaSamw return (B_TRUE);
1777da6c28aaSamw
1778da6c28aaSamw if (strcasecmp(prop->p_value, "off") == 0)
1779da6c28aaSamw return (B_TRUE);
1780da6c28aaSamw
1781da6c28aaSamw (void) fprintf(stderr,
1782da6c28aaSamw gettext("%s: unrecognized value for '%s' property\n"),
1783da6c28aaSamw prop->p_value, prop->p_name);
1784da6c28aaSamw
1785da6c28aaSamw return (B_FALSE);
1786da6c28aaSamw }
1787da6c28aaSamw
1788da6c28aaSamw static const char *
smbadm_pwd_strerror(int error)1789da6c28aaSamw smbadm_pwd_strerror(int error)
1790da6c28aaSamw {
1791da6c28aaSamw switch (error) {
1792da6c28aaSamw case SMB_PWE_SUCCESS:
1793da6c28aaSamw return (gettext("Success."));
1794da6c28aaSamw
1795da6c28aaSamw case SMB_PWE_USER_UNKNOWN:
1796da6c28aaSamw return (gettext("User does not exist."));
1797da6c28aaSamw
1798da6c28aaSamw case SMB_PWE_USER_DISABLE:
17998d7e4166Sjose borrego return (gettext("User is disabled."));
1800da6c28aaSamw
1801da6c28aaSamw case SMB_PWE_CLOSE_FAILED:
1802da6c28aaSamw case SMB_PWE_OPEN_FAILED:
1803da6c28aaSamw case SMB_PWE_WRITE_FAILED:
1804da6c28aaSamw case SMB_PWE_UPDATE_FAILED:
1805da6c28aaSamw return (gettext("Unexpected failure. "
1806da6c28aaSamw "SMB password database unchanged."));
1807da6c28aaSamw
1808da6c28aaSamw case SMB_PWE_STAT_FAILED:
1809da6c28aaSamw return (gettext("stat of SMB password file failed."));
1810da6c28aaSamw
1811da6c28aaSamw case SMB_PWE_BUSY:
1812da6c28aaSamw return (gettext("SMB password database busy. "
1813da6c28aaSamw "Try again later."));
1814da6c28aaSamw
1815da6c28aaSamw case SMB_PWE_DENIED:
1816da6c28aaSamw return (gettext("Operation not permitted."));
1817da6c28aaSamw
1818da6c28aaSamw case SMB_PWE_SYSTEM_ERROR:
1819da6c28aaSamw return (gettext("System error."));
18203db3f65cSamw
18213db3f65cSamw default:
18223db3f65cSamw break;
1823da6c28aaSamw }
1824da6c28aaSamw
1825da6c28aaSamw return (gettext("Unknown error code."));
1826da6c28aaSamw }
1827da6c28aaSamw
1828da6c28aaSamw /*
1829da6c28aaSamw * Enable libumem debugging by default on DEBUG builds.
1830da6c28aaSamw */
1831da6c28aaSamw #ifdef DEBUG
1832da6c28aaSamw const char *
_umem_debug_init(void)1833da6c28aaSamw _umem_debug_init(void)
1834da6c28aaSamw {
1835da6c28aaSamw return ("default,verbose"); /* $UMEM_DEBUG setting */
1836da6c28aaSamw }
1837da6c28aaSamw
1838da6c28aaSamw const char *
_umem_logging_init(void)1839da6c28aaSamw _umem_logging_init(void)
1840da6c28aaSamw {
1841da6c28aaSamw return ("fail,contents"); /* $UMEM_LOGGING setting */
1842da6c28aaSamw }
1843da6c28aaSamw #endif
1844