From 2faf05612f9172f4c02245cdfcca6b62a3e5f527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Mon, 28 Feb 2022 13:13:10 +0100 Subject: [PATCH] libshare/smb: cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia ZiemiaƄska Closes #13165 --- lib/libshare/os/freebsd/smb.c | 17 ++-------- lib/libshare/os/linux/nfs.c | 4 +-- lib/libshare/os/linux/smb.c | 63 +++++++++++++++-------------------- lib/libshare/smb.h | 2 -- lib/libspl/include/libshare.h | 2 ++ 5 files changed, 34 insertions(+), 54 deletions(-) diff --git a/lib/libshare/os/freebsd/smb.c b/lib/libshare/os/freebsd/smb.c index 445784b75..f14e631b2 100644 --- a/lib/libshare/os/freebsd/smb.c +++ b/lib/libshare/os/freebsd/smb.c @@ -23,20 +23,9 @@ * Copyright (c) 2020 by Delphix. All rights reserved. */ -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include "libshare_impl.h" -#include "smb.h" static sa_fstype_t *smb_fstype; @@ -47,7 +36,7 @@ static int smb_enable_share(sa_share_impl_t 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); } /* @@ -57,7 +46,7 @@ static int smb_disable_share(sa_share_impl_t 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); } @@ -68,7 +57,7 @@ static int smb_validate_shareopts(const char *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); } diff --git a/lib/libshare/os/linux/nfs.c b/lib/libshare/os/linux/nfs.c index 5acfa3fb8..72653b6d4 100644 --- a/lib/libshare/os/linux/nfs.c +++ b/lib/libshare/os/linux/nfs.c @@ -496,8 +496,8 @@ static int nfs_commit_shares(void) { char *argv[] = { - "/usr/sbin/exportfs", - "-ra", + (char *)"/usr/sbin/exportfs", + (char *)"-ra", NULL }; diff --git a/lib/libshare/os/linux/smb.c b/lib/libshare/os/linux/smb.c index 47d1aa776..f4a0bfd6b 100644 --- a/lib/libshare/os/linux/smb.c +++ b/lib/libshare/os/linux/smb.c @@ -65,7 +65,7 @@ static boolean_t smb_available(void); 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 boolean_t smb_is_share_active(sa_share_impl_t impl_share); @@ -218,46 +218,39 @@ out: static int smb_enable_share_one(const char *sharename, const char *sharepath) { - char *argv[10], *pos; char name[SMB_NAME_MAX], comment[SMB_COMMENT_MAX]; - int rc; /* Support ZFS share name regexp '[[:alnum:]_-.: ]' */ strlcpy(name, sharename, sizeof (name)); - name [sizeof (name)-1] = '\0'; - - pos = name; - while (*pos != '\0') { - switch (*pos) { + for (char *itr = name; *itr != '\0'; ++itr) + switch (*itr) { case '/': case '-': case ':': case ' ': - *pos = '_'; + *itr = '_'; } - ++pos; - } - /* * CMD: net -S NET_CMD_ARG_HOST usershare add Test1 /share/Test1 \ * "Comment" "Everyone:F" */ snprintf(comment, sizeof (comment), "Comment: %s", sharepath); - argv[0] = NET_CMD_PATH; - argv[1] = (char *)"-S"; - argv[2] = NET_CMD_ARG_HOST; - argv[3] = (char *)"usershare"; - argv[4] = (char *)"add"; - argv[5] = (char *)name; - argv[6] = (char *)sharepath; - argv[7] = (char *)comment; - argv[8] = (char *)"Everyone:F"; - argv[9] = NULL; + char *argv[] = { + (char *)NET_CMD_PATH, + (char *)"-S", + (char *)NET_CMD_ARG_HOST, + (char *)"usershare", + (char *)"add", + name, + (char *)sharepath, + comment, + (char *)"Everyone:F", + NULL, + }; - rc = libzfs_run_process(argv[0], argv, 0); - if (rc < 0) + if (libzfs_run_process(argv[0], argv, 0) < 0) return (SA_SYSTEM_ERR); /* Reload the share file */ @@ -298,20 +291,18 @@ smb_enable_share(sa_share_impl_t impl_share) static int smb_disable_share_one(const char *sharename) { - int rc; - char *argv[7]; - /* CMD: net -S NET_CMD_ARG_HOST usershare delete Test1 */ - argv[0] = NET_CMD_PATH; - argv[1] = (char *)"-S"; - argv[2] = NET_CMD_ARG_HOST; - argv[3] = (char *)"usershare"; - argv[4] = (char *)"delete"; - argv[5] = (char *)sharename; - argv[6] = NULL; + char *argv[] = { + (char *)NET_CMD_PATH, + (char *)"-S", + (char *)NET_CMD_ARG_HOST, + (char *)"usershare", + (char *)"delete", + (char *)sharename, + NULL, + }; - rc = libzfs_run_process(argv[0], argv, 0); - if (rc < 0) + if (libzfs_run_process(argv[0], argv, 0) < 0) return (SA_SYSTEM_ERR); else return (SA_OK); diff --git a/lib/libshare/smb.h b/lib/libshare/smb.h index 8ea44677f..c45e0aec6 100644 --- a/lib/libshare/smb.h +++ b/lib/libshare/smb.h @@ -44,6 +44,4 @@ typedef struct smb_share_s { struct smb_share_s *next; } smb_share_t; -extern smb_share_t *smb_shares; - void libshare_smb_init(void); diff --git a/lib/libspl/include/libshare.h b/lib/libspl/include/libshare.h index 5d06b163a..0395c2815 100644 --- a/lib/libspl/include/libshare.h +++ b/lib/libspl/include/libshare.h @@ -27,6 +27,8 @@ #ifndef _LIBSPL_LIBSHARE_H #define _LIBSPL_LIBSHARE_H extern __attribute__((visibility("default"))) +#include + /* API Initialization */ #define SA_INIT_SHARE_API 0x0001 /* init share specific interface */ #define SA_INIT_CONTROL_API 0x0002 /* init control specific interface */