smbadm.c revision 3db3f65c6274eb042354801a308c8e9bc4994553
/*
* 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 2008 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>
typedef enum {
#define SMBADM_CMDF_USER 0x01
#define SMBADM_CMDF_GROUP 0x02
#define SMBADM_CMDF_TYPEMASK 0x0F
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 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:
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;
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_join
*
*/
static int
{
char option;
char curdom[MAXHOSTNAMELEN];
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);
}
if (smb_config_get_secmode() == SMB_SECMODE_DOMAIN) {
char reply[8];
"joined to '%s' domain.\n"
"Would you like to join the new domain "
curdom);
(void) trim_whitespace(reply);
return (0);
}
}
/* 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 domain[MAXHOSTNAMELEN];
char modename[16];
int rc;
if (rc != SMBD_SMF_OK) {
gettext("failed to get the security mode\n"));
return (1);
}
modename);
return (1);
}
return (0);
}
/*
* smbadm_group_create
*
* Creates a local SMB group
*/
static int
{
char option;
int status;
switch (option) {
case 'd':
break;
default:
}
}
}
return (1);
}
if (status != SMB_LGRP_SUCCESS) {
gettext("failed to create the group (%s)\n"),
} else {
gname);
}
return (status);
}
/*
* smbadm_group_dump_members
*
* Dump group members details.
*/
static void
{
char sidstr[SMB_SID_STRSZ];
int i;
if (num == 0) {
return;
}
for (i = 0; i < num; i++) {
*sidstr = '\0';
sizeof (sidstr)) == NT_STATUS_SUCCESS)
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
{
char sidstr[SMB_SID_STRSZ];
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);
}
gettext("failed to list groups (%s)\n"),
return (status);
}
smb_lgrp_free(&grp);
}
if (status != SMB_LGRP_NO_MORE) {
gettext("failed to get all the groups (%s)\n"),
return (status);
}
return (0);
}
/*
* smbadm_group_delete
*/
static int
{
int status;
}
if (status != SMB_LGRP_SUCCESS) {
gettext("failed to delete the group (%s)\n"),
} else {
gname);
}
return (status);
}
/*
* smbadm_group_rename
*/
static int
{
int status;
}
}
return (1);
}
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 status;
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;
gettext("failed to add %s "
"(could not obtain the SID)\n"),
mname[i]);
continue;
}
if (status != SMB_LGRP_SUCCESS) {
gettext("failed to add %s (%s)\n"),
ret = 1;
} else {
}
}
return (ret);
}
/*
* smbadm_group_delmember
*/
static int
{
char **mname;
char option;
int status;
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;
gettext("failed to remove %s "
"(could not obtain the SID)\n"),
mname[i]);
continue;
}
if (status != SMB_LGRP_SUCCESS) {
gettext("failed to remove %s (%s)\n"),
ret = 1;
} else {
(void) printf(
gettext("'%s' has been removed 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 ret;
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/-? */
}
if ((ret = smbadm_init()) != 0)
return (ret);
smbadm_fini();
return (ret);
}
}
return (2);
}
static int
smbadm_init(void)
{
int rc;
case SMBADM_CMDF_GROUP:
if (smb_idmap_start() != 0) {
gettext("failed to contact idmap service\n"));
return (1);
}
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
{
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
{
int status;
if (status != SMB_LGRP_SUCCESS) {
gettext("failed to modify the group description (%s)\n"),
return (1);
}
"'%s' description\n"), gname);
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 *
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."));
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