/*
- Unix SMB/Netbios implementation.
- Version 1.9.
+ Unix SMB/CIFS implementation.
Groupname handling
Copyright (C) Jeremy Allison 1998.
#ifdef USING_GROUPNAME_MAP
#include "includes.h"
-extern int DEBUGLEVEL;
extern DOM_SID global_sam_sid;
-
/**************************************************************************
Groupname map functionality. The code loads a groupname map file and
(currently) loads it into a linked list. This is slow and memory
groupname_map_entry *gmep;
while((gmep = (groupname_map_entry *)ubi_slRemHead( &groupname_map_list )) != NULL) {
- if(gmep->windows_name)
- free(gmep->windows_name);
- if(gmep->unix_name)
- free(gmep->unix_name);
- free((char *)gmep);
+ SAFE_FREE(gmep->windows_name);
+ SAFE_FREE(gmep->unix_name);
+ SAFE_FREE(gmep);
}
}
static BOOL initialized = False;
char *groupname_map_file = lp_groupname_map();
SMB_STRUCT_STAT st;
- FILE *fp;
- char *s;
- pstring buf;
+ char **lines;
+ int i;
groupname_map_entry *new_ep;
if(!initialized) {
* Load the file.
*/
- fp = sys_fopen(groupname_map_file,"r");
- if (!fp) {
+ lines = file_lines_load(groupname_map_file,NULL,False);
+ if (!lines) {
DEBUG(0,("load_groupname_map: can't open groupname map %s. Error was %s\n",
groupname_map_file, strerror(errno)));
return;
}
+ file_lines_slashcont(lines);
/*
* Throw away any previous list.
DEBUG(4,("load_groupname_map: Scanning groupname map %s\n",groupname_map_file));
- while((s=fgets_slash(buf,sizeof(buf),fp))!=NULL) {
+ for (i=0; lines[i]; i++) {
pstring unixname;
pstring windows_name;
- struct group *gptr;
+ gid_t gid;
DOM_SID tmp_sid;
+ char *s = lines[i];
DEBUG(10,("load_groupname_map: Read line |%s|\n", s));
- if (!*s || strchr("#;",*s))
+ if (!*s || strchr_m("#;",*s))
continue;
if(!next_token(&s,unixname, "\t\n\r=", sizeof(unixname)))
* Attempt to get the unix gid_t for this name.
*/
- if((gptr = (struct group *)getgrnam(unixname)) == NULL) {
- DEBUG(0,("load_groupname_map: getgrnam for group %s failed.\
+ if ((gid = nametogid(unixname)) == (gid_t)-1)
+ DEBUG(0,("load_groupname_map: nametogid for group %s failed.\
Error was %s.\n", unixname, strerror(errno) ));
continue;
}
*/
tmp_sid = global_sam_sid;
tmp_sid.sub_auths[tmp_sid.num_auths++] =
- pdb_gid_to_group_rid((gid_t)gptr->gr_gid);
+ pdb_gid_to_group_rid(gid);
}
/*
return;
}
- new_ep->unix_gid = gptr->gr_gid;
+ new_ep->unix_gid = gid;
new_ep->windows_sid = tmp_sid;
new_ep->windows_name = strdup( windows_name );
new_ep->unix_name = strdup( unixname );
if(new_ep->windows_name == NULL || new_ep->unix_name == NULL) {
DEBUG(0,("load_groupname_map: malloc fail for names in groupname_map_entry.\n"));
fclose(fp);
- if(new_ep->windows_name != NULL)
- free(new_ep->windows_name);
- if(new_ep->unix_name != NULL)
- free(new_ep->unix_name);
- free((char *)new_ep);
+ SAFE_FREE(new_ep->windows_name);
+ SAFE_FREE(new_ep->unix_name);
+ SAFE_FREE(new_ep);
+ file_lines_free(lines);
return;
}
memset((char *)&new_ep->next, '\0', sizeof(new_ep->next) );
DEBUG(10,("load_groupname_map: Added %ld entries to groupname map.\n",
ubi_slCount(&groupname_map_list)));
- fclose(fp);
+ file_lines_free(lines);
}
/***********************************************************