Added back groupname map stuff removed by Andrew's "slash 'n' burn"
authorJeremy Allison <jra@samba.org>
Tue, 8 Sep 1998 19:21:04 +0000 (19:21 +0000)
committerJeremy Allison <jra@samba.org>
Tue, 8 Sep 1998 19:21:04 +0000 (19:21 +0000)
tactics :-). Protected by #ifdef until used.

Fixed bug in fd_attempt_close() where a pointer to potentially
free'd memory was returned. I hate that.

Added "blocking locks" as a per-share option for performance testing.

Changed is_mangled() so it will return true if called with a pathname
and any component of the pathname was mangled (it was already attempting
to do this, but not checking for a '/' as end-of-mangle).

This should be a better fix for the wierd stat cache bug Andrew identified.

Jeremy.

source/include/proto.h
source/param/loadparm.c
source/smbd/filename.c
source/smbd/groupname.c
source/smbd/mangle.c
source/smbd/open.c
source/smbd/reply.c

index a7581ced79ab6837e194911289531ad491bff56d..862c11f350e7c4194f64beb7ba3452f9d67e6b9d 100644 (file)
@@ -858,6 +858,7 @@ char *lp_passwordserver(void);
 char *lp_name_resolve_order(void);
 char *lp_workgroup(void);
 char *lp_username_map(void);
+char *lp_groupname_map(void);
 char *lp_logon_script(void);
 char *lp_logon_path(void);
 char *lp_logon_drive(void);
@@ -1019,6 +1020,7 @@ BOOL lp_recursive_veto_delete(int );
 BOOL lp_dos_filetimes(int );
 BOOL lp_dos_filetime_resolution(int );
 BOOL lp_fake_dir_create_times(int );
+BOOL lp_blocking_locks(int );
 int lp_create_mode(int );
 int lp_force_create_mode(int );
 int lp_dir_mode(int );
@@ -1742,6 +1744,11 @@ void file_chain_reset(void);
 void file_chain_save(void);
 void file_chain_restore(void);
 
+/*The following definitions come from  smbd/groupname.c  */
+
+void load_groupname_map(void);
+void map_gid_to_sid( gid_t gid, DOM_SID *psid);
+
 /*The following definitions come from  smbd/ipc.c  */
 
 int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int bufsize);
@@ -1788,7 +1795,7 @@ int reply_nttrans(connection_struct *conn,
 /*The following definitions come from  smbd/open.c  */
 
 void fd_add_to_uid_cache(file_fd_struct *fd_ptr, uid_t u);
-int fd_attempt_close(file_fd_struct *fd_ptr);
+uint16 fd_attempt_close(file_fd_struct *fd_ptr);
 void open_file_shared(files_struct *fsp,connection_struct *conn,char *fname,int share_mode,int ofun,
                      int mode,int oplock_request, int *Access,int *action);
 int open_directory(files_struct *fsp,connection_struct *conn,
index fe3cf2f06af8685bcc13757222157d8ed5c71d42..c8ab2d411bfc320ff50c9c280b6e35dc7fcfebb0 100644 (file)
@@ -126,7 +126,9 @@ typedef struct
   char *szDomainHostsallow; 
   char *szDomainHostsdeny;
   char *szUsernameMap;
+#ifdef USING_GROUPNAME_MAP
   char *szGroupnameMap;
+#endif /* USING_GROUPNAME_MAP */
   char *szCharacterSet;
   char *szLogonScript;
   char *szLogonPath;
@@ -324,6 +326,7 @@ typedef struct
   BOOL bDosFiletimes;
   BOOL bDosFiletimeResolution;
   BOOL bFakeDirCreateTimes;
+  BOOL bBlockingLocks;
   char dummy[3]; /* for alignment */
 } service;
 
@@ -415,6 +418,7 @@ static service sDefault =
   False, /* bDosFiletimes */
   False, /* bDosFiletimeResolution */
   False, /* bFakeDirCreateTimes */
+  True,  /* bBlockingLocks */
   ""     /* dummy */
 };
 
