Patch: FHS-compliant reorganization of 'lock files'

Steve Langasek vorlon at netexpress.net
Wed Feb 6 16:22:02 GMT 2002


Many thanks to Tim, Alexander and Jean-François for their help in 
helping to ID the various files currently floating around in the 
Samba lockdir.

I'm including below a patch against SAMBA_2_2 that attempts to ensure
that --with-fhs really gives the user FHS compatibility.  This patch is 
*not* ready to be applied to the CVS tree, as there are no provisions 
yet for moving existing tdb files to their new locations at install 
time.  However, I'm posting it here in the hopes of getting some 
feedback from the Samba Team regarding how they would like to see this 
handled.  Currently, the patch takes a barebones approach, hardcoding 
the CACHEDIR and STATEDIR values relative to VARDIR.  Would it be 
preferable to make this more configurable, with corresponding 'state 
directory' and 'cache directory' smb.conf directives and AC_ARG_WITH 
settings?  If so, what would the desired behavior be where --with-fhs is 
not declared?

Once there's a consensus regarding the shape of this code, I'll start 
looking at the install scripts to find a migration path for existing 
installs.

Cheers,
Steve Langasek
postmodern programmer

Index: Makefile.in
===================================================================
RCS file: /cvsroot/samba/source/Makefile.in,v
retrieving revision 1.227.2.107
diff -u -w -r1.227.2.107 Makefile.in
--- Makefile.in	31 Jan 2002 21:46:34 -0000	1.227.2.107
+++ Makefile.in	6 Feb 2002 23:56:13 -0000
@@ -79,7 +79,7 @@
 FLAGS1 = $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/smbwrapper $(CPPFLAGS) -DLOGFILEBASE=\"$(LOGFILEBASE)\"
 FLAGS2 = -DCONFIGFILE=\"$(CONFIGFILE)\" -DLMHOSTSFILE=\"$(LMHOSTSFILE)\"  
 FLAGS3 = -DSWATDIR=\"$(SWATDIR)\" -DSBINDIR=\"$(SBINDIR)\" -DLOCKDIR=\"$(LOCKDIR)\" -DCODEPAGEDIR=\"$(CODEPAGEDIR)\"
-FLAGS4 = -DDRIVERFILE=\"$(DRIVERFILE)\" -DBINDIR=\"$(BINDIR)\" 
+FLAGS4 = -DDRIVERFILE=\"$(DRIVERFILE)\" -DBINDIR=\"$(BINDIR)\" -DVARDIR=\"$(VARDIR)\"
 FLAGS5 = $(FLAGS1) $(FLAGS2) $(FLAGS3) $(FLAGS4) -DHAVE_INCLUDES_H
 FLAGS  = $(ISA) $(FLAGS5) $(PASSWD_FLAGS)
 FLAGS32  = $(ISA32) $(FLAGS5) $(PASSWD_FLAGS)
Index: acconfig.h
===================================================================
RCS file: /cvsroot/samba/source/acconfig.h,v
retrieving revision 1.44.4.32
diff -u -w -r1.44.4.32 acconfig.h
--- acconfig.h	11 Jan 2002 02:28:45 -0000	1.44.4.32
+++ acconfig.h	6 Feb 2002 23:56:13 -0000
@@ -173,3 +173,4 @@
 #undef HAVE_DEVICE_MAJOR_FN
 #undef HAVE_DEVICE_MINOR_FN
 #undef HAVE_MAKEDEV_FN
+#undef FHS_COMPATIBLE
Index: configure.in
===================================================================
RCS file: /cvsroot/samba/source/configure.in,v
retrieving revision 1.130.4.112
diff -u -w -r1.130.4.112 configure.in
--- configure.in	6 Feb 2002 00:23:52 -0000	1.130.4.112
+++ configure.in	6 Feb 2002 23:56:13 -0000
@@ -12,10 +12,11 @@
 [  --with-fhs              Use FHS-compliant paths (default=no)],
     codepagedir="\$(DATADIR)/samba/codepages"
     configdir="${sysconfdir}/samba"
-    lockdir="\${VARDIR}/cache/samba"
+    lockdir="\${VARDIR}/run/samba"
     logfilebase="\${VARDIR}/log/samba"
     privatedir="\${CONFIGDIR}/private"
-    swatdir="\${DATADIR}/samba/swat",
+    swatdir="\${DATADIR}/samba/swat"
+    AC_DEFINE(FHS_COMPATIBLE),
     codepagedir="\$(LIBDIR)/codepages"
     configdir="\$(LIBDIR)"
     lockdir="\$(VARDIR)/locks"
Index: include/config.h.in
===================================================================
RCS file: /cvsroot/samba/source/include/config.h.in,v
retrieving revision 1.83.4.53
diff -u -w -r1.83.4.53 config.h.in
--- include/config.h.in	5 Feb 2002 03:33:42 -0000	1.83.4.53
+++ include/config.h.in	6 Feb 2002 23:56:13 -0000
@@ -236,6 +236,7 @@
 #undef HAVE_DEVICE_MAJOR_FN
 #undef HAVE_DEVICE_MINOR_FN
 #undef HAVE_MAKEDEV_FN
