Skip to content

Commit

Permalink
Empty framework created with a little README what's
Browse files Browse the repository at this point in the history
required and how to test functionality.
  • Loading branch information
root committed Dec 15, 2011
1 parent 30a9524 commit cb4f9ea
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/libshare/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ lib_LTLIBRARIES = libshare.la

libshare_la_SOURCES = \
$(top_srcdir)/lib/libshare/libshare.c \
$(top_srcdir)/lib/libshare/nfs.c \
$(top_srcdir)/lib/libshare/libshare_impl.h \
$(top_srcdir)/lib/libshare/nfs.h
$(top_srcdir)/lib/libshare/nfs.c \
$(top_srcdir)/lib/libshare/nfs.h \
$(top_srcdir)/lib/libshare/smb.c \
$(top_srcdir)/lib/libshare/smb.h

libshare_la_LDFLAGS = -version-info 1:0:0
19 changes: 16 additions & 3 deletions lib/libshare/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ am__base_list = \
am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
libshare_la_LIBADD =
am_libshare_la_OBJECTS = libshare.lo nfs.lo
am_libshare_la_OBJECTS = libshare.lo nfs.lo smb.lo
libshare_la_OBJECTS = $(am_libshare_la_OBJECTS)
AM_V_lt = $(am__v_lt_$(V))
am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
Expand Down Expand Up @@ -333,11 +333,14 @@ AM_CFLAGS = -Wall -Wstrict-prototypes -fno-strict-aliasing \
lib_LTLIBRARIES = libshare.la
libshare_la_SOURCES = \
$(top_srcdir)/lib/libshare/libshare.c \
$(top_srcdir)/lib/libshare/nfs.c \
$(top_srcdir)/lib/libshare/libshare_impl.h \
$(top_srcdir)/lib/libshare/nfs.h
$(top_srcdir)/lib/libshare/nfs.c \
$(top_srcdir)/lib/libshare/nfs.h \
$(top_srcdir)/lib/libshare/smb.c \
$(top_srcdir)/lib/libshare/smb.h

libshare_la_LDFLAGS = -version-info 1:0:0

all: all-am

.SUFFIXES:
Expand Down Expand Up @@ -414,6 +417,7 @@ distclean-compile:

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libshare.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nfs.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smb.Plo@am__quote@

.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
Expand Down Expand Up @@ -455,6 +459,15 @@ nfs.lo: $(top_srcdir)/lib/libshare/nfs.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o nfs.lo `test -f '$(top_srcdir)/lib/libshare/nfs.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/libshare/nfs.c

smb.lo: $(top_srcdir)/lib/libshare/smb.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT smb.lo -MD -MP -MF $(DEPDIR)/smb.Tpo -c -o smb.lo `test -f '$(top_srcdir)/lib/libshare/smb.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/libshare/smb.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/smb.Tpo $(DEPDIR)/smb.Plo
@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/libshare/smb.c' object='smb.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o smb.lo `test -f '$(top_srcdir)/lib/libshare/smb.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/libshare/smb.c


mostlyclean-libtool:
-rm -f *.lo

Expand Down
53 changes: 53 additions & 0 deletions lib/libshare/README_smb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
This is basic information about the 'sharesmb' option in ZFS
On Linux by Turbo Fredriksson <[email protected]>.

REQUIRENMENTS
============================================================
1. Samba (doh! :)
* I'm using version 3.3.3, but any 3.x should
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),
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.

5. A ZFS filesystem or more to export.


TESTING
============================================================
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

The first and second command will ask for a root password
and the second (middle) command should give at least one
line.
2 changes: 2 additions & 0 deletions lib/libshare/libshare.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <libshare.h>
#include "libshare_impl.h"
#include "nfs.h"
#include "smb.h"

static sa_share_impl_t find_share(sa_handle_impl_t handle,
const char *sharepath);
Expand Down Expand Up @@ -103,6 +104,7 @@ __attribute__((constructor)) static void
libshare_init(void)
{
libshare_nfs_init();
libshare_smb_init();

/*
* This bit causes /etc/dfs/sharetab to be updated before libzfs gets a
Expand Down
153 changes: 153 additions & 0 deletions lib/libshare/smb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* 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
* or http://www.opensolaris.org/os/licensing.
* 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 (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011 Turbo Fredriksson <[email protected]>
*
* This is an addition to the zfs device driver to add, modify and remove SMB
* shares using the 'net share' command that comes with Samba.
*/

#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <unistd.h>
#include <libzfs.h>
#include <libshare.h>
#include "libshare_impl.h"
#include "smb.h"

static sa_fstype_t *smb_fstype;
boolean_t smb_available;

int
smb_enable_share_one(void)
{
fprintf(stderr, "smb_enable_share_one()\n");
return 0;
}

int
smb_enable_share(sa_share_impl_t impl_share)
{
fprintf(stderr, "smb_enable_share()\n");
return 0;
}

int
smb_disable_share_one(void)
{
fprintf(stderr, "smb_disable_share_one()\n");
return 0;
}

int
smb_disable_share(sa_share_impl_t impl_share)
{
fprintf(stderr, "smb_disable_share()\n");
return 0;
}

static boolean_t
smb_is_share_active(sa_share_impl_t impl_share)
{
fprintf(stderr, "smb_is_share_active()\n");
return 0;
}

static int
smb_validate_shareopts(const char *shareopts)
{
/* TODO: implement */
return 0;
}

static int
smb_update_shareopts(sa_share_impl_t impl_share, const char *resource,
const char *shareopts)
{
char *shareopts_dup;
boolean_t needs_reshare = B_FALSE;
char *old_shareopts;
fprintf(stderr, "smb_update_shareopts()\n");

FSINFO(impl_share, smb_fstype)->active = smb_is_share_active(impl_share);

old_shareopts = FSINFO(impl_share, smb_fstype)->shareopts;

if (FSINFO(impl_share, smb_fstype)->active && old_shareopts != NULL &&
strcmp(old_shareopts, shareopts) != 0) {
needs_reshare = B_TRUE;
smb_disable_share(impl_share);
}

shareopts_dup = strdup(shareopts);

if (shareopts_dup == NULL)
return SA_NO_MEMORY;

if (old_shareopts != NULL)
free(old_shareopts);

FSINFO(impl_share, smb_fstype)->shareopts = shareopts_dup;

if (needs_reshare)
smb_enable_share(impl_share);

return 0;
}

static void
smb_clear_shareopts(sa_share_impl_t impl_share)
{
fprintf(stderr, "smb_clear_shareopts()\n");
free(FSINFO(impl_share, smb_fstype)->shareopts);
FSINFO(impl_share, smb_fstype)->shareopts = NULL;
}

static const sa_share_ops_t smb_shareops = {
.enable_share = smb_enable_share,
.disable_share = smb_disable_share,

.validate_shareopts = smb_validate_shareopts,
.update_shareopts = smb_update_shareopts,
.clear_shareopts = smb_clear_shareopts,
};

int
smb_retrieve_shares(void)
{
fprintf(stderr, " smb_retrieve_shares()\n");
return 1;
}

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

smb_fstype = register_fstype("smb", &smb_shareops);
}
27 changes: 27 additions & 0 deletions lib/libshare/smb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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
* or http://www.opensolaris.org/os/licensing.
* 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 (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011 Turbo Fredriksson <[email protected]>.
*/

void libshare_smb_init(void);

0 comments on commit cb4f9ea

Please sign in to comment.