[PATCH 1/1] Extended share names

Amin Azez azez at ufomechanic.net
Thu Jan 10 19:22:16 GMT 2008


Stefan (metze) Metzmacher wrote:
> Hi,
>
>   
>> if "extended share names" is enabled, then When make_connection()
>> tries to load the share section from the config it will check in
>> this order for:
>>   \\name.domain\share
>>   \\name\share
>>   \\name.domain
>>   \\name
>>     
>
> why this two without share?
>   
So that backends like proxy and cifs can automatically propagate 
whatever shares exist on the proxied server without having to define a 
share for each one, or worry about defining new shares every time one is 
created on the server.
>   
>>  /* local prototypes */
>>  static int map_parameter(const char *pszParmName);
>> @@ -2407,6 +2413,8 @@ bool loadparm_init(struct loadparm_context *lp_ctx)
>>  	lp_do_global_parameter_var(lp_ctx, "setup directory", "%s", 
>>  				   dyn_SETUPDIR);
>>  
>> +	lp_do_global_parameter(lp_ctx, "extended share names", "0");
>>     
>
> This should be "no" instead of "0".
>   
spotted!
>   
>>  	for (i = 0; parm_table[i].label; i++) {
>>  		if (!(parm_table[i].flags & FLAG_CMDLINE)) {
>>  			parm_table[i].flags |= FLAG_DEFAULT;
>> diff --git a/source/smb_server/smb/service.c b/source/smb_server/smb/service.c
>> index 558f303..8fb00b2 100644
>> --- a/source/smb_server/smb/service.c
>> +++ b/source/smb_server/smb/service.c
>> @@ -120,17 +120,70 @@ static NTSTATUS make_connection(struct smbsrv_request *req,
>>  	const char *type_str;
>>  	struct share_config *scfg;
>>  	const char *sharetype;
>> -
>> +	const char *server_name=NULL;
>> +	const char *full_server_name=NULL;
>> +	const char *full_service=service;
>> +	const char* short_service=NULL;
>> +	bool extended_share_names=lp_extended_share_names(global_loadparm);
>> +	
>>  	/* the service might be of the form \\SERVER\SHARE. Should we put
>>  	   the server name we get from this somewhere? */
>>  	if (strncmp(service, "\\\\", 2) == 0) {
>>  		char *p = strchr(service+2, '\\');
>> +		/* Get the server name (including \\ ) up to a . or \ */
>> +		server_name=talloc_strndup(req, service, 2+strcspn(2+service, "\\."));
>> +		full_server_name=talloc_strndup(req, service, 2+strcspn(2+service, "\\"));
>>     
>
> This looks a bit complex for oneliners, please split this up a bit more.
> Split the logic from the allocation and check for allocation errors.
>   
well.... string processing is a _bit_ complex and I don't see how 
splitting it up will make it any easier to follow, it will just leave 
more threads, however I will try to comply :-)

would this sort of thing do?

/* find the end of the short server name */
int server_name_n=2+strcspn(2+service, "\\.");
/* pull out the short server name */
server_name=talloc_strndup(req, service, server_name_n);
if (! server_name) return NT_STATUS_DIDNT_WORK;

or I could be very daring with:

if (! (server_name=talloc_strndup(req, service, server_name_n))
	return NT_STATUS_DIDNT_WORK;

?
I
>>  		if (p) {
>>  			service = p + 1;
>>  		}
>> +		short_service=talloc_asprintf(req, "%s\\%s", server_name, service);
>> +	}
>> +
>> +	if (extended_share_names) {
>> +		/* Try the full \\blah.domain\blah service - useful for proxy backends */
>> +		if (!NT_STATUS_IS_OK(status) && full_service) {
>> +			DEBUG(3,("Looking for service %s\n",full_service));
>> +			status = share_get_config(req, req->smb_conn->share_context, full_service, &scfg);
>> +		}
>> +
>> +		/* Try the short \\blah\blah service - useful for proxy backends */
>> +		if (!NT_STATUS_IS_OK(status) && short_service) {
>> +			DEBUG(3,("Looking for service %s\n",short_service));
>> +			status = share_get_config(req, req->smb_conn->share_context, short_service, &scfg);
>> +		}
>> +
>> +		/* Try the full \\blah.domain server name - useful for proxy backends */
>> +		if (!NT_STATUS_IS_OK(status) && service > full_server_name) {
>> +				DEBUG(3,("Looking for service %s\n", full_server_name));
>> +				status = share_get_config(req, req->smb_conn->share_context, full_server_name, &scfg);
>> +		}
>>     
>
> here's one tab too much:-)
>   
ta
>   
>> +		/* Try the short \\blah server name - useful for proxy backends */
>> +		if (!NT_STATUS_IS_OK(status) && service > server_name) {
>>     
>
> '>' doesn't work on strings...
>   
darn, dead cells left over from an earlier incarnation, old pointer 
arithmetic, I'll fix that too.
A fresh copy to follow tomorrow.

No objections in principle though?

Sam


More information about the samba-technical mailing list