Skip to content

Commit

Permalink
15976 List users connected via SMB
Browse files Browse the repository at this point in the history
Reviewed by: Gordon Ross <gwr@racktopsystems.com>
Reviewed by: Matt Barden <mbarden@racktopsystems.com>
Approved by: Robert Mustacchi <rm@fingolfin.org>
  • Loading branch information
Jason King authored and tsoome committed Apr 19, 2024
1 parent 34bbc83 commit 821b358
Show file tree
Hide file tree
Showing 5 changed files with 937 additions and 33 deletions.
5 changes: 4 additions & 1 deletion usr/src/cmd/smbsrv/smbadm/Makefile
Expand Up @@ -33,7 +33,10 @@ include ../../Makefile.cmd
include ../../Makefile.ctf
include ../Makefile.smbsrv.defs

LDLIBS += -L$(ROOT)/usr/lib/smbsrv -lsmb -lsmbns -lsecdb -lumem
OBJS= smbadm.o smbinfo.o

LDLIBS += -L$(ROOT)/usr/lib/smbsrv -lsmb -lsmbns \
-lsecdb -lofmt -lcmdutils -lumem
LDFLAGS += -R/usr/lib/smbsrv

.KEEP_STATE:
Expand Down
84 changes: 66 additions & 18 deletions usr/src/cmd/smbsrv/smbadm/smbadm.c
Expand Up @@ -48,6 +48,7 @@
#include <locale.h>
#include <smbsrv/libsmb.h>
#include <smbsrv/libsmbns.h>
#include "smbadm.h"

#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
Expand All @@ -61,6 +62,12 @@ typedef enum {
HELP_GET,
HELP_JOIN,
HELP_LIST,
HELP_LIST_DOMAINS,
HELP_LIST_SESS,
HELP_LIST_TREES,
HELP_LIST_OFILES,
HELP_CLOSE_SESS,
HELP_CLOSE_OFILE,
HELP_LOOKUP,
HELP_RENAME,
HELP_SET,
Expand All @@ -71,8 +78,9 @@ typedef enum {
} smbadm_help_t;

#define SMBADM_CMDF_NONE 0x00
#define SMBADM_CMDF_USER 0x01
#define SMBADM_CMDF_GROUP 0x02
#define SMBADM_CMDF_USER 0x01 /* needs smb_pwd_init */
#define SMBADM_CMDF_GROUP 0x02 /* needs smb_lgrp_start */
#define SMBADM_CMDF_KMOD 0x04 /* needs smb_kmod_bind */
#define SMBADM_CMDF_TYPEMASK 0x0F

typedef enum {
Expand Down Expand Up @@ -153,8 +161,22 @@ static smbadm_cmdinfo_t smbadm_cmdtable[] =
SMBADM_CMDF_USER, SMBADM_ACTION_AUTH },
{ "join", smbadm_join, HELP_JOIN,
SMBADM_CMDF_GROUP, SMBADM_VALUE_AUTH },
/* "list" is now an alias for "list-domains" */
{ "list", smbadm_list, HELP_LIST,
SMBADM_CMDF_NONE, SMBADM_BASIC_AUTH },
{ "list-domains", smbadm_list, HELP_LIST_DOMAINS,
SMBADM_CMDF_NONE, SMBADM_BASIC_AUTH },

{ "list-sessions", cmd_list_sess, HELP_LIST_SESS,
SMBADM_CMDF_KMOD, SMBADM_BASIC_AUTH },
{ "list-trees", cmd_list_trees, HELP_LIST_TREES,
SMBADM_CMDF_KMOD, SMBADM_BASIC_AUTH },
{ "list-ofiles", cmd_list_ofiles, HELP_LIST_OFILES,
SMBADM_CMDF_KMOD, SMBADM_BASIC_AUTH },
{ "close-session", cmd_close_sess, HELP_CLOSE_SESS,
SMBADM_CMDF_KMOD, SMBADM_BASIC_AUTH },
{ "close-ofile", cmd_close_ofile, HELP_CLOSE_OFILE,
SMBADM_CMDF_KMOD, SMBADM_BASIC_AUTH },
{ "lookup", smbadm_lookup, HELP_LOOKUP,
SMBADM_CMDF_NONE, SMBADM_BASIC_AUTH },
};
Expand Down Expand Up @@ -260,9 +282,31 @@ smbadm_cmdusage(FILE *fp, smbadm_cmdinfo_t *cmd)
return;