@@ -582,6 +586,7 @@ static struct parm_struct parm_table[] =
   {"time server",      P_BOOL,    P_GLOBAL, &Globals.bTimeServer,      NULL,   NULL,  0},
 
   {"Tuning Options", P_SEP, P_SEPARATOR},
+  {"blocking locks",   P_BOOL,    P_LOCAL,  &sDefault.bBlockingLocks,    NULL,   NULL,  0},
   {"change notify timeout", P_INTEGER, P_GLOBAL, &Globals.change_notify_timeout, NULL,   NULL,  0},
   {"deadtime",         P_INTEGER, P_GLOBAL, &Globals.deadtime,          NULL,   NULL,  0},
   {"getwd cache",      P_BOOL,    P_GLOBAL, &use_getwd_cache,           NULL,   NULL,  0},
@@ -654,6 +659,9 @@ static struct parm_struct parm_table[] =
   {"domain guest group",P_STRING, P_GLOBAL, &Globals.szDomainGuestGroup, NULL,   NULL,  0},
   {"domain admin users",P_STRING, P_GLOBAL, &Globals.szDomainAdminUsers, NULL,   NULL,  0},
   {"domain guest users",P_STRING, P_GLOBAL, &Globals.szDomainGuestUsers, NULL,   NULL,  0},
+#ifdef USING_GROUPNAME_MAP
+  {"groupname map",     P_STRING, P_GLOBAL, &Globals.szGroupnameMap,     NULL,   NULL,  0},
+#endif /* USING_GROUPNAME_MAP */
   {"machine password timeout", P_INTEGER, P_GLOBAL, &Globals.machine_password_timeout,  NULL,   NULL,  0},
 
   {"Logon Options", P_SEP, P_SEPARATOR},
@@ -1060,6 +1068,9 @@ FN_GLOBAL_STRING(lp_passwordserver,&Globals.szPasswordServer)
 FN_GLOBAL_STRING(lp_name_resolve_order,&Globals.szNameResolveOrder)
 FN_GLOBAL_STRING(lp_workgroup,&Globals.szWorkGroup)
 FN_GLOBAL_STRING(lp_username_map,&Globals.szUsernameMap)
+#ifdef USING_GROUPNAME_MAP
+FN_GLOBAL_STRING(lp_groupname_map,&Globals.szGroupnameMap)
+#endif /* USING_GROUPNAME_MAP */
 FN_GLOBAL_STRING(lp_logon_script,&Globals.szLogonScript) 
 FN_GLOBAL_STRING(lp_logon_path,&Globals.szLogonPath) 
 FN_GLOBAL_STRING(lp_logon_drive,&Globals.szLogonDrive) 
@@ -1239,6 +1250,7 @@ FN_LOCAL_BOOL(lp_recursive_veto_delete,bDeleteVetoFiles)
 FN_LOCAL_BOOL(lp_dos_filetimes,bDosFiletimes)
 FN_LOCAL_BOOL(lp_dos_filetime_resolution,bDosFiletimeResolution)
 FN_LOCAL_BOOL(lp_fake_dir_create_times,bFakeDirCreateTimes)
+FN_LOCAL_BOOL(lp_blocking_locks,bBlockingLocks)
 
 FN_LOCAL_INTEGER(lp_create_mode,iCreate_mask)
 FN_LOCAL_INTEGER(lp_force_create_mode,iCreate_force_mode)
index a88829de9d6b3e797895edfd6d3a6d11fc135b10..0910e03ee3409c7c6cc071bb7273cd4727212983 100644 (file)
@@ -339,7 +339,10 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
   int saved_errno;
   BOOL component_was_mangled = False;
   BOOL name_has_wildcard = False;
+#if 0
+  /* Andrew's conservative code... JRA. */
   extern char magic_char;
