configure-list-all-volumes [plain text]
Index: samba/source/smbd/service.c
===================================================================
--- samba/source/smbd/service.c.orig
+++ samba/source/smbd/service.c
@@ -249,7 +249,14 @@ int add_home_service(const char *service
if (!lp_add_home(service, iHomeService, username, homedir)) {
return -1;
}
-
+ /*
+ * If the user is part of the admin group then the shae
+ * list should include all local volumes.
+ */
+ if ((lp_parm_bool(iHomeService, "com.apple", "show admin all volumes", False)) &&
+ (user_in_group(username, "admin")))
+ apple_clone_local_volumes(iHomeService, username);
+
return lp_servicenumber(service);
}
Index: samba/source/smbd/darwin_clone_local_volumes.c
===================================================================
--- /dev/null
+++ samba/source/smbd/darwin_clone_local_volumes.c
@@ -0,0 +1,107 @@
+/*
+ * Darwin Show all volumes for admin users
+ *
+ * Copyright (c) 2007 Apple Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/* This header has to be here due to preprocessor conflicts with Samba
+ * headers.
+ */
+#include "includes.h"
+#include <sys/attr.h>
+
+#define APPLE_SLASH_VOLUMES "/Volumes"
+
+/*
+ * We have a path to a mounted volume, use getattrlist to get its real name. If
+ * we fail then just use the last component of the path name.
+ */
+static void get_volume_name(const char *path, char *volname)
+{
+ struct attrlist attrlist;
+ char attrbuf[sizeof(struct attrreference) + sizeof(u_int32_t) + NAME_MAX + 1];
+ struct attrreference * data = (struct attrreference *)attrbuf;
+ u_int32_t *nmlen;
+ char *name = NULL;
+ int len, maxlen;
+
+ ZERO_STRUCT(attrlist);
+ ZERO_STRUCT(attrbuf);
+ attrlist.bitmapcount = ATTR_BIT_MAP_COUNT;
+ attrlist.commonattr = ATTR_CMN_NAME;
+ /* Call getattrlist to get the real volume name */
+ if (getattrlist(path, &attrlist, attrbuf, sizeof(attrbuf), 0) != 0) {
+ DEBUG(5, ("getattrlist for %s failed: %s\n", path, strerror(errno)));
+ return;
+ }
+ /* Make sure we didn't get something bad */
+ maxlen = data->attr_dataoffset - (sizeof(struct attrreference) + sizeof(u_int32_t));
+ nmlen = (u_int32_t *)(attrbuf+sizeof(struct attrreference));
+ /* Should never happen, but just to be safe */
+ if (*nmlen > maxlen) {
+ DEBUG(5, ("name length to large for buffer nmlen = %d maxlen = %d\n", nmlen, maxlen));
+ return;
+ }
+ len = *nmlen++;
+ name = (char *)nmlen;
+ strlcpy(volname, name, NAME_MAX + 1);
+ return;
+}
+
+/*
+ * Get all the mounted volumes and search for local volumes that are either the root mount
+ * point or have been mounted under /Volumes. Call getattrlist to get the real volume name
+ * to display in the share list.
+ */
+void apple_clone_local_volumes(int iHomeService, const char *username)
+{
+ struct statfs *sb, *stat_p = NULL;
+ int n = getfsstat(NULL, 0, MNT_NOWAIT);
+ char volname[NAME_MAX + 1];
+ int ii;
+
+ if (n <= 0) /* nothing to do just return */
+ goto out;
+
+ stat_p = (struct statfs *)SMB_MALLOC(n * sizeof(*stat_p));
+ if (stat_p == NULL) /* nothing to do just return */
+ goto out;
+
+ /* Never wait gettng the list of mounted volumes */
+ if (getfsstat(stat_p, n * sizeof(*stat_p), MNT_NOWAIT) <= 0)
+ goto out;
+
+ sb = stat_p;
+ for (ii=0; ii < n; ii++) {
+ /* Must be local mount and either the root volume or mount under /Volumes */
+ if ((sb->f_flags & MNT_LOCAL) && ((sb->f_flags & MNT_DONTBROWSE) != MNT_DONTBROWSE) &&
+ ((strncmp(sb->f_mntonname, "/", 2) == 0) ||
+ (strncmp(sb->f_mntonname, APPLE_SLASH_VOLUMES, strlen(APPLE_SLASH_VOLUMES)) == 0))) {
+
+ get_volume_name(sb->f_mntonname, volname);
+ if (lp_add_home(volname, iHomeService, username, sb->f_mntonname))
+ DEBUG(5,("Sharing %s with path = %s\n", volname, sb->f_mntonname));
+ else
+ DEBUG(5,("Failed to sharing %s with path = %s\n", volname, sb->f_mntonname));
+ }
+ sb++;
+ }
+
+out:
+ /* Clean up */
+ SAFE_FREE(stat_p);
+}
Index: samba/source/Makefile.in
===================================================================
--- samba/source/Makefile.in.orig
+++ samba/source/Makefile.in
@@ -480,6 +480,7 @@ SMBD_OBJ_SRV = smbd/files.o smbd/chgpass
smbd/change_trust_pw.o smbd/fake_file.o \
smbd/quotas.o smbd/ntquotas.o $(AFS_OBJ) smbd/msdfs.o \
$(AFS_SETTOKEN_OBJ) smbd/aio.o smbd/statvfs.o \
+ smbd/darwin_clone_local_volumes.o \
smbd/dmapi.o lib/opendirectory.o \
lib/launchd.o smbd/sockinit.o \
$(MANGLE_OBJ) @VFS_STATIC@