[PATCH] Parametrical options support for Samba 3.0

Alexander Bokovoy a.bokovoy at sam-solutions.net
Fri Apr 12 09:17:02 GMT 2002


Greetings!

Attached patch makes possible arbitrary options to be specified in
smb.conf and later queried from VFS modules (and other places)
without problems. Below such options are called 'parametrical options'.

Patch introduces new notation to smb.conf option's language, as discussed
today with Tridgell on @samba-technical:

	TYPE: OPTION = VALUE

Colon sign is important here, it is what distinguishes parametrical
options from ones hardcoded in param/loadparm.c.

TYPE is 'option domain', OPTION is option name itself.

In order to access values of parametrical options, lp_parm_string()
function was implemented:

char *lp_parm_string(const char *servicename, const char *type, const char *option);

This function accepts service name, type and option name, and returns
value of option or NULL if this option is underfined. Service name can be
NULL, resulting in search in 'global' section only.

If option does not exist in specified service, 'global' section is
scanned. This allows propagation of globally specified options to all
services and later overloading of the option in some services.

Caution: 'TYPE: OPTION' combination is case sensitive.

So far, testparm is able to handle parametrical options, while SWAT
can't. Thus, everyone familiar with SWAT internals is welcomed to add
parametrical options support.

Below is simple example from examples/VFS/recycle.c:

Old code:

static int recycle_connect(struct connection_struct *conn, const char *service, const char *user)
{
	pstring opts_str;
	fstring recycle_bin;
	char *p;

	DEBUG(3,("recycle_connect: called for service %s as user %s\n", service, user));

	pstrcpy(opts_str, (const char *)lp_vfs_options(SNUM(conn)));
	if (!*opts_str) {
		DEBUG(3,("recycle_connect: No options listed (%s).\n", lp_vfs_options(SNUM(conn)) ));
		return 0; /* No options. */
	}

	p = opts_str;
	if (next_token(&p,recycle_bin,"=",sizeof(recycle_bin))) {
		if (!strequal("recycle", recycle_bin)) {
			DEBUG(3,("recycle_connect: option %s is not recycle\n", recycle_bin ));
			return -1;
		}
	}

	if (!next_token(&p,recycle_bin," \n",sizeof(recycle_bin))) {
		DEBUG(3,("recycle_connect: no option after recycle=\n"));
		return -1;
	}

	DEBUG(10,("recycle_connect: recycle name is %s\n", recycle_bin ));

	conn->vfs_private = (void *)strdup(recycle_bin);
	return 0;
}


New code:


static int recycle_connect(struct connection_struct *conn, const char *service, const char *user)
{
	fstring recycle_bin;

	DEBUG(3,("recycle_connect: called for service %s as user %s\n", service, user));

	fstrcpy(recycle_bin, (const char *)lp_parm_string(lp_servicename(SNUM(conn)),"vfs","recycle bin"));
	if (!*recycle_bin) {
		DEBUG(3,("recycle_connect: No options listed (vfs:recycle bin).\n" ));
		return 0; /* No options. */
	}

	DEBUG(3,("recycle_connect: recycle name is %s\n", recycle_bin ));

	conn->vfs_private = (void *)strdup(recycle_bin);
	return 0;
}


Note that parametrical options with spaces are supported.

-- 
/ Alexander Bokovoy
Software architect and analyst             // SaM-Solutions Ltd.
---
It may be that your whole purpose in life is simply to serve as a
warning to others.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: samba-3.0-vfs-options.patch.bz2
Type: application/x-bzip2
Size: 2304 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20020412/0777bd08/samba-3.0-vfs-options.patch.bin


More information about the samba-technical mailing list