+#endif
 
   *dirpath = 0;
   *bad_path = False;
@@ -441,9 +444,20 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
   if(strchr(start,'?') || strchr(start,'*'))
     name_has_wildcard = True;
 
+  /* 
+   * is_mangled() was changed to look at an entire pathname, not 
+   * just a component. JRA.
+   */
+
+  if(is_mangled(start))
+    component_was_mangled = True;
+
+#if 0
+  /* Keep Andrew's conservative code around, just in case. JRA. */
   /* this is an extremely conservative test for mangled names. */
   if (strchr(start,magic_char))
     component_was_mangled = True;
+#endif
 
   /* 
    * Now we need to recursively match the name against the real 
index 75af12a47afd758211b3b82754bd6446a52bf492..29236e2ca5777965a3fba33d3fecff6eb4645582 100644 (file)
@@ -19,6 +19,8 @@
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#ifdef USING_GROUPNAME_MAP
+
 #include "includes.h"
 extern int DEBUGLEVEL;
 extern DOM_SID global_machine_sid;
@@ -236,3 +238,6 @@ void map_gid_to_sid( gid_t gid, DOM_SID *psid)
 
   return;
 }
+#else /* USING_GROUPNAME_MAP */
+ void load_groupname_map(void) {;}
+#endif /* USING_GROUPNAME_MAP */
index 0a3d3f54eb7f1135b95c59ae159364692781f8d1..f0d5a9d85ca06f26269f06d308dd8da23bbc1cd8 100644 (file)
@@ -272,7 +272,7 @@ static BOOL is_illegal_name( char *name )
 /* ************************************************************************** **
  * Return True if the name *could be* a mangled name.
  *
- *  Input:  s - A file name.
+ *  Input:  s - A path name - in UNIX pathname format.
  *
  *  Output: True if the name matches the pattern described below in the
  *          notes, else False.
@@ -281,7 +281,8 @@ static BOOL is_illegal_name( char *name )
  *          done separately.  This function returns true if the name contains
  *          a magic character followed by excactly two characters from the
  *          basechars list (above), which in turn are followed either by the
- *          nul (end of string) byte or a dot (extension).
+ *          nul (end of string) byte or a dot (extension) or by a '/' (end of
+ *          a directory name).
  *
  * ************************************************************************** **
  */
