More strlcat/strlcpy truncate checks.
[amitay/samba.git] / source3 / modules / vfs_recycle.c
index c6f2836763b6ec89823c92e8efe936c5e7384173..80332523ed922b4f999c127944ed41f777130b71 100644 (file)
  */
 
 #include "includes.h"
+#include "smbd/smbd.h"
+#include "system/filesys.h"
 #include "../librpc/gen_ndr/ndr_netlogon.h"
+#include "auth.h"
 
 #define ALLOC_CHECK(ptr, label) do { if ((ptr) == NULL) { DEBUG(0, ("recycle.bin: out of memory!\n")); errno = ENOMEM; goto label; } } while(0)
 
@@ -32,33 +35,9 @@ static int vfs_recycle_debug_level = DBGC_VFS;
 #undef DBGC_CLASS
 #define DBGC_CLASS vfs_recycle_debug_level
  
-static int recycle_connect(vfs_handle_struct *handle, const char *service, const char *user);
-static void recycle_disconnect(vfs_handle_struct *handle);
 static int recycle_unlink(vfs_handle_struct *handle,
                          const struct smb_filename *smb_fname);
 
-static int recycle_connect(vfs_handle_struct *handle, const char *service, const char *user)
-{
-       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
-
-       if (ret < 0) {
-               return ret;
-       }
-
-       DEBUG(10,("recycle_connect() connect to service[%s] as user[%s].\n",
-               service,user));
-
-       return 0;
-}
-
-static void recycle_disconnect(vfs_handle_struct *handle)
-{
-       DEBUG(10,("recycle_disconnect() connect to service[%s].\n",
-               lp_servicename(SNUM(handle->conn))));
-
-       SMB_VFS_NEXT_DISCONNECT(handle);
-}
-
 static const char *recycle_repository(vfs_handle_struct *handle)
 {
        const char *tmp_str = NULL;
@@ -301,13 +280,17 @@ static bool recycle_create_dir(vfs_handle_struct *handle, const char *dname)
        *new_dir = '\0';
        if (dname[0] == '/') {
                /* Absolute path. */
-               safe_strcat(new_dir,"/",len);
+               if (strlcat(new_dir,"/",len+1) >= len+1) {
+                       goto done;
+               }
        }
 
        /* Create directory tree if neccessary */
        for(token = strtok_r(tok_str, "/", &saveptr); token;
            token = strtok_r(NULL, "/", &saveptr)) {
-               safe_strcat(new_dir, token, len);
+               if (strlcat(new_dir, token, len+1) >= len+1) {
+                       goto done;
+               }
                if (recycle_directory_exist(handle, new_dir))
                        DEBUG(10, ("recycle: dir %s already exists\n", new_dir));
                else {
@@ -318,7 +301,9 @@ static bool recycle_create_dir(vfs_handle_struct *handle, const char *dname)
                                goto done;
                        }
                }
-               safe_strcat(new_dir, "/", len);
+               if (strlcat(new_dir, "/", len+1) >= len+1) {
+                       goto done;
+               }
                mode = recycle_subdir_mode(handle);
        }
 
@@ -464,11 +449,11 @@ static int recycle_unlink(vfs_handle_struct *handle,
        int rc = -1;
 
        repository = talloc_sub_advanced(NULL, lp_servicename(SNUM(conn)),
-                                       conn->server_info->unix_name,
+                                       conn->session_info->unix_info->unix_name,
                                        conn->connectpath,
-                                       conn->server_info->utok.gid,
-                                       conn->server_info->sanitized_username,
-                                       conn->server_info->info3->base.domain.string,
+                                       conn->session_info->unix_token->gid,
+                                       conn->session_info->unix_info->sanitized_username,
+                                       conn->session_info->info->domain_name,
                                        recycle_repository(handle));
        ALLOC_CHECK(repository, done);
        /* shouldn't we allow absolute path names here? --metze */
@@ -660,9 +645,7 @@ done:
 }
 
 static struct vfs_fn_pointers vfs_recycle_fns = {
-       .connect_fn = recycle_connect,
-       .disconnect = recycle_disconnect,
-       .unlink = recycle_unlink
+       .unlink_fn = recycle_unlink
 };
 
 NTSTATUS vfs_recycle_init(void);