smbadm.c revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This module contains smbadm CLI which offers smb configuration
* functionalities.
*/
#include <stdlib.h>
#include <stdio.h>
#include <syslog.h>
#include <strings.h>
#include <limits.h>
#include <getopt.h>
#include <libintl.h>
#include <zone.h>
#include <grp.h>
#include <libgen.h>
#include <smbsrv/libmlsvc.h>
typedef enum {
typedef struct smbadm_cmdinfo {
char *name;
int (*func)(int, char **);
static char *progname;
static int smbadm_join(int, char **);
static int smbadm_list(int, 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 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_user_disable(int, char **);
static int smbadm_user_enable(int, char **);
static smbadm_cmdinfo_t smbadm_cmdtable[] =
{
};
typedef struct smbadm_prop {
char *p_name;
char *p_value;
typedef struct smbadm_prop_handle {
char *p_name;
char *p_dispvalue;
int (*p_setfn)(char *, smbadm_prop_t *);
int (*p_getfn)(char *, smbadm_prop_t *);
static smbadm_prop_handle_t smbadm_ptable[] = {
};
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_UDISABLE:
case HELP_UENABLE:
return;
case HELP_GET:
return;
case HELP_JOIN:
return;
case HELP_LIST:
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;
}
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_join
*
*/
static int
{
char option;
switch (option) {
case 'w':
sizeof (jdi.domain_name));
break;
case 'u':
/* admin username */
sizeof (jdi.domain_username));
break;
default:
}
}
gettext("domain and workgroup "
"can not be specified together\n"));
}
sizeof (jdi.domain_name));
}
}
}
if (join_w) {
if (status == NT_STATUS_SUCCESS) {
(void) printf(
gettext("Successfully joined workgroup '%s'\n"),
return (0);
}
gettext("failed to join workgroup '%s' (%s)\n"),
return (1);
}
/* Join the domain */
char *p = NULL;
p = getpassphrase(prompt);
if (!p) {
}
sizeof (jdi.domain_passwd));
}
switch (status) {
case NT_STATUS_SUCCESS:
return (0);
"any domain controllers for '%s'\n"),
break;
default:
gettext("failed to join domain '%s' (%s)\n"),
}
return (1);
}
/*
* smbadm_list
*
*/
/*ARGSUSED*/
static int
{
char resource_domain[SMB_PI_MAX_DOMAIN];
int sec_mode;
char *modename;
if (smbd_get_security_mode(&sec_mode)) {
gettext("failed to get the security mode\n"));
return (1);
}
return (1);
}
return (0);
}
/*
* smbadm_group_create
*
* Creates a local SMB group
*/
static int
{
char option;
switch (option) {
case 'd':
break;
default:
}
}
}
gettext("failed to get the Solaris group\n"));
gettext("use 'groupadd' to add the Solaris group\n"));
return (1);
}
if (status != NT_STATUS_SUCCESS) {
gettext("failed to create the group (%s)\n"),
} else {
gname);
}
return (status);
}
/*
* smbadm_group_dump_members
*
* Dump group members details.
*/
static void
smbadm_group_dump_members(char *gname)
{
int mem_cnt = 0;
int offset = 0;
int i;
if (mem_cnt < 0) {
gettext("failed to get the group members (%s)\n"),
}
if (mem_cnt == 0) {
return;
}
break;
break;
}
}
/*
* smbadm_group_dump_privs
*
* Dump group privilege details.
*/
static void
{
int privcnt = 0;
int i;
continue;
&privval) != 0) {
continue;
}
if (privval == SE_PRIVILEGE_ENABLED) {
} else if (privval == SE_PRIVILEGE_DISABLED) {
} else {
}
privcnt++;
}
if (privcnt == 0)
}
/*
* smbadm_group_dump
*
* Dump group details.
*/
static int
{
char *gname;
int i;
if (show_privs) {
gettext("failed to get privileges (%s)\n"),
return (1);
}
}
if (show_privs)
if (show_mem)
}
return (0);
}
/*
* smbadm_group_show
*
*/
static int
{
int cnt = 0;
int offset = 0;
char option;
int ret = 0;
switch (option) {
case 'm':
break;
case 'p':
show_privs = B_TRUE;
break;
default:
}
}
gname = "*";
gettext("failed to get the number of group(s) (%s)\n"),
return (1);
}
if (status != NT_STATUS_SUCCESS) {
gettext("failed to get the group(s) (%s)\n"),
return (1);
}
break;
if (ret)
break;
smb_group_free_list(list, 0);
}
return (ret);
}
/*
* smbadm_group_delete
*
*/
static int
{
}
if (status != NT_STATUS_SUCCESS) {
gettext("failed to delete the group (%s)\n"),
} else {
gname);
}
return (status);
}
/*
* smbadm_group_rename
*
*/
static int
{
}
}
gettext("failed to get the Solaris group\n"));
gettext("use 'groupadd' to add the Solaris group\n"));
return (1);
}
if (status != NT_STATUS_SUCCESS) {
gettext("failed to modify the group (%s)\n"),
} else {
"group '%s'\n"), gname);
}
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"));
}
if (ret) {
if (ret == 1)
exit(1);
if (ret == 2)
}
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"));
}
if (ret) {
if (ret == 1)
exit(1);
if (ret == 2)
}
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;
if (status != NT_STATUS_SUCCESS) {
gettext("failed to add %s (%s)\n"),
ret = 1;
}
else
}
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++) {
continue;
if (status != NT_STATUS_SUCCESS) {
gettext("failed to remove %s (%s)\n"),
ret = 1;
} else {
(void) printf(
gettext("Successfully removed %s from %s\n"),
}
}
return (ret);
}
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 i;
(void) malloc(0); /* satisfy libumem dependency */
if (getzoneid() != GLOBAL_ZONEID) {
gettext("cannot execute in non-global zone\n"));
return (0);
}
if (is_system_labeled()) {
gettext("Trusted Extensions not supported\n"));
return (0);
}
if (argc < 2) {
}
/*
* Special case "cmd --help/-?"
*/
for (i = 0; i < SMBADM_NCMD; ++i) {
curcmd = &smbadm_cmdtable[i];
if (argc > 2) {
/* cmd subcmd --help/-? */
}
}
}
return (2);
}
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 *
smbadm_prop_gethandle(char *pname)
{
int i;
for (i = 0; i < SMBADM_NPROP; i++)
return (&smbadm_ptable[i]);
return (NULL);
}
static int
{
if (status != NT_STATUS_SUCCESS) {
gettext("failed to modify the group description (%s)\n"),
return (1);
}
"'%s' description\n"), gname);
return (0);
}
static int
{
if (status != NT_STATUS_SUCCESS) {
gettext("failed to get the %s (%s)\n"),
return (1);
}
return (1);
}
smb_group_free_list(list, 0);
return (0);
}
static int
{
int ret;
} else {
}
if (status == NT_STATUS_SUCCESS) {
ret = 0;
} else {
ret = 1;
}
return (ret);
}
static int
{
if (status != NT_STATUS_SUCCESS) {
return (1);
}
if (priv_attr == SE_PRIVILEGE_ENABLED)
else if (priv_attr == SE_PRIVILEGE_DISABLED)
else
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 *
smbadm_pwd_strerror(int error)
{
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 disable."));
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."));
}
return (gettext("Unknown error code."));
}
/*
* Enable libumem debugging by default on DEBUG builds.
*/
#ifdef DEBUG
/* LINTED - external libumem symbol */
const char *
_umem_debug_init(void)
{
return ("default,verbose"); /* $UMEM_DEBUG setting */
}
/* LINTED - external libumem symbol */
const char *
_umem_logging_init(void)
{
return ("fail,contents"); /* $UMEM_LOGGING setting */
}
#endif