case HELP_LIST:
(void) fprintf(fp, gettext(
"\t%s (alias for list-domains)\n"), cmd->name);
return;

case HELP_LIST_DOMAINS:
(void) fprintf(fp, gettext("\t%s\n"), cmd->name);
return;

case HELP_LIST_SESS:
case HELP_LIST_TREES:
case HELP_LIST_OFILES:
(void) fprintf(fp, gettext(
"\t%s [-p] [-o field,...]\n"), cmd->name);
return;

case HELP_CLOSE_SESS:
(void) fprintf(fp, gettext(
"\t%s <client_name> [user_name]\n"), cmd->name);
return;

case HELP_CLOSE_OFILE:
(void) fprintf(fp, gettext("\t%s <File_ID>\n"), cmd->name);
return;


case HELP_LOOKUP:
(void) fprintf(fp,
gettext("\t%s <account-name>\n"),
Expand Down Expand Up @@ -1711,22 +1755,26 @@ smbadm_init(void)
{
int rc;

switch (curcmd->flags & SMBADM_CMDF_TYPEMASK) {
case SMBADM_CMDF_GROUP:
if ((curcmd->flags & SMBADM_CMDF_KMOD) != 0) {
if ((rc = smb_kmod_bind(B_FALSE)) != 0) {
(void) fprintf(stderr,
gettext("failed to open driver (%s)\n"),
strerror(rc));
return (1);
}
}

if ((curcmd->flags & SMBADM_CMDF_GROUP) != 0) {
if ((rc = smb_lgrp_start()) != SMB_LGRP_SUCCESS) {
(void) fprintf(stderr,
gettext("failed to initialize (%s)\n"),
smb_lgrp_strerror(rc));
return (1);
}
break;
}

case SMBADM_CMDF_USER:
if ((curcmd->flags & SMBADM_CMDF_USER) != 0) {
smb_pwd_init(B_FALSE);
break;

default:
break;
}

return (0);
Expand All @@ -1735,17 +1783,17 @@ smbadm_init(void)
static void
smbadm_fini(void)
{
switch (curcmd->flags & SMBADM_CMDF_TYPEMASK) {
case SMBADM_CMDF_GROUP:

if ((curcmd->flags & SMBADM_CMDF_KMOD) != 0) {
smb_kmod_unbind();
}

if ((curcmd->flags & SMBADM_CMDF_GROUP) != 0) {
smb_lgrp_stop();
break;
}

case SMBADM_CMDF_USER:
if ((curcmd->flags & SMBADM_CMDF_USER) != 0) {
smb_pwd_fini();
break;

default:
break;
}
}

Expand Down
38 changes: 38 additions & 0 deletions usr/src/cmd/smbsrv/smbadm/smbadm.h
@@ -0,0 +1,38 @@
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/

/*
* Copyright 2023 RackTop Systems, Inc.
*/

#ifndef _SMBADM_H
#define _SMBADM_H

/*
* Declarations private to the smbadm command
*/

#ifdef __cplusplus
extern "C" {
#endif

/* Commands in smbinfo.c */
extern int cmd_list_sess(int, char **);
extern int cmd_list_trees(int, char **);
extern int cmd_list_ofiles(int, char **);
extern int cmd_close_sess(int, char **);
extern int cmd_close_ofile(int, char **);

#ifdef __cplusplus
}
#endif

#endif /* _SMBADM_H */

0 comments on commit 821b358

Please sign in to comment.