smbd: Avoid casts in do_unlock()
[metze/samba/wip.git] / source3 / locking / locking.c
index 10e9606d134a3395dba2833bdfb4ded9308af445..8deb5279fa4dd4bba2cdcfab9a26bc1b93470942 100644 (file)
@@ -316,9 +316,12 @@ NTSTATUS do_unlock(struct messaging_context *msg_ctx,
                return NT_STATUS_OK;
        }
 
-       DEBUG(10, ("do_unlock: unlock start=%ju len=%ju requested for %s file "
-                  "%s\n", (uintmax_t)offset, (uintmax_t)count,
-                  fsp_fnum_dbg(fsp), fsp_str_dbg(fsp)));
+       DBG_DEBUG("unlock start=%"PRIu64" len=%"PRIu64" requested for %s file "
+                 "%s\n",
+                 offset,
+                 count,
+                 fsp_fnum_dbg(fsp),
+                 fsp_str_dbg(fsp));
 
        br_lck = brl_get_locks(talloc_tos(), fsp);
        if (!br_lck) {
@@ -501,14 +504,13 @@ bool rename_share_filename(struct messaging_context *msg_ctx,
                        const struct smb_filename *smb_fname_dst)
 {
        struct share_mode_data *d = lck->data;
-       size_t sp_len;
-       size_t bn_len;
-       size_t sn_len;
-       size_t msg_len;
-       char *frm = NULL;
+       struct file_rename_message msg = {
+               .id = id,
+               .servicepath = servicepath,
+               .base_name = smb_fname_dst->base_name,
+               .stream_name = smb_fname_dst->stream_name,
+       };
        uint32_t i;
-       bool strip_two_chars = false;
-       bool has_stream = smb_fname_dst->stream_name != NULL;
        struct server_id self_pid = messaging_server_id(msg_ctx);
        bool ok;
 
@@ -519,56 +521,27 @@ bool rename_share_filename(struct messaging_context *msg_ctx,
         * rename_internal_fsp() and rename_internals() add './' to
         * head of newname if newname does not contain a '/'.
         */
-       if (smb_fname_dst->base_name[0] &&
-           smb_fname_dst->base_name[1] &&
-           smb_fname_dst->base_name[0] == '.' &&
-           smb_fname_dst->base_name[1] == '/') {
-               strip_two_chars = true;
-       }
-
-       d->servicepath = talloc_strdup(d, servicepath);
-       d->base_name = talloc_strdup(d, smb_fname_dst->base_name +
-                                      (strip_two_chars ? 2 : 0));
-       d->stream_name = talloc_strdup(d, smb_fname_dst->stream_name);
-       if (d->base_name == NULL ||
-           (has_stream && d->stream_name == NULL) ||
-           d->servicepath == NULL) {
-               DEBUG(0, ("rename_share_filename: talloc failed\n"));
-               return False;
-       }
-       d->modified = True;
 
-       sp_len = strlen(d->servicepath);
-       bn_len = strlen(d->base_name);
-       sn_len = has_stream ? strlen(d->stream_name) : 0;
-
-       msg_len = MSG_FILE_RENAMED_MIN_SIZE + sp_len + 1 + bn_len + 1 +
-           sn_len + 1;
-
-       /* Set up the name changed message. */
-       frm = talloc_array(d, char, msg_len);
-       if (!frm) {
-               return False;
+       if (strncmp(msg.base_name, "./", 2) == 0) {
+               msg.base_name += 2;
        }
 
-       push_file_id_24(frm, &id);
-
-       DEBUG(10,("rename_share_filename: msg_len = %u\n", (unsigned int)msg_len ));
-
-       strlcpy(&frm[24],
-               d->servicepath ? d->servicepath : "",
-               sp_len+1);
-       strlcpy(&frm[24 + sp_len + 1],
-               d->base_name ? d->base_name : "",
-               bn_len+1);
-       strlcpy(&frm[24 + sp_len + 1 + bn_len + 1],
-               d->stream_name ? d->stream_name : "",
-               sn_len+1);
+       d->servicepath = talloc_strdup(d, msg.servicepath);
+       d->base_name = talloc_strdup(d, msg.base_name);
+       d->stream_name = talloc_strdup(d, msg.stream_name);
+       if ((d->servicepath == NULL) ||
+           (d->base_name == NULL) ||
+           ((msg.stream_name != NULL) && (d->stream_name == NULL))) {
+               DBG_WARNING("talloc failed\n");
+               return false;
+       }
+       d->modified = True;
 
        /* Send the messages. */
        for (i=0; i<d->num_share_modes; i++) {
                struct share_mode_entry *se = &d->share_modes[i];
-               struct server_id_buf tmp;
+               DATA_BLOB blob;
+               enum ndr_err_code ndr_err;
 
                if (!is_valid_share_mode_entry(se)) {
                        continue;
@@ -591,16 +564,28 @@ bool rename_share_filename(struct messaging_context *msg_ctx,
                        continue;
                }
 
-               DEBUG(10,("rename_share_filename: sending rename message to "
-                         "pid %s file_id %s sharepath %s base_name %s "
-                         "stream_name %s\n",
-                         server_id_str_buf(se->pid, &tmp),
-                         file_id_string_tos(&id),
-                         d->servicepath, d->base_name,
-                       has_stream ? d->stream_name : ""));
+               msg.share_file_id = se->share_file_id;
+
+               ndr_err = ndr_push_struct_blob(
+                       &blob,
+                       talloc_tos(),
+                       &msg,
+                       (ndr_push_flags_fn_t)ndr_push_file_rename_message);
+               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+                       DBG_DEBUG("ndr_push_file_rename_message failed: %s\n",
+                                 ndr_errstr(ndr_err));
+                       return false;
+               }
+               if (DEBUGLEVEL >= 10) {
+                       struct server_id_buf tmp;
+                       DBG_DEBUG("sending rename message to %s\n",
+                                 server_id_str_buf(se->pid, &tmp));
+                       NDR_PRINT_DEBUG(file_rename_message, &msg);
+               }
+
+               messaging_send(msg_ctx, se->pid, MSG_SMB_FILE_RENAME, &blob);
 
-               messaging_send_buf(msg_ctx, se->pid, MSG_SMB_FILE_RENAME,
-                                  (uint8_t *)frm, msg_len);
+               TALLOC_FREE(blob.data);
        }
 
        ok = share_mode_forall_leases(lck, rename_lease_fn, NULL);