@@ -295,7 +296,7 @@ BOOL is_mangled( char *s )
   magic = strchr( s, magic_char );
   while( magic && magic[1] && magic[2] )          /* 3 chars, 1st is magic. */
     {
-    if( ('.' == magic[3] || !(magic[3]))          /* Ends with '.' or nul?  */
+    if( ('.' == magic[3] || '/' == magic[3] || !(magic[3]))          /* Ends with '.' or nul or '/' ?  */
      && isbasechar( toupper(magic[1]) )           /* is 2nd char basechar?  */
      && isbasechar( toupper(magic[2]) ) )         /* is 3rd char basechar?  */
       return( True );                           /* If all above, then true, */
index e6289b1cdbca913080d6265f8aa0e2f6442ad17f..bd1ead69218d98bce4f9607fcbd660c02f23d8be 100644 (file)
@@ -145,40 +145,37 @@ static void fd_attempt_reopen(char *fname, int mode, file_fd_struct *fd_ptr)
 fd support routines - attempt to close the file referenced by this fd.
 Decrements the ref_count and returns it.
 ****************************************************************************/
-int fd_attempt_close(file_fd_struct *fd_ptr)
+uint16 fd_attempt_close(file_fd_struct *fd_ptr)
 {
   extern struct current_user current_user;
+  uint16 ret_ref = fd_ptr->ref_count;
 
-#ifdef LARGE_SMB_INO_T
   DEBUG(3,("fd_attempt_close fd = %d, dev = %x, inode = %.0f, open_flags = %d, ref_count = %d.\n",
           fd_ptr->fd, (unsigned int)fd_ptr->dev, (double)fd_ptr->inode,
           fd_ptr->real_open_flags,
           fd_ptr->ref_count));
-#else /* LARGE_SMB_INO_T */
-  DEBUG(3,("fd_attempt_close fd = %d, dev = %x, inode = %lx, open_flags = %d, ref_count = %d.\n",
-          fd_ptr->fd, (unsigned int)fd_ptr->dev, (unsigned long)fd_ptr->inode,
-          fd_ptr->real_open_flags,
-          fd_ptr->ref_count));
-#endif /* LARGE_SMB_INO_T */
 
-  if(fd_ptr->ref_count > 0) {
-    fd_ptr->ref_count--;
-    if(fd_ptr->ref_count == 0) {
-      if(fd_ptr->fd != -1)
-        close(fd_ptr->fd);
-      if(fd_ptr->fd_readonly != -1)
-        close(fd_ptr->fd_readonly);
-      if(fd_ptr->fd_writeonly != -1)
-        close(fd_ptr->fd_writeonly);
-      /*
-       * Delete this fd_ptr.
-       */
-      fd_ptr_free(fd_ptr);
-    } else {
-      fd_remove_from_uid_cache(fd_ptr, (uid_t)current_user.uid);
-    }
-  } 
- return fd_ptr->ref_count;
+  SMB_ASSERT(fd_ptr->ref_count != 0);
+
+  fd_ptr->ref_count--;
+  ret_ref = fd_ptr->ref_count;
+
+  if(fd_ptr->ref_count == 0) {
+    if(fd_ptr->fd != -1)
+      close(fd_ptr->fd);
+    if(fd_ptr->fd_readonly != -1)
+      close(fd_ptr->fd_readonly);
+    if(fd_ptr->fd_writeonly != -1)
+      close(fd_ptr->fd_writeonly);
+    /*
+     * Delete this fd_ptr.
+     */
+    fd_ptr_free(fd_ptr);
+  } else {
+    fd_remove_from_uid_cache(fd_ptr, (uid_t)current_user.uid);
+  }
+
+ return ret_ref;
 }
 
 /****************************************************************************
index d7ab99701094bb9325a6ce45a545cf994b4f4b12..3d537d88681db7d556266c1094548bd1cbd8d301 100644 (file)
@@ -1891,7 +1891,7 @@ int reply_lockread(connection_struct *conn, char *inbuf,char *outbuf, int length
   data = smb_buf(outbuf) + 3;
   
   if(!do_lock( fsp, conn, numtoread, startpos, F_RDLCK, &eclass, &ecode)) {
-    if(ecode == ERRlock) {
+    if((ecode == ERRlock) && lp_blocking_locks(SNUM(conn))) {
       /*
        * A blocking lock was requested. Package up
        * this smb into a queued request and push it
@@ -2485,7 +2485,7 @@ int reply_lock(connection_struct *conn,
                 fsp->fd_ptr->fd, fsp->fnum, offset, count));
 
        if (!do_lock(fsp, conn, count, offset, F_WRLCK, &eclass, &ecode)) {
-      if(ecode == ERRlock) {
+      if((ecode == ERRlock) && lp_blocking_locks(SNUM(conn))) {
         /*
          * A blocking lock was requested. Package up
          * this smb into a queued request and push it
@@ -3618,7 +3618,7 @@ dev = %x, inode = %lx\n", fsp->fnum, (unsigned int)dev, (unsigned long)inode));
           (int)offset, (int)count, fsp->fsp_name ));
     if(!do_lock(fsp,conn,count,offset, ((locktype & 1) ? F_RDLCK : F_WRLCK),
                 &eclass, &ecode)) {
-      if((ecode == ERRlock) && (lock_timeout != 0)) {
+      if((ecode == ERRlock) && (lock_timeout != 0) && lp_blocking_locks(SNUM(conn))) {
         /*
          * A blocking lock was requested. Package up
          * this smb into a queued request and push it