r21115: notify_internal.c needs to remove the table entry if a process has crashed. So
authorVolker Lendecke <vlendec@samba.org>
Thu, 1 Feb 2007 19:29:07 +0000 (19:29 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:17:39 +0000 (12:17 -0500)
it needs the specific error message.

Make messages.c return NTSTATUS and specificially NT_STATUS_INVALID_HANDLE if
sending to a non-existent process.

Volker

source/lib/messages.c
source/libsmb/clidgram.c
source/rpc_server/srv_srvsvc_nt.c
source/smbd/open.c
source/utils/smbcontrol.c

index 5bf1774af1b518a33da06a3fb8c91b5b26a74805..e0bf86a46cee38fd564638bd5d519ce910e8a8c2 100644 (file)
@@ -166,7 +166,7 @@ static TDB_DATA message_key_pid(struct process_id pid)
  then delete its record in the database.
 ****************************************************************************/
 
-static BOOL message_notify(struct process_id procid)
+static NTSTATUS message_notify(struct process_id procid)
 {
        pid_t pid = procid.pid;
        int ret;
@@ -191,25 +191,40 @@ static BOOL message_notify(struct process_id procid)
 
        if (ret == -1) {
                if (errno == ESRCH) {
-                       DEBUG(2,("pid %d doesn't exist - deleting messages record\n", (int)pid));
+                       DEBUG(2,("pid %d doesn't exist - deleting messages record\n",
+                                (int)pid));
                        tdb_delete(tdb, message_key_pid(procid));
-               } else {
-                       DEBUG(2,("message to process %d failed - %s\n", (int)pid, strerror(errno)));
+
+                       /*
+                        * INVALID_HANDLE is the closest I can think of -- vl
+                        */
+                       return NT_STATUS_INVALID_HANDLE;
                }
-               return False;
+
+               DEBUG(2,("message to process %d failed - %s\n", (int)pid,
+                        strerror(errno)));
+
+               /*
+                * No call to map_nt_error_from_unix -- don't want to link in
+                * errormap.o into lots of utils.
+                */
+
+               if (errno == EINVAL) return NT_STATUS_INVALID_PARAMETER;
+               if (errno == EPERM)  return NT_STATUS_ACCESS_DENIED;
+               return NT_STATUS_UNSUCCESSFUL;
        }
 
-       return True;
+       return NT_STATUS_OK;
 }
 
 /****************************************************************************
  Send a message to a particular pid.
 ****************************************************************************/
 
-static BOOL message_send_pid_internal(struct process_id pid, int msg_type,
-                                     const void *buf, size_t len,
-                                     BOOL duplicates_allowed,
-                                     unsigned int timeout)
+static NTSTATUS message_send_pid_internal(struct process_id pid, int msg_type,
+                                         const void *buf, size_t len,
+                                         BOOL duplicates_allowed,
+                                         unsigned int timeout)
 {
        TDB_DATA kbuf;
        TDB_DATA dbuf;
@@ -239,8 +254,9 @@ static BOOL message_send_pid_internal(struct process_id pid, int msg_type,
        kbuf = message_key_pid(pid);
 
        dbuf.dptr = (char *)SMB_MALLOC(len + sizeof(rec));
-       if (!dbuf.dptr)
-               return False;
+       if (!dbuf.dptr) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
        memcpy(dbuf.dptr, &rec, sizeof(rec));
        if (len > 0 && buf)
@@ -255,13 +271,15 @@ static BOOL message_send_pid_internal(struct process_id pid, int msg_type,
                /* lock the record for the destination */
                if (timeout) {
                        if (tdb_chainlock_with_timeout(tdb, kbuf, timeout) == -1) {
-                               DEBUG(0,("message_send_pid_internal: failed to get chainlock with timeout %ul.\n", timeout));
-                               return False;
+                               DEBUG(0,("message_send_pid_internal: failed to get "
+                                        "chainlock with timeout %ul.\n", timeout));
+                               return NT_STATUS_IO_TIMEOUT;
                        }
                } else {
                        if (tdb_chainlock(tdb, kbuf) == -1) {
-                               DEBUG(0,("message_send_pid_internal: failed to get chainlock.\n"));
-                               return False;
+                               DEBUG(0,("message_send_pid_internal: failed to get "
+                                        "chainlock.\n"));
+                               return NT_STATUS_LOCK_NOT_GRANTED;
                        }
                }       
                tdb_append(tdb, kbuf, dbuf);
@@ -275,13 +293,15 @@ static BOOL message_send_pid_internal(struct process_id pid, int msg_type,
        /* lock the record for the destination */
        if (timeout) {
                if (tdb_chainlock_with_timeout(tdb, kbuf, timeout) == -1) {
-                       DEBUG(0,("message_send_pid_internal: failed to get chainlock with timeout %ul.\n", timeout));
-                       return False;
+                       DEBUG(0,("message_send_pid_internal: failed to get chainlock "
+                                "with timeout %ul.\n", timeout));
+                       return NT_STATUS_IO_TIMEOUT;
                }
        } else {
                if (tdb_chainlock(tdb, kbuf) == -1) {
-                       DEBUG(0,("message_send_pid_internal: failed to get chainlock.\n"));
-                       return False;
+                       DEBUG(0,("message_send_pid_internal: failed to get "
+                                "chainlock.\n"));
+                       return NT_STATUS_LOCK_NOT_GRANTED;
                }
        }       
 
@@ -310,10 +330,11 @@ static BOOL message_send_pid_internal(struct process_id pid, int msg_type,
                if (!memcmp(ptr, &rec, sizeof(rec))) {
                        if (!len || (len && !memcmp( ptr + sizeof(rec), buf, len))) {
                                tdb_chainunlock(tdb, kbuf);
-                               DEBUG(10,("message_send_pid_internal: discarding duplicate message.\n"));
+                               DEBUG(10,("message_send_pid_internal: discarding "
+                                         "duplicate message.\n"));
                                SAFE_FREE(dbuf.dptr);
                                SAFE_FREE(old_dbuf.dptr);
-                               return True;
+                               return NT_STATUS_OK;
                        }
                }
                memcpy(&prec, ptr, sizeof(prec));
@@ -336,19 +357,23 @@ static BOOL message_send_pid_internal(struct process_id pid, int msg_type,
  Send a message to a particular pid - no timeout.
 ****************************************************************************/
 
-BOOL message_send_pid(struct process_id pid, int msg_type, const void *buf, size_t len, BOOL duplicates_allowed)
+NTSTATUS message_send_pid(struct process_id pid, int msg_type, const void *buf,
+                         size_t len, BOOL duplicates_allowed)
 {
-       return message_send_pid_internal(pid, msg_type, buf, len, duplicates_allowed, 0);
+       return message_send_pid_internal(pid, msg_type, buf, len,
+                                        duplicates_allowed, 0);
 }
 
 /****************************************************************************
  Send a message to a particular pid, with timeout in seconds.
 ****************************************************************************/
 
-BOOL message_send_pid_with_timeout(struct process_id pid, int msg_type, const void *buf, size_t len,
-               BOOL duplicates_allowed, unsigned int timeout)
+NTSTATUS message_send_pid_with_timeout(struct process_id pid, int msg_type,
+                                      const void *buf, size_t len,
+                                      BOOL duplicates_allowed, unsigned int timeout)
 {
-       return message_send_pid_internal(pid, msg_type, buf, len, duplicates_allowed, timeout);
+       return message_send_pid_internal(pid, msg_type, buf, len, duplicates_allowed,
+                                        timeout);
 }
 
 /****************************************************************************
@@ -586,6 +611,7 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void
 {
        struct connections_data crec;
        struct msg_all *msg_all = (struct msg_all *)state;
+       NTSTATUS status;
 
        if (dbuf.dsize != sizeof(crec))
                return 0;
@@ -603,18 +629,17 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void
        /* If the msg send fails because the pid was not found (i.e. smbd died), 
         * the msg has already been deleted from the messages.tdb.*/
 
-       if (!message_send_pid(crec.pid, msg_all->msg_type,
-                             msg_all->buf, msg_all->len,
-                             msg_all->duplicates)) {
+       status = message_send_pid(crec.pid, msg_all->msg_type,
+                                 msg_all->buf, msg_all->len,
+                                 msg_all->duplicates);
+
+       if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
                
                /* If the pid was not found delete the entry from connections.tdb */
 
-               if (errno == ESRCH) {
-                       DEBUG(2,("pid %s doesn't exist - deleting connections %d [%s]\n",
-                                procid_str_static(&crec.pid),
-                                crec.cnum, crec.name));
-                       tdb_delete(the_tdb, kbuf);
-               }
+               DEBUG(2,("pid %s doesn't exist - deleting connections %d [%s]\n",
+                        procid_str_static(&crec.pid), crec.cnum, crec.name));
+               tdb_delete(the_tdb, kbuf);
        }
        msg_all->n_sent++;
        return 0;
@@ -806,8 +831,7 @@ NTSTATUS messaging_send(struct messaging_context *msg,
                        uint32_t msg_type, DATA_BLOB *data)
 {
        return message_send_pid_internal(server.id, msg_type, data->data,
-                                        data->length, True, 0)
-               ? NT_STATUS_OK : NT_STATUS_ACCESS_DENIED;
+                                        data->length, True, 0);
 }
 
 /** @} **/
index dfb613238f60facfd6799e9b1732aae89536008a..a983f485ab4ccc3d25e02322e8f4fa8404a9555e 100644 (file)
@@ -101,8 +101,9 @@ BOOL cli_send_mailslot(BOOL unique, const char *mailslot,
        DEBUGADD(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name),
                    inet_ntoa(dest_ip)));
 
-       return message_send_pid(pid_to_procid(nmbd_pid), MSG_SEND_PACKET, &p, sizeof(p),
-                               False);
+       return NT_STATUS_IS_OK(message_send_pid(pid_to_procid(nmbd_pid),
+                                               MSG_SEND_PACKET, &p, sizeof(p),
+                                               False));
 }
 
 /*
index 3dea0a84938b9c084fdc1ccaa7eaeb8452cb29d0..c0953f2723aa4dbcc5915c531c267ba2daf75d07 100644 (file)
@@ -1219,7 +1219,7 @@ WERROR _srvsvc_NetSessDel(pipes_struct *p, struct srvsvc_NetSessDel *r)
                if ((strequal(session_list[snum].username, r->in.user) || r->in.user[0] == '\0' ) &&
                     strequal(session_list[snum].remote_machine, machine)) {
                
-                       if (message_send_pid(pid_to_procid(session_list[snum].pid), MSG_SHUTDOWN, NULL, 0, False))
+                       if (NT_STATUS_IS_OK(message_send_pid(pid_to_procid(session_list[snum].pid), MSG_SHUTDOWN, NULL, 0, False)))
                                status = WERR_OK;
                }
        }
index 6de620e4883aaf2656f1f26b0648c5158ab46d3d..2415433fe9f24df1596e5e512afb7062c3734935 100644 (file)
@@ -652,7 +652,7 @@ static BOOL delay_for_oplocks(struct share_mode_lock *lck,
        BOOL valid_entry = False;
        BOOL delay_it = False;
        BOOL have_level2 = False;
-       BOOL ret;
+       NTSTATUS status;
        char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
 
        if (oplock_request & INTERNAL_OPEN_ONLY) {
@@ -740,10 +740,11 @@ static BOOL delay_for_oplocks(struct share_mode_lock *lck,
                SSVAL(msg,6,exclusive->op_type | FORCE_OPLOCK_BREAK_TO_NONE);
        }
 
-       ret = message_send_pid(exclusive->pid, MSG_SMB_BREAK_REQUEST,
-                              msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
-       if (!ret) {
-               DEBUG(3, ("Could not send oplock break message\n"));
+       status = message_send_pid(exclusive->pid, MSG_SMB_BREAK_REQUEST,
+                                 msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(3, ("Could not send oplock break message: %s\n",
+                         nt_errstr(status)));
        }
 
        return True;
index 26e2b82ae68d2b28e13270337ad1dd2b50478a9d..ec1e101e061764272a0ae79630c15ef963d97b8e 100644 (file)
@@ -59,7 +59,8 @@ static BOOL send_message(struct process_id pid, int msg_type,
                return False;
 
        if (procid_to_pid(&pid) != 0)
-               return message_send_pid(pid, msg_type, buf, len, duplicates);
+               return NT_STATUS_IS_OK(message_send_pid(pid, msg_type, buf, len,
+                                                       duplicates));
 
        tdb = tdb_open_log(lock_path("connections.tdb"), 0, 
                           TDB_DEFAULT, O_RDWR, 0);