libshare/smb: cleanup

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13165
This commit is contained in:
наб 2022-02-28 13:13:10 +01:00 committed by Brian Behlendorf
parent 566e4a58b7
commit 2faf05612f
5 changed files with 34 additions and 54 deletions

View File

@ -23,20 +23,9 @@
* Copyright (c) 2020 by Delphix. All rights reserved. * Copyright (c) 2020 by Delphix. All rights reserved.
*/ */
#include <time.h>
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <libzfs.h>
#include <libshare.h> #include <libshare.h>
#include "libshare_impl.h" #include "libshare_impl.h"
#include "smb.h"
static sa_fstype_t *smb_fstype; static sa_fstype_t *smb_fstype;
@ -47,7 +36,7 @@ static int
smb_enable_share(sa_share_impl_t impl_share) smb_enable_share(sa_share_impl_t impl_share)
{ {
(void) impl_share; (void) impl_share;
fprintf(stderr, "No SMB support in FreeBSD yet.\n"); fputs("No SMB support in FreeBSD yet.\n", stderr);
return (SA_NOT_SUPPORTED); return (SA_NOT_SUPPORTED);
} }
/* /*
@ -57,7 +46,7 @@ static int
smb_disable_share(sa_share_impl_t impl_share) smb_disable_share(sa_share_impl_t impl_share)
{ {
(void) impl_share; (void) impl_share;
fprintf(stderr, "No SMB support in FreeBSD yet.\n"); fputs("No SMB support in FreeBSD yet.\n", stderr);
return (SA_NOT_SUPPORTED); return (SA_NOT_SUPPORTED);
} }
@ -68,7 +57,7 @@ static int
smb_validate_shareopts(const char *shareopts) smb_validate_shareopts(const char *shareopts)
{ {
(void) shareopts; (void) shareopts;
fprintf(stderr, "No SMB support in FreeBSD yet.\n"); fputs("No SMB support in FreeBSD yet.\n", stderr);
return (SA_NOT_SUPPORTED); return (SA_NOT_SUPPORTED);
} }

View File

@ -496,8 +496,8 @@ static int
nfs_commit_shares(void) nfs_commit_shares(void)
{ {
char *argv[] = { char *argv[] = {
"/usr/sbin/exportfs", (char *)"/usr/sbin/exportfs",
"-ra", (char *)"-ra",
NULL NULL
}; };

View File

@ -65,7 +65,7 @@ static boolean_t smb_available(void);
static sa_fstype_t *smb_fstype; static sa_fstype_t *smb_fstype;
smb_share_t *smb_shares; static smb_share_t *smb_shares;
static int smb_disable_share(sa_share_impl_t impl_share); static int smb_disable_share(sa_share_impl_t impl_share);
static boolean_t smb_is_share_active(sa_share_impl_t impl_share); static boolean_t smb_is_share_active(sa_share_impl_t impl_share);
@ -218,46 +218,39 @@ out:
static int static int
smb_enable_share_one(const char *sharename, const char *sharepath) smb_enable_share_one(const char *sharename, const char *sharepath)
{ {
char *argv[10], *pos;
char name[SMB_NAME_MAX], comment[SMB_COMMENT_MAX]; char name[SMB_NAME_MAX], comment[SMB_COMMENT_MAX];
int rc;
/* Support ZFS share name regexp '[[:alnum:]_-.: ]' */ /* Support ZFS share name regexp '[[:alnum:]_-.: ]' */
strlcpy(name, sharename, sizeof (name)); strlcpy(name, sharename, sizeof (name));
name [sizeof (name)-1] = '\0'; for (char *itr = name; *itr != '\0'; ++itr)
switch (*itr) {
pos = name;
while (*pos != '\0') {
switch (*pos) {
case '/': case '/':
case '-': case '-':
case ':': case ':':
case ' ': case ' ':
*pos = '_'; *itr = '_';
} }
++pos;
}
/* /*
* CMD: net -S NET_CMD_ARG_HOST usershare add Test1 /share/Test1 \ * CMD: net -S NET_CMD_ARG_HOST usershare add Test1 /share/Test1 \
* "Comment" "Everyone:F" * "Comment" "Everyone:F"
*/ */
snprintf(comment, sizeof (comment), "Comment: %s", sharepath); snprintf(comment, sizeof (comment), "Comment: %s", sharepath);
argv[0] = NET_CMD_PATH; char *argv[] = {
argv[1] = (char *)"-S"; (char *)NET_CMD_PATH,
argv[2] = NET_CMD_ARG_HOST; (char *)"-S",
argv[3] = (char *)"usershare"; (char *)NET_CMD_ARG_HOST,
argv[4] = (char *)"add"; (char *)"usershare",
argv[5] = (char *)name; (char *)"add",
argv[6] = (char *)sharepath; name,
argv[7] = (char *)comment; (char *)sharepath,
argv[8] = (char *)"Everyone:F"; comment,
argv[9] = NULL; (char *)"Everyone:F",
NULL,
};
rc = libzfs_run_process(argv[0], argv, 0); if (libzfs_run_process(argv[0], argv, 0) < 0)
if (rc < 0)
return (SA_SYSTEM_ERR); return (SA_SYSTEM_ERR);
/* Reload the share file */ /* Reload the share file */
@ -298,20 +291,18 @@ smb_enable_share(sa_share_impl_t impl_share)
static int static int
smb_disable_share_one(const char *sharename) smb_disable_share_one(const char *sharename)
{ {
int rc;
char *argv[7];
/* CMD: net -S NET_CMD_ARG_HOST usershare delete Test1 */ /* CMD: net -S NET_CMD_ARG_HOST usershare delete Test1 */
argv[0] = NET_CMD_PATH; char *argv[] = {
argv[1] = (char *)"-S"; (char *)NET_CMD_PATH,
argv[2] = NET_CMD_ARG_HOST; (char *)"-S",
argv[3] = (char *)"usershare"; (char *)NET_CMD_ARG_HOST,
argv[4] = (char *)"delete"; (char *)"usershare",
argv[5] = (char *)sharename; (char *)"delete",
argv[6] = NULL; (char *)sharename,
NULL,
};
rc = libzfs_run_process(argv[0], argv, 0); if (libzfs_run_process(argv[0], argv, 0) < 0)
if (rc < 0)
return (SA_SYSTEM_ERR); return (SA_SYSTEM_ERR);
else else
return (SA_OK); return (SA_OK);

View File

@ -44,6 +44,4 @@ typedef struct smb_share_s {
struct smb_share_s *next; struct smb_share_s *next;
} smb_share_t; } smb_share_t;
extern smb_share_t *smb_shares;
void libshare_smb_init(void); void libshare_smb_init(void);

View File

@ -27,6 +27,8 @@
#ifndef _LIBSPL_LIBSHARE_H #ifndef _LIBSPL_LIBSHARE_H
#define _LIBSPL_LIBSHARE_H extern __attribute__((visibility("default"))) #define _LIBSPL_LIBSHARE_H extern __attribute__((visibility("default")))
#include <sys/types.h>
/* API Initialization */ /* API Initialization */
#define SA_INIT_SHARE_API 0x0001 /* init share specific interface */ #define SA_INIT_SHARE_API 0x0001 /* init share specific interface */
#define SA_INIT_CONTROL_API 0x0002 /* init control specific interface */ #define SA_INIT_CONTROL_API 0x0002 /* init control specific interface */