+#undef FHS_COMPATIBLE
 
 /* The number of bytes in a int.  */
 #undef SIZEOF_INT
Index: include/local.h
===================================================================
RCS file: /cvsroot/samba/source/include/local.h,v
retrieving revision 1.54.4.7
diff -u -w -r1.54.4.7 local.h
--- include/local.h	14 Jan 2002 19:31:38 -0000	1.54.4.7
+++ include/local.h	6 Feb 2002 23:56:13 -0000
@@ -189,4 +189,20 @@
 /* Allocation roundup. */
 #define SMB_ROUNDUP_ALLOCATION_SIZE 0x100000
 
+/* FHS-compatible directory defines */
+#ifdef FHS_COMPATIBLE
+#ifndef CACHEDIR
+#define CACHEDIR VARDIR "/cache/samba"
+#endif
+#ifndef STATEDIR
+#define STATEDIR VARDIR "/lib/samba"
+#endif
+
+#else
+
+#define CACHEDIR lp_lockdir()
+#define STATEDIR lp_lockdir()
+
+#endif
+
 #endif
Index: lib/util.c
===================================================================
RCS file: /cvsroot/samba/source/lib/util.c,v
retrieving revision 1.287.4.42
diff -u -w -r1.287.4.42 util.c
--- lib/util.c	31 Jan 2002 22:33:18 -0000	1.287.4.42
+++ lib/util.c	6 Feb 2002 23:56:13 -0000
@@ -1780,6 +1780,47 @@
 	return fname;
 }
 
+/*****************************************************************
+a useful function for returning a path in the Samba state directory
+ *****************************************************************/  
+char *state_path(char *name)
+{
+	static pstring fname;
+
+	pstrcpy(fname,STATEDIR);
+	trim_string(fname,"","/");
+
+	if (!directory_exist(fname,NULL)) {
+		mkdir(fname,0755);
+	}
+
+	pstrcat(fname,"/");
+	pstrcat(fname,name);
+
+	return fname;
+}
+
+/*****************************************************************
+a useful function for returning a path in the Samba cache directory
+ *****************************************************************/  
+char *cache_path(char *name)
+{
+	static pstring fname;
+
+	pstrcpy(fname,CACHEDIR);
+	trim_string(fname,"","/");
+
+	if (!directory_exist(fname,NULL)) {
+		mkdir(fname,0755);
+	}
+
+	pstrcat(fname,"/");
+	pstrcat(fname,name);
+
+	return fname;
+}
+
+
 /*******************************************************************
  Given a filename - get its directory name
  NB: Returned in static storage.  Caveats:
Index: nmbd/nmbd_serverlistdb.c
===================================================================
RCS file: /cvsroot/samba/source/nmbd/nmbd_serverlistdb.c,v
retrieving revision 1.13.6.4
diff -u -w -r1.13.6.4 nmbd_serverlistdb.c
--- nmbd/nmbd_serverlistdb.c	18 Jan 2002 02:30:33 -0000	1.13.6.4
+++ nmbd/nmbd_serverlistdb.c	6 Feb 2002 23:56:13 -0000
@@ -348,7 +348,7 @@
 
   updatecount++;
     
-  pstrcpy(fname,lp_lockdir());
+  pstrcpy(fname,CACHEDIR);
   trim_string(fname,NULL,"/");
   pstrcat(fname,"/");
   pstrcat(fname,SERVER_LIST);
Index: nmbd/nmbd_winsserver.c
===================================================================
RCS file: /cvsroot/samba/source/nmbd/nmbd_winsserver.c,v
retrieving revision 1.38.4.6
diff -u -w -r1.38.4.6 nmbd_winsserver.c
--- nmbd/nmbd_winsserver.c	27 Dec 2001 06:34:46 -0000	1.38.4.6
+++ nmbd/nmbd_winsserver.c	6 Feb 2002 23:56:13 -0000
@@ -180,7 +180,7 @@
 
   add_samba_names_to_subnet(wins_server_subnet);
 
-  if((fp = sys_fopen(lock_path(WINS_LIST),"r")) == NULL)
+  if((fp = sys_fopen(state_path(WINS_LIST),"r")) == NULL)
   {
     DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n",
            WINS_LIST, strerror(errno) ));
Index: nsswitch/winbindd_cache.c
===================================================================
RCS file: /cvsroot/samba/source/nsswitch/winbindd_cache.c,v
retrieving revision 1.5.4.7
diff -u -w -r1.5.4.7 winbindd_cache.c
--- nsswitch/winbindd_cache.c	22 Nov 2001 07:24:39 -0000	1.5.4.7
+++ nsswitch/winbindd_cache.c	6 Feb 2002 23:56:13 -0000
@@ -41,7 +41,7 @@
 {
 	/* Open tdb cache */
 
