/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
*/
/*
* This module contains smbadm CLI which offers smb configuration
* functionalities.
*/
#include <errno.h>
#include <err.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <syslog.h>
#include <strings.h>
#include <limits.h>
#include <getopt.h>
#include <libintl.h>
#include <zone.h>
#include <pwd.h>
#include <grp.h>
#include <libgen.h>
#include <auth_attr.h>
#include <locale.h>
#include <smbsrv/libsmbns.h>
#if !defined(TEXT_DOMAIN)
#endif
typedef enum {
typedef enum {
SMBADM_GRP_ADDMEMBER = 0,
typedef struct smbadm_cmdinfo {
char *name;
int (*func)(int, char **);
char *auth;
static char *progname;
static boolean_t smbadm_checkauth(const char *);
static void smbadm_usage(boolean_t);
static int smbadm_join_workgroup(const char *, boolean_t);
static int smbadm_join_domain(const char *, const char *, boolean_t);
static void smbadm_extract_domain(char *, char **, char **);
static int smbadm_join(int, char **);
static int smbadm_list(int, char **);
static int smbadm_lookup(int, char **);
static void smbadm_lookup_name(char *);
static void smbadm_lookup_sid(char *);
static int smbadm_group_create(int, char **);
static int smbadm_group_delete(int, char **);
static int smbadm_group_rename(int, char **);
static int smbadm_group_show(int, char **);
static void smbadm_group_show_name(const char *, const char *);
static int smbadm_group_getprop(int, char **);
static int smbadm_group_setprop(int, char **);
static int smbadm_group_addmember(int, char **);
static int smbadm_group_delmember(int, char **);
static int smbadm_group_add_del_member(char *, char *, smbadm_grp_action_t);
static int smbadm_user_disable(int, char **);
static int smbadm_user_enable(int, char **);
{
};
typedef struct smbadm_prop {
char *p_name;
char *p_value;
typedef struct smbadm_prop_handle {
char *p_name;
char *p_dispvalue;
};
static int smbadm_init(void);
static void smbadm_fini(void);
static const char *smbadm_pwd_strerror(int error);
/*
* Number of supported properties
*/
static void
{
case HELP_ADD_MEMBER:
gettext("\t%s -m member [[-m member] ...] group\n"),
return;
case HELP_CREATE:
return;
case HELP_DELETE:
return;
case HELP_USER_DISABLE:
case HELP_USER_ENABLE:
return;
case HELP_GET:
return;
case HELP_JOIN:
#if 0 /* Don't document "-p" yet, still needs work (NX 11960) */
"\t%s [-y] -u username domain\n\t%s [-y] -w workgroup\n"),
#else
#endif
return;
case HELP_LIST:
gettext("\t\t[*] primary domain\n"));
gettext("\t\t[+] selected domain controller\n"));
return;
case HELP_LOOKUP:
gettext("\t%s user-or-group-name\n"),
return;
case HELP_DEL_MEMBER:
gettext("\t%s -m member [[-m member] ...] group\n"),
return;
case HELP_RENAME:
return;
case HELP_SET:
return;
case HELP_SHOW:
return;
default:
break;
}
abort();
/* NOTREACHED */
}
static void
{
int i;
gettext("usage: %s [-h | <command> [options]]\n"),
progname);
gettext("where 'command' is one of the following:\n\n"));
for (i = 0; i < SMBADM_NCMD; i++)
gettext("\nFor property list, run %s %s|%s\n"),
}
show_props = B_TRUE;
if (show_props) {
gettext("\nThe following properties are supported:\n"));
"PROPERTY", "VALUES");
for (i = 0; i < SMBADM_NPROP; i++) {
smbadm_ptable[i].p_name,
smbadm_ptable[i].p_dispvalue);
}
}
}
/*
* smbadm_strcasecmplist
*
* Find a string 's' within a list of strings.
*
* Returns the index of the matching string or -1 if there is no match.
*/
static int
smbadm_strcasecmplist(const char *s, ...)
{
char *p;
int ndx;
if (strcasecmp(s, p) == 0) {
return (ndx);
}
}
return (-1);
}
/*
* smbadm_answer_prompt
*
* Prompt for the answer to a question. A default response must be
* specified, which will be used if the user presses <enter> without
* answering the question.
*/
static int
{
char *p;
return (-1);
*p = '\0';
if (*buf == '\0')
else
return (0);
}
/*
* smbadm_confirm
*
* A default response must be specified.
*/
static boolean_t
{
for (;;) {
return (B_FALSE);
return (B_FALSE);
return (B_TRUE);
}
}
static boolean_t
{
"restarted automatically.\n"), domain);
}
static void
smbadm_restart_service(void)
{
if (smb_smf_restart_service() != 0) {
gettext("Unable to restart smb service. "
}
}
/*
* smbadm_join
*
* Join a domain or workgroup.
*
* When joining a domain, we may receive the username, password and
* domain name in any of the following combinations. Note that the
* password is optional on the command line: if it is not provided,
* we will prompt for it later.
*
* username+password domain
* domain\username+password
* username@domain
*
* name+password@domain because @ is a valid password character.
*
* If the username and domain name are passed as separate command
* line arguments, we process them directly. Otherwise we separate
* them and continue as if they were separate command line arguments.
*/
static int
{
char option;
if (mode != 0) {
"join options are mutually exclusive\n"));
}
switch (option) {
case 'p':
/* leave username = NULL */
break;
case 'u':
break;
case 'w':
break;
case 'y':
break;
default:
break;
}
}
/*
* The domain was not specified as a separate
* argument, check for the combination forms.
*/
}
}
if (mode == SMB_SECMODE_WORKGRP) {
}
}
/*
* Workgroups comprise a collection of standalone, independently administered
* computers that use a common workgroup name. This is a peer-to-peer model
* with no formal membership mechanism.
*/
static int
{
}
return (0);
return (1);
}
return (0);
}
/*
* Domains comprise a centrally administered group of computers and accounts
* that share a common security and administration policy and database.
* Computers must join a domain and become domain members, which requires
* an administrator level account name.
*
* The '+' character is invalid within a username. We allow the password
* to be appended to the username using '+' as a scripting convenience.
*/
static int
{
char *passwd_prompt;
char *p;
}
return (0);
/*
* Note: username is null for "unsecure join"
* (join using a pre-created computer account)
* No password either.
*/
++p;
sizeof (jdi.domain_passwd));
} else {
sizeof (jdi.domain_username));
}
!= ERROR_SUCCESS) {
gettext("username contains invalid characters\n"));
}
"missing password\n"));
}
sizeof (jdi.domain_passwd));
}
}
if (rc != 0) {
" (error %d: %s) "
"Please check the service status "
return (1);
}
case NT_STATUS_SUCCESS:
"Successfully joined domain %s using AD server %s\n"),
return (0);
/* See: smb_ads_lookup_msdcs */
"failed to find any AD servers for domain: %s\n"),
goto common;
/* See: smbrdr_ctx_new / smb_ctx_resolve */
"failed to resolve address of AD server: %s\n"),
goto common;
/* See: smbrdr_ctx_new / smb_ctx_get_ssn */
"failed to authenticate with AD server: %s\n"),
goto common;
/*
* See: smbrdr_ctx_new / smb_ctx_get_tree
* and: ndr_rpc_bind / smb_fh_open
*/
"failed connecting to services on AD server: %s\n"),
goto common;
default:
"failed to join domain %s\n"),
"using AD server: %s\n"),
}
/* FALLTHROUGH */
}
"service log for more information.\n"));
return (1);
}
}
/*
* We want to process the user and domain names as separate strings.
* Check for names of the forms below and separate the components as
* required.
*
* name@domain
* domain\name
*
* If we encounter any of the forms above in arg, the @, / or \
* separator is replaced by \0 and the username and domain pointers
* are changed to point to the appropriate components (in arg).
*
* If none of the separators are encountered, the username and domain
* pointers remain unchanged.
*/
static void
{
char *p;
if (*p == '@') {
*p = '\0';
++p;
return;
*domain = p;
} else {
*p = '\0';
++p;
*username = p;
}
}
}
/*
* smbadm_list
*
*/
/*ARGSUSED*/
static int
{
int rc;
if (rc != SMBD_SMF_OK) {
gettext("cannot determine the operational mode\n"));
return (1);
}
modename);
return (1);
}
return (0);
}
(!smb_inet_iszero(&srvipaddr))) {
}
/* Print the local and domain SID. */
return (0);
}
/*
* smbadm_lookup
*
* Lookup the SID for a given account (user or group)
*/
static int
{
int i;
if (argc < 2) {
}
for (i = 1; i < argc; i++) {
smbadm_lookup_sid(argv[i]);
else
smbadm_lookup_name(argv[i]);
}
return (0);
}
static void
{
int rc;
"\t\t%s: lookup name failed, rc=%d\n"),
return;
}
return;
}
}
static void
{
int rc;
"\t\t%s: lookup SID failed, rc=%d\n"),
return;
}
return;
}
}
/*
* smbadm_group_create
*
* Creates a local SMB group
*/
static int
{
char option;
int status;
switch (option) {
case 'd':
break;
default:
}
}
}
if (status != SMB_LGRP_SUCCESS) {
} else {
}
return (status);
}
/*
* smbadm_group_dump_members
*
* Dump group members details.
*/
static void
{
int i;
if (num == 0) {
return;
}
for (i = 0; i < num; i++) {
else
} else {
}
}
}
static void
{
else
}
/*
* smbadm_group_dump_privs
*
* Dump group privilege details.
*/
static void
{
char *pstatus;
int i;
continue;
case SE_PRIVILEGE_ENABLED:
pstatus = "On";
break;
case SE_PRIVILEGE_DISABLED:
pstatus = "Off";
break;
default:
pstatus = "Unknown";
break;
}
}
}
/*
* smbadm_group_dump
*
* Dump group details.
*/
static void
{
if (show_privs)
if (show_mem)
}
/*
* smbadm_group_show
*
*/
static int
{
char option;
int status;
switch (option) {
case 'm':
break;
case 'p':
show_privs = B_TRUE;
break;
default:
}
}
gname = "*";
if (status == SMB_LGRP_SUCCESS) {
smb_lgrp_free(&grp);
} else {
gettext("failed to find %s (%s)\n"),
}
return (status);
}
return (status);
}
smb_lgrp_free(&grp);
}
if (status != SMB_LGRP_NO_MORE)
gettext("\nAn error occurred while retrieving group data.\n"
"Check the system log for more information.\n"));
return (status);
}
return (0);
}
/*
* smbadm_group_delete
*/
static int
{
int status;
}
if (status != SMB_LGRP_SUCCESS) {
} else {
}
return (status);
}
/*
* smbadm_group_rename
*/
static int
{
int status;
}
}
if (status != SMB_LGRP_SUCCESS) {
if (status == SMB_LGRP_EXISTS)
gettext("failed to rename '%s' (%s already "
else
} else {
}
return (status);
}
/*
* smbadm_group_setprop
*
* Set the group properties.
*/
static int
{
char option;
int pcnt = 0;
int ret;
int p;
switch (option) {
case 'p':
if (pcnt >= SMBADM_NPROP) {
gettext("exceeded number of supported"
" properties\n"));
}
break;
default:
}
}
if (pcnt == 0) {
gettext("missing property=value argument\n"));
}
}
for (p = 0; p < pcnt; p++) {
if (phandle) {
ret = 1;
}
}
return (ret);
}
/*
* smbadm_group_getprop
*
* Get the group properties.
*/
static int
{
char option;
int pcnt = 0;
int ret;
int p;
switch (option) {
case 'p':
if (pcnt >= SMBADM_NPROP) {
gettext("exceeded number of supported"
" properties\n"));
}
break;
default:
}
}
}
if (pcnt == 0) {
/*
* If no property has be specified then get
* all the properties.
*/
pcnt = SMBADM_NPROP;
for (p = 0; p < pcnt; p++)
}
for (p = 0; p < pcnt; p++) {
if (phandle) {
ret = 1;
}
}
return (ret);
}
/*
* smbadm_group_addmember
*
*/
static int
{
char **mname;
char option;
int mcnt = 0;
int ret = 0;
int i;
return (1);
}
switch (option) {
case 'm':
break;
default:
}
}
if (mcnt == 0) {
}
}
for (i = 0; i < mcnt; i++) {
continue;
}
return (ret);
}
/*
* smbadm_group_delmember
*/
static int
{
char **mname;
char option;
int mcnt = 0;
int ret = 0;
int i;
return (1);
}
switch (option) {
case 'm':
break;
default:
}
}
if (mcnt == 0) {
}
}
for (i = 0; i < mcnt; i++) {
ret = 0;
continue;
}
return (ret);
}
static int
{
char *sidstr;
char *act_str;
int rc;
/*
* We are given a SID. Just use it.
*
* We'e like the real account type if we can get it,
* but don't want to error out if we can't get it.
*/
} else {
return (1);
}
}
return (1);
}
switch (act) {
case SMBADM_GRP_ADDMEMBER:
break;
case SMBADM_GRP_DELMEMBER:
break;
default:
break;
}
if (rc != SMB_LGRP_SUCCESS) {
gettext("failed to %s %s (%s)\n"),
return (1);
}
return (0);
}
static int
{
int error;
}
if (error == SMB_PWE_SUCCESS)
else
return (error);
}
static int
{
int error;
}
if (error == SMB_PWE_SUCCESS)
else
return (error);
}
int
{
int ret;
int i;
(void) textdomain(TEXT_DOMAIN);
(void) malloc(0); /* satisfy libumem dependency */
if (is_system_labeled()) {
gettext("Trusted Extensions not supported\n"));
return (1);
}
if (argc < 2) {
}
/*
* Special case "cmd --help/-?"
*/
for (i = 0; i < SMBADM_NCMD; ++i) {
curcmd = &smbadm_cmdtable[i];
if (argc > 2) {
/* cmd subcmd --help/-? */
}
gettext("%s: %s: authorization denied\n"),
return (1);
}
if ((ret = smbadm_init()) != 0)
return (ret);
smbadm_fini();
return (ret);
}
}
return (2);
}
static int
smbadm_init(void)
{
int rc;
case SMBADM_CMDF_GROUP:
gettext("failed to initialize (%s)\n"),
return (1);
}
break;
case SMBADM_CMDF_USER:
break;
default:
break;
}
return (0);
}
static void
smbadm_fini(void)
{
case SMBADM_CMDF_GROUP:
break;
case SMBADM_CMDF_USER:
smb_pwd_fini();
break;
default:
break;
}
}
static boolean_t
{
return (B_FALSE);
return (B_FALSE);
return (B_TRUE);
}
static boolean_t
{
int i;
for (i = 0; i < SMBADM_NPROP; i++) {
pinfo = &smbadm_ptable[i];
return (B_TRUE);
}
}
return (B_FALSE);
}
static int
{
char *equal;
return (2);
else
if (parse_value) {
return (2);
*equal++ = '\0';
}
return (2);
return (0);
}
static smbadm_prop_handle_t *
{
int i;
for (i = 0; i < SMBADM_NPROP; i++)
return (&smbadm_ptable[i]);
return (NULL);
}
static int
{
int status;
if (status != SMB_LGRP_SUCCESS) {
gettext("failed to modify the group description (%s)\n"),
return (1);
}
return (0);
}
static int
{
int status;
if (status != SMB_LGRP_SUCCESS) {
gettext("failed to get the group description (%s)\n"),
return (1);
}
return (0);
}
static int
{
int status;
int ret;
} else {
}
if (status == SMB_LGRP_SUCCESS) {
ret = 0;
} else {
ret = 1;
}
return (ret);
}
static int
{
int status;
if (status != SMB_LGRP_SUCCESS) {
return (1);
}
return (0);
}
static int
{
}
static int
{
}
static int
{
}
static int
{
}
static int
{
}
static int
{
}
static boolean_t
{
return (B_FALSE);
}
return (B_TRUE);
return (B_TRUE);
gettext("%s: unrecognized value for '%s' property\n"),
return (B_FALSE);
}
static const char *
{
switch (error) {
case SMB_PWE_SUCCESS:
return (gettext("Success."));
case SMB_PWE_USER_UNKNOWN:
return (gettext("User does not exist."));
case SMB_PWE_USER_DISABLE:
return (gettext("User is disabled."));
case SMB_PWE_CLOSE_FAILED:
case SMB_PWE_OPEN_FAILED:
case SMB_PWE_WRITE_FAILED:
case SMB_PWE_UPDATE_FAILED:
return (gettext("Unexpected failure. "
"SMB password database unchanged."));
case SMB_PWE_STAT_FAILED:
return (gettext("stat of SMB password file failed."));
case SMB_PWE_BUSY:
return (gettext("SMB password database busy. "
"Try again later."));
case SMB_PWE_DENIED:
return (gettext("Operation not permitted."));
case SMB_PWE_SYSTEM_ERROR:
return (gettext("System error."));
default:
break;
}
return (gettext("Unknown error code."));
}
/*
* Enable libumem debugging by default on DEBUG builds.
*/
#ifdef DEBUG
const char *
_umem_debug_init(void)
{
return ("default,verbose"); /* $UMEM_DEBUG setting */
}
const char *
_umem_logging_init(void)
{
return ("fail,contents"); /* $UMEM_LOGGING setting */
}
#endif