Skip to content

Commit

Permalink
Go with usershare instead of systemshare. Less modification
Browse files Browse the repository at this point in the history
to system configs and are easier to list and parse.
  • Loading branch information
root committed Dec 15, 2011
1 parent b5493c8 commit d686384
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 55 deletions.
42 changes: 11 additions & 31 deletions lib/libshare/README_smb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,14 @@ REQUIRENMENTS
probably work. Please update the tracker with
info..

2. The following configuration in smb.conf

add share command = /usr/local/sbin/modify_samba_config.pl
delete share command = /usr/local/sbin/modify_samba_config.pl
change share command = /usr/local/sbin/modify_samba_config.pl

include = /etc/samba/shares.conf-dynamic

The script (modify_samba_config.pl) comes in two
versions, one perl and one python and can be found
in the samba source directory:

./examples/scripts/shares/perl/modify_samba_config.pl
./examples/scripts/shares/python/modify_samba_config.py

Personaly, I choosed the perl version and modified
it slightly - to not overwrite or modify smb.conf,
but instead the /etc/samba/shares.conf-dynamic file,
which is completely managed by the zfs/net commands.

3. Samba will need to listen to 'localhost' (127.0.0.1),
2. Samba will need to listen to 'localhost' (127.0.0.1),
because that is hardcoded into the zfs module/libraries.

4. A workable root password. ZFS is using 'root' as samba
account to add, modify and remove shares so this need
to work.
3. Some configuration settings in samba:

usershare max shares = 100

5. A ZFS filesystem or more to export.
4. A ZFS filesystem or more to export.


TESTING
Expand All @@ -44,10 +24,10 @@ Once configuration in samba have been done, test that this
works with the following commands (in this case, my ZFS
filesystem is called 'share/Test1'):

net -U root -S 127.0.0.1 share add Test1=/share/Test1
net share list | grep -i test
net -U root -S 127.0.0.1 share delete Test1
net -U root -S 127.0.0.1 usershare add Test1 /share/Test1 "Comment: /share/Test1" "Everyone:F"
net usershare list | grep -i test
net -U root -S 127.0.0.1 usershare delete Test1

The first and second command will ask for a root password
and the second (middle) command should give at least one
line.
The first command will create a user share that gives
everyone full access. To limit the access below that,
use normal UNIX commands (chmod, chown etc).
52 changes: 28 additions & 24 deletions lib/libshare/smb.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ strrep(char *str, char old, char new)
int
smb_enable_share_one(const char *sharename, const char *sharepath)
{
char *argv[10], name_path[255], name[255];
char *argv[12], name[255], comment[255];
int rc;

// DEBUG
Expand All @@ -78,27 +78,23 @@ fprintf(stderr, " smb_enable_share_one(%s, %s)\n",
strrep(name, '/', '_');

/*
* CMD: net -U root -S 127.0.0.1 share add Test1=/share/Test1
* CMD: net -U root -S 127.0.0.1 usershare add Test1 /share/Test1 "Comment" "Everyone:F"
*/

snprintf(name_path, sizeof(name_path), "%s=%s", name, sharepath);

argv[0] = "/usr/bin/net";
argv[1] = "-U";
argv[2] = "root";
argv[3] = "-S";
argv[4] = "127.0.0.1";
argv[5] = "share";
argv[6] = "add";
argv[7] = name_path;
argv[8] = NULL;

int i;
fprintf(stderr, "CMD: ");
for (i=0; i < 8; i++) {
fprintf(stderr, "%s ", argv[i]);
}
fprintf(stderr, "\n");
snprintf(comment, sizeof (comment), "Comment: %s", sharepath);

argv[0] = "/usr/bin/net";
argv[1] = "-U";
argv[2] = "root";
argv[3] = "-S";
argv[4] = "127.0.0.1";
argv[5] = "usershare";
argv[6] = "add";
argv[7] = name;
argv[8] = strdup(sharepath);
argv[9] = comment;
argv[10] = "Everyone:F";
argv[11] = NULL;

rc = libzfs_run_process(argv[0], argv, 0);
if (rc < 0)
Expand Down Expand Up @@ -143,10 +139,15 @@ fprintf(stderr, " smb_enable_share(): -> off (0)\n");
}

int
smb_disable_share_one(void)
smb_disable_share_one(int sid)
{
int rc;
char *argv[6];

// DEBUG
fprintf(stderr, "smb_disable_share_one()\n");
/* CMD: net -U root -S 127.0.0.1 share delete Test1 */

/* CMD: net -U root -S 127.0.0.1 usershare delete Test1 */

return 0;
}
Expand Down Expand Up @@ -179,6 +180,7 @@ smb_update_shareopts(sa_share_impl_t impl_share, const char *resource,
char *shareopts_dup;
boolean_t needs_reshare = B_FALSE;
char *old_shareopts;
// DEBUG
fprintf(stderr, "smb_update_shareopts()\n");

FSINFO(impl_share, smb_fstype)->active = smb_is_share_active(impl_share);
Expand Down Expand Up @@ -210,6 +212,7 @@ fprintf(stderr, "smb_update_shareopts()\n");
static void
smb_clear_shareopts(sa_share_impl_t impl_share)
{
// DEBUG
fprintf(stderr, "smb_clear_shareopts()\n");
free(FSINFO(impl_share, smb_fstype)->shareopts);
FSINFO(impl_share, smb_fstype)->shareopts = NULL;
Expand All @@ -228,17 +231,18 @@ int
smb_retrieve_shares(void)
{
int rc = SA_OK;

// DEBUG
fprintf(stderr, " smb_retrieve_shares()\n");

/* CMD: net share list */
/* CMD: net usershare list -l */

return rc;
}

void
libshare_smb_init(void)
{
// DEBUG
fprintf(stderr, "libshare_smb_init()\n");
smb_available = (smb_retrieve_shares() == SA_OK);

Expand Down

0 comments on commit d686384

Please sign in to comment.