SOC report:Alternative configuration backend

Mingwang mingwxia at gmail.com
Mon Aug 21 04:33:49 GMT 2006


hi,

     This project add libelektra support to SAMBA so that smb.conf can
substitue with a elektra database which provides a registry-like
parameter holder.
And the storage backend behind it can be file system,berkeleydb,ini,etc.Legacy
smb.conf can transfered to elektra database automaticly.
The folowing has done:
	1. elektra database support:
		+parse smb.conf and transfer to elektra backend.
		+dispose smb.conf and use elektra database totally.
		+elektra database can edit with kdbEdit(a visual key/value editor
			from elektra project.)
		+support include in smb.conf and elektra backend.
	2.parameter/service access
		+support all legacy lp_** functions
		+set/get global&service parameter with parameter name/serviceContex
		+add/del service
		+mantain consistency between internal parameter structure
			and elektra storage backend.

The attachement is the whole report. And code availible at
  http://people.samba.org/bzr/mwxia/samba-soc/

-----
Cheers,
Mingwang
-------------- next part --------------
				Alternative SAMBA Configuration Backend Report
					  (SOC2006, mingwxia at gmail.com)            

I Abstract

	This project add libelektra support to SAMBA so that smb.conf can 
substitue with a elektra database which provides a registry-like parameter holder.
And the storage backend behind it can be file system,berkeleydb,ini,etc.Legacy
smb.conf can transfered to elektra database automaticly.


II Implement

	1. elektra database support:
		+parse smb.conf and transfer to elektra backend.
		+dispose smb.conf and use elektra database totally.
		+elektra database can edit with kdbEdit(a visual key/value editor
			from elektra project.)
		+support include in smb.conf and elektra backend.
	2.parameter/service access
		+support all legacy lp_** functions
		+set/get global&service parameter with parameter name/serviceContex
		+add/del service
		+mantain consistency between internal parameter structure
			and elektra storage backend.


III Design

	1. elektra database support

  		1.1 key,keyset,parameter,section

        A key has key name,value,type,comment,etc.Parameter has name and value which
   	corresponse to a key name&value. A section is a service whose key has name and tagged
   	with some specific KDB_TYPE.Key set contains a set of keys.
   		The SAMBA' elektra database has the flowing layout:

			-system/sw/samba/
			   -main/
				  -global/
					 -(workgroup,PLANET)
				  -homes/
					 -(browseable,no)
				  -printers/	  
					 -(public,no)
					 -zinclude_section=%L.conf
			   +include/
				  -MARS.conf
					-public/
						-(path,/mnt/vol1)
						-(public,yes)
					-sales/
						-(path,/mnt/vol2)
				  +VENUS.conf
     The corresponding smb.conf may like this:
			[global]
			workgroup = PLANET
			[homes]
			browseable=no
			[printers]
			public=no
			include = /work/smb/%L.conf
	and MARS.conf:
			[public]
			path = /mnt/vol1
			public = yes
			[sales]
			path = /mnt/vol2

	Notice that include parameter should be placed at end of a section.
        According to the above layout, in the project we call system/sw/samba/main 
	the main keyset which contains all infomation in smb.conf and call 
	system/sw/samba/include the include keyset which contains all include files' 
	infomation.

 		
		 1.2 elektra backend support
   		
		 Elektra backend support are mainly done in param/params:pm_process().See the
	file for reference.

		BOOL pm_process( const char *root,
				BOOL (*sfunc)(const char *),
				BOOL (*pfunc)(const char *, const char *) )

		 The new pm_process() works in two main situation.
	 root = smb.conf:   In this situation, we first parse the file top-down.
                  Add a section key in params_old with type KEY_TYPE_DIR
                  using kdb_importer_sfunc and add a parameter key in
                  params_old with type KEY_TYPE_STRING using
                  kdb_importer_pfunc.
                    A special things is that when an 'include' is find.
                  We first add the key to params_old as normal and then
                  set bInclude and call pm_process to process the specific
                  include file,kdb_importer_sfunc and kdb_importer_pfunc
                  will add keys to include_ks.
                    When processing smb.conf is done,parameter keys in
                  smb.conf are in params_old and include file
                  parameter keys are in include_ks. Then serialize them to
                  elektra backend.
	 root = elektra database:
                   If a elektra key database path(it's denoted as
                   system/sw/samba in elektra) is passed in, we get the
                  system/sw/samba/main key&subkeys which correponse
                  to smb.conf into params_new.
 
    We now get params_old or params_new containing main parameters keys
    as smb.conf does.params_ks is used to point to the valid one.
    The final step:Traverse params_ks to fill internal parameter
    structures using real sfunc(eg:do_section) and pfunc(eg:do_parameter).
    When a 'include' is found, we get the key&subkeys under
    system/sw/samba/include/(specific file name) into include_ks and
    traverse include_ks.

	2 parameter access and service manipulate

		The service and global parameter are get from internal parameter structure
	such as loadparm.c:Globals and loadparm.c:ServicePtrs
		To get service paramer, ServiceCtx are simplely defined as:
				typedef struct serviceCtx{
				   char *serviceName;
				   char *userName;
				   char *clientIp;
				} ServiceCtx;
	which I only used the serviceName to help search parameters in
	registry.For global parameter, a parameter name is needed.
 	   When setting a parameter, we needs to first find the corresponding key and set 
	the key to backend.So first, in the conf/conf.c:kdb_init() main and include keyset
	should be filled.
	   Because there are different type of parameter(string,int,list,etc),a union is
	also defined to hold all type of values.


IV Use

	1. User

	   When starting SAMBA, the first time it need a smb.conf then translated to 
	system/sw/samba/, the next time you can drop smb.conf and start SAMBA as
	smbd -s system/sw/samba.if you want to modified the configuration, a elektra
	GUI tool kdbEdit(http://www.libelektra.org/Image:Kdbedit-signature.png)
	can be used.See file conf/Readme for details.

 	2.Developer:
  		See conf/conf.h and ELEKTRA_DEBUG example code block.
	 	
V Others
		The code is experimental and I found it's more and more interesting as I get in
	it.In the past two months, I'm had a very happy period of time work with my mentor 
	Jerry and other people's from samba team.I must thank Jerry,he first outlined the 
	thoughts of	this soc project and pointed out that the *The main hurdles are smb.conf
	variables and the include parameter.* which proved to be very true when I doing the project.
	Also thank vl and csd on the irc who help making the problem domain clear. Avi's initial
	trying to elektralized SAMBA inspired me I hope the code are usefull for SAMBA and 
	I'll be glad to make it more stable and intergrate to SAMBA in the future if it's 
	worth to be done.
  
ref:
http://www.samba.org
http://www.libelektra.org


More information about the samba-technical mailing list