text-base idmap patch

Takashi Ikebe ikebe.takashi at lab.ntt.co.jp
Tue Mar 23 13:07:01 GMT 2004


Hi,
I made idmap patch based on samba 3.0.2a.
Attached patch maps sid to gid/uid with text base database.
The ldap server is good for big network, however small network does
not need such database.
By using this patch, you can use same uid with nis with text-base
configuration.

Text base user database should be named as "smbidmap" and should be
placed on /etc/samba/smbidmap.
Format is below;
SID id(uid/gid) type(uid=1,gid=2)
for instance,
S-1-5-21-2581315262-1086050687-3579556021-**** 1012 1
This mean S-1-5-21-2581315262-1086050687-3579556021-**** is user's SID
and uid is 1012.

I don't know this kind of patch is welcome, however I need this
function for my environment.

Thank you
-- 
Takashi Ikebe
e-mail : ikebe.takashi at lab.ntt.co.jp
e-mail : iktaka99 at hotmail.com
-------------- next part --------------
*** idmap_util.c.org	2004-02-14 00:12:49.000000000 +0900
--- idmap_util.c	2004-03-23 20:53:54.372648552 +0900
***************
*** 146,156 ****
--- 146,174 ----
  {
  	NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
  	unid_t id;
+ 	fstring keystr, tempstr;
  	
  	DEBUG(10,("idmap_sid_to_uid: sid = [%s]\n", sid_string_static(sid)));
  
  	flags |= ID_USERID;
  
+ 	/*writen by iktaka*/
+ 	if(opt_smbidmap){
+ 		currentptr=previousptr;
+ 		while(currentptr!=NULL){
+ 			if(currentptr->type==1){
+ 				strncpy(tempstr,currentptr->sid,currentptr->size);
+ 				sid_to_string(keystr,sid);
+ 				if(strncmp(keystr,tempstr,currentptr->size)==0){
+ 					ret=NT_STATUS_OK;
+ 					*uid=currentptr->id;
+ 					return ret;
+ 				}
+ 			}
+ 			currentptr=currentptr->nextptr;
+ 		}
+ 	}
+ 
  	ret = idmap_get_id_from_sid(&id, (int *)&flags, sid);
  		
  	if ( NT_STATUS_IS_OK(ret) ) {
***************
*** 176,185 ****
--- 193,222 ----
  	NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
  	unid_t id;
  	
+ 	/*writen by iktaka*/
+ 	fstring keystr, tempstr;
+ 
  	DEBUG(10,("sid_to_gid: sid = [%s]\n", sid_string_static(sid)));
  
  	flags |= ID_GROUPID;
  
+ 	/*writen by iktaka*/
+ 	if(opt_smbidmap){
+ 		currentptr=previousptr;
+ 		while(currentptr!=NULL){
+ 			if(currentptr->type==2){
+ 				strncpy(tempstr,currentptr->sid,currentptr->size);
+ 				sid_to_string(keystr,sid);
+ 				if(strncmp(keystr,tempstr,currentptr->size)==0){
+ 					ret=NT_STATUS_OK;
+ 					*gid=currentptr->id;
+ 					return ret;
+ 				}
+ 			}
+ 			currentptr=currentptr->nextptr;
+ 		}
+ 	}
+ 	
  	ret = idmap_get_id_from_sid(&id, (int *)&flags, sid);
  		
  	if ( NT_STATUS_IS_OK(ret) ) 
-------------- next part --------------
*** includes.h.org	2004-02-14 00:12:44.000000000 +0900
--- includes.h	2004-03-23 20:43:47.743870144 +0900
***************
*** 1326,1329 ****
--- 1326,1342 ----
  #undef HAVE_MMAP
  #endif
  
+ /*fro smbidmap*/
+ BOOL opt_smbidmap;
+ 
+ struct sid2uid{
+ 	fstring	sid;
+ 	int		id;
+ 	int		type;
+ 	int		size;
+ 	struct sid2uid *nextptr;
+ };
+ 
+ struct sid2uid *newptr, *currentptr, *previousptr;
+ 
  #endif /* _INCLUDES_H */
-------------- next part --------------
#This file is static idmap file.
#format is below;
#SID id(uid/gid) type(uid=1,gid=2)
#
#user account
S-1-5-21-2581315262-1086050687-3579556021-XXXX 1012 1
S-1-5-21-2581315262-1086050687-3579556021-XXXX 1011 1
S-1-5-21-2581315262-1086050687-3579556021-XXXX 1006 1
S-1-5-21-2581315262-1086050687-3579556021-XXXX 1003 1
S-1-5-21-2581315262-1086050687-3579556021-XXXX 1002 1
S-1-5-21-2581315262-1086050687-3579556021-XXXX 1010 1
S-1-5-21-2581315262-1086050687-3579556021-XXXX 1103 1
#group account	
S-1-5-21-2581315262-1086050687-3579556021-XXX 100 2
-------------- next part --------------
*** winbindd.c.org	2004-02-14 00:12:47.000000000 +0900
--- winbindd.c	2004-03-23 21:51:48.321528048 +0900
***************
*** 792,797 ****
--- 792,852 ----
  	};
  	poptContext pc;
  	int opt;
+ 	
+ 	/* for smbidmap file check  writen by iktaka */
+ 	opt_smbidmap = False;
+ 	FILE *fpr;
+ 	if (fpr = fopen("/etc/samba/smbidmap", "r")){
+ 
+ 		currentptr=NULL;
+ 		previousptr=NULL;
+ 		char tmpc[255];
+ 		
+ 		while(fgets(tmpc,255,fpr)){
+ 			newptr=malloc(sizeof(struct sid2uid));
+ 			if(newptr != NULL){
+ 				if(tmpc[0]!='#'){
+ 					int i, j;
+ 					i=0;
+ 					while(tmpc[i]!=' '){
+ 						i++;
+ 					}
+ 					strncpy(newptr->sid,tmpc,i);
+ 					j=i;
+ 					i++;
+ 					newptr->size=j;
+ 
+ 					while(tmpc[i]!=' '){
+ 						i++;
+ 					}
+ 					char tmpb[6];
+ 					strncpy(tmpb,&tmpc[j+1],i-j);
+ 					newptr->id=atoi(tmpb);
+ 					char tmpd;
+ 					tmpd=tmpc[i+1];
+ 					if((int)tmpd==49){
+ 						newptr->type=1;
+ 					}else{
+ 						newptr->type=2;
+ 					}
+ 					if(previousptr==NULL){
+ 						previousptr=newptr;
+ 						previousptr->nextptr=NULL;
+ 					}else{
+ 						currentptr=previousptr;
+ 						while(currentptr->nextptr!=NULL){
+ 							currentptr=currentptr->nextptr;
+ 						}
+ 						currentptr->nextptr=newptr;
+ 					}
+ 					memset(tmpc,NULL,256);
+ 				}
+ 			}
+ 			/*malloc error OOM*/
+ 			break;
+ 		}
+ 		opt_smbidmap=True;	
+ 	}
  
  	/* glibc (?) likes to print "User defined signal 1" and exit if a
  	   SIGUSR[12] is received before a handler is installed */


More information about the samba-technical mailing list