Removed version number from file header.
[kai/samba.git] / source3 / smbd / groupname.c
index 4dadfaa9396e62a07a14849a85364c498b243f33..812488571a33b2442a444ba307f20a0f496779e8 100644 (file)
@@ -1,6 +1,5 @@
 /* 
-   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
@@ -53,11 +50,9 @@ static void delete_groupname_map_list(void)
   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);
   }
 }
 
@@ -71,9 +66,8 @@ void load_groupname_map(void)
   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) {
@@ -102,12 +96,13 @@ void load_groupname_map(void)
    * 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.
@@ -116,15 +111,16 @@ void load_groupname_map(void)
 
   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)))
@@ -149,8 +145,8 @@ void load_groupname_map(void)
      * 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;
     }
@@ -166,7 +162,7 @@ Error was %s.\n", unixname, strerror(errno) ));
        */
       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);
     }
 
     /*
@@ -179,7 +175,7 @@ Error was %s.\n", unixname, strerror(errno) ));
       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 );
@@ -187,11 +183,10 @@ Error was %s.\n", unixname, strerror(errno) ));
     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) );
@@ -202,7 +197,7 @@ Error was %s.\n", unixname, strerror(errno) ));
   DEBUG(10,("load_groupname_map: Added %ld entries to groupname map.\n",
            ubi_slCount(&groupname_map_list)));
            
-  fclose(fp);
+  file_lines_free(lines);
 }
 
 /***********************************************************