-	if (!(cache_tdb = tdb_open_log(lock_path("winbindd_cache.tdb"), 0, 
+	if (!(cache_tdb = tdb_open_log(cache_path("winbindd_cache.tdb"), 0, 
 				   TDB_NOLOCK, O_RDWR | O_CREAT | O_TRUNC, 
 				   0600)))
 		DEBUG(0, ("Unable to open tdb cache - user and group caching disabled\n"));
Index: nsswitch/winbindd_idmap.c
===================================================================
RCS file: /cvsroot/samba/source/nsswitch/winbindd_idmap.c,v
retrieving revision 1.3.4.7
diff -u -w -r1.3.4.7 winbindd_idmap.c
--- nsswitch/winbindd_idmap.c	19 Jan 2002 20:16:40 -0000	1.3.4.7
+++ nsswitch/winbindd_idmap.c	6 Feb 2002 23:56:13 -0000
@@ -215,7 +215,7 @@
 {
     /* Open tdb cache */
 
-    if (!(idmap_tdb = tdb_open_log(lock_path("winbindd_idmap.tdb"), 0,
+    if (!(idmap_tdb = tdb_open_log(state_path("winbindd_idmap.tdb"), 0,
                                TDB_NOLOCK, O_RDWR | O_CREAT, 0600))) {
         DEBUG(0, ("Unable to open idmap database\n"));
         return False;
Index: printing/nt_printing.c
===================================================================
RCS file: /cvsroot/samba/source/printing/nt_printing.c,v
retrieving revision 1.96.2.99
diff -u -w -r1.96.2.99 nt_printing.c
--- printing/nt_printing.c	1 Feb 2002 20:54:47 -0000	1.96.2.99
+++ printing/nt_printing.c	6 Feb 2002 23:56:13 -0000
@@ -240,24 +240,24 @@
 	if (tdb_drivers && tdb_printers && tdb_forms && local_pid == sys_getpid())
 		return True;
  
-	tdb_drivers = tdb_open_log(lock_path("ntdrivers.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+	tdb_drivers = tdb_open_log(state_path("ntdrivers.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
 	if (!tdb_drivers) {
 		DEBUG(0,("nt_printing_init: Failed to open nt drivers database %s (%s)\n",
-			lock_path("ntdrivers.tdb"), strerror(errno) ));
+			state_path("ntdrivers.tdb"), strerror(errno) ));
 		return False;
 	}
  
-	tdb_printers = tdb_open_log(lock_path("ntprinters.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+	tdb_printers = tdb_open_log(state_path("ntprinters.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
 	if (!tdb_printers) {
 		DEBUG(0,("nt_printing_init: Failed to open nt printers database %s (%s)\n",
-			lock_path("ntprinters.tdb"), strerror(errno) ));
+			state_path("ntprinters.tdb"), strerror(errno) ));
 		return False;
 	}
  
-	tdb_forms = tdb_open_log(lock_path("ntforms.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+	tdb_forms = tdb_open_log(state_path("ntforms.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
 	if (!tdb_forms) {
 		DEBUG(0,("nt_printing_init: Failed to open nt forms database %s (%s)\n",
-			lock_path("ntforms.tdb"), strerror(errno) ));
+			state_path("ntforms.tdb"), strerror(errno) ));
 		return False;
 	}
  
Index: printing/printing.c
===================================================================
RCS file: /cvsroot/samba/source/printing/printing.c,v
retrieving revision 1.71.2.53
diff -u -w -r1.71.2.53 printing.c
--- printing/printing.c	9 Jan 2002 04:40:36 -0000	1.71.2.53
+++ printing/printing.c	6 Feb 2002 23:56:13 -0000
@@ -54,7 +54,7 @@
 	char *sversion = "INFO/version";
 
 	if (tdb && local_pid == sys_getpid()) return True;
-	tdb = tdb_open_log(lock_path("printing.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+	tdb = tdb_open_log(cache_path("printing.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
 	if (!tdb) {
 		DEBUG(0,("print_backend_init: Failed to open printing backend database. Error = [%s]\n",
 				 tdb_errorstr(tdb)));
Index: rpc_server/srv_srvsvc_nt.c
===================================================================
RCS file: /cvsroot/samba/source/rpc_server/srv_srvsvc_nt.c,v
retrieving revision 1.1.2.55
diff -u -w -r1.1.2.55 srv_srvsvc_nt.c
--- rpc_server/srv_srvsvc_nt.c	9 Jan 2002 05:24:05 -0000	1.1.2.55
+++ rpc_server/srv_srvsvc_nt.c	6 Feb 2002 23:56:14 -0000
@@ -127,10 +127,10 @@
  
 	if (share_tdb && local_pid == sys_getpid())
 		return True;
-	share_tdb = tdb_open_log(lock_path("share_info.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+	share_tdb = tdb_open_log(state_path("share_info.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
 	if (!share_tdb) {
 		DEBUG(0,("Failed to open share info database %s (%s)\n",
-			lock_path("share_info.tdb"), strerror(errno) ));
+			state_path("share_info.tdb"), strerror(errno) ));
 		return False;
 	}
  

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20020206/bc34c874/attachment.bin


More information about the samba-technical mailing list