r16435: Add in the uid info that Jerry needs into the
authorJeremy Allison <jra@samba.org>
Wed, 21 Jun 2006 02:31:12 +0000 (02:31 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:18:54 +0000 (11:18 -0500)
share_mode struct. Allows us to know the unix
uid of the opener of the file/directory. Needed
for info level queries on open files.
Jeremy.

source/include/smb.h
source/libsmb/smb_share_modes.c
source/locking/locking.c
source/smbd/open.c
source/smbd/oplock.c
source/utils/status.c
source/web/statuspage.c

index 41ffce1a155f61e2230ae90957436671a9a92f0f..5aa06347f8c82b356dabd3501dc7900eaa0c8780 100644 (file)
@@ -671,6 +671,7 @@ struct share_mode_entry {
        SMB_DEV_T dev;
        SMB_INO_T inode;
        unsigned long share_file_id;
+       uint32 uid;             /* uid of file opener. */
 };
 
 /* oplock break message definition - linearization of share_mode_entry.
@@ -687,10 +688,11 @@ Offset  Data                      length.
 28     SMB_DEV_T dev           8 bytes.
 36     SMB_INO_T inode         8 bytes
 44     unsigned long file_id   4 bytes
-48
+48     uint32 uid              4 bytes
+52
 
 */
-#define MSG_SMB_SHARE_MODE_ENTRY_SIZE 48
+#define MSG_SMB_SHARE_MODE_ENTRY_SIZE 52
 
 struct share_mode_lock {
        const char *servicepath; /* canonicalized. */
index 090571b810764df0311cfcecae0c31fca64ade17..34ede9df296947a64e0ea5b49eb1d054854ec9cc 100644 (file)
@@ -149,6 +149,7 @@ static void create_share_mode_entry(struct share_mode_entry *out,
        out->access_mask = in->access_mask;
        out->dev = (SMB_DEV_T)in->dev;
        out->inode = (SMB_INO_T)in->ino;
+       out->uid = (uint32)geteuid();
 }
 
 /*
index 0ffb937432629eba4045971f2dfa195f10e44682..01f12bbb58ddc78e6bdf82b5b7ce3fb9da82bb31 100644 (file)
@@ -443,13 +443,13 @@ char *share_mode_str(int num, struct share_mode_entry *e)
        slprintf(share_str, sizeof(share_str)-1, "share_mode_entry[%d]: %s "
                 "pid = %s, share_access = 0x%x, private_options = 0x%x, "
                 "access_mask = 0x%x, mid = 0x%x, type= 0x%x, file_id = %lu, "
-                "dev = 0x%x, inode = %.0f",
+                "uid = %u, dev = 0x%x, inode = %.0f",
                 num,
                 e->op_type == UNUSED_SHARE_MODE_ENTRY ? "UNUSED" : "",
                 procid_str_static(&e->pid),
                 e->share_access, e->private_options,
                 e->access_mask, e->op_mid, e->op_type, e->share_file_id,
-                (unsigned int)e->dev, (double)e->inode );
+                (unsigned int)e->uid, (unsigned int)e->dev, (double)e->inode );
 
        return share_str;
 }
@@ -917,7 +917,7 @@ BOOL is_unused_share_mode_entry(const struct share_mode_entry *e)
 
 static void fill_share_mode_entry(struct share_mode_entry *e,
                                  files_struct *fsp,
-                                 uint16 mid, uint16 op_type)
+                                 uid_t uid, uint16 mid, uint16 op_type)
 {
        ZERO_STRUCTP(e);
        e->pid = procid_self();
@@ -928,9 +928,10 @@ static void fill_share_mode_entry(struct share_mode_entry *e,
        e->op_type = op_type;
        e->time.tv_sec = fsp->open_time.tv_sec;
        e->time.tv_usec = fsp->open_time.tv_usec;
-       e->share_file_id = fsp->fh->file_id;
        e->dev = fsp->dev;
        e->inode = fsp->inode;
+       e->share_file_id = fsp->fh->file_id;
+       e->uid = (uint32)uid;
 }
 
 static void fill_deferred_open_entry(struct share_mode_entry *e,
@@ -945,6 +946,7 @@ static void fill_deferred_open_entry(struct share_mode_entry *e,
        e->time.tv_usec = request_time.tv_usec;
        e->dev = dev;
        e->inode = ino;
+       e->uid = (uint32)-1;
 }
 
 static void add_share_mode_entry(struct share_mode_lock *lck,
@@ -969,10 +971,10 @@ static void add_share_mode_entry(struct share_mode_lock *lck,
 }
 
 void set_share_mode(struct share_mode_lock *lck, files_struct *fsp,
-                   uint16 mid, uint16 op_type)
+                       uid_t uid, uint16 mid, uint16 op_type)
 {
        struct share_mode_entry entry;
-       fill_share_mode_entry(&entry, fsp, mid, op_type);
+       fill_share_mode_entry(&entry, fsp, uid, mid, op_type);
        add_share_mode_entry(lck, &entry);
 }
 
@@ -1044,7 +1046,8 @@ BOOL del_share_mode(struct share_mode_lock *lck, files_struct *fsp)
 {
        struct share_mode_entry entry, *e;
 
-       fill_share_mode_entry(&entry, fsp, 0, NO_OPLOCK);
+       /* Don't care about the pid owner being correct here - just a search. */
+       fill_share_mode_entry(&entry, fsp, (uid_t)-1, 0, NO_OPLOCK);
 
        e = find_share_mode_entry(lck, &entry);
        if (e == NULL) {
@@ -1080,7 +1083,8 @@ BOOL remove_share_oplock(struct share_mode_lock *lck, files_struct *fsp)
 {
        struct share_mode_entry entry, *e;
 
-       fill_share_mode_entry(&entry, fsp, 0, NO_OPLOCK);
+       /* Don't care about the pid owner being correct here - just a search. */
+       fill_share_mode_entry(&entry, fsp, (uid_t)-1, 0, NO_OPLOCK);
 
        e = find_share_mode_entry(lck, &entry);
        if (e == NULL) {
@@ -1101,7 +1105,8 @@ BOOL downgrade_share_oplock(struct share_mode_lock *lck, files_struct *fsp)
 {
        struct share_mode_entry entry, *e;
 
-       fill_share_mode_entry(&entry, fsp, 0, NO_OPLOCK);
+       /* Don't care about the pid owner being correct here - just a search. */
+       fill_share_mode_entry(&entry, fsp, (uid_t)-1, 0, NO_OPLOCK);
 
        e = find_share_mode_entry(lck, &entry);
        if (e == NULL) {
index 2e4091d937e620baed6062397ae0454161a291f8..832a8df75598e1914f6fb28f88671252596759fd 100644 (file)
@@ -1685,7 +1685,7 @@ files_struct *open_file_ntcreate(connection_struct *conn,
                        fsp->oplock_type = NO_OPLOCK;
                }
        }
-       set_share_mode(lck, fsp, 0, fsp->oplock_type);
+       set_share_mode(lck, fsp, current_user.ut.uid, 0, fsp->oplock_type);
 
        if (info == FILE_WAS_OVERWRITTEN || info == FILE_WAS_CREATED ||
                                info == FILE_WAS_SUPERSEDED) {
@@ -1991,7 +1991,7 @@ files_struct *open_directory(connection_struct *conn,
                return NULL;
        }
 
-       set_share_mode(lck, fsp, 0, NO_OPLOCK);
+       set_share_mode(lck, fsp, current_user.ut.uid, 0, NO_OPLOCK);
 
        /* For directories the delete on close bit at open time seems
           always to be honored on close... See test 19 in Samba4 BASE-DELETE. */
index 1f731e172917ad5efde4601b4275e97e6e79dc51..e4f5c434b092ae77da0ee14dccb675b65b4a89aa 100644 (file)
@@ -830,6 +830,7 @@ void share_mode_entry_to_message(char *msg, struct share_mode_entry *e)
        SDEV_T_VAL(msg,28,e->dev);
        SINO_T_VAL(msg,36,e->inode);
        SIVAL(msg,44,e->share_file_id);
+       SIVAL(msg,48,e->uid);
 }
 
 /****************************************************************************
@@ -849,6 +850,7 @@ void message_to_share_mode_entry(struct share_mode_entry *e, char *msg)
        e->dev = DEV_T_VAL(msg,28);
        e->inode = INO_T_VAL(msg,36);
        e->share_file_id = (unsigned long)IVAL(msg,44);
+       e->uid = (uint32)IVAL(msg,48);
 }
 
 /****************************************************************************
index 2566c8a50def54fbfab74844144ca8bf55a20b83..163d99a2f69bf8be6725463b9cbfd829792c3e21 100644 (file)
@@ -108,13 +108,14 @@ static void print_share_mode(const struct share_mode_entry *e, const char *share
 
        if (count==0) {
                d_printf("Locked files:\n");
-               d_printf("Pid          DenyMode   Access      R/W        Oplock           SharePath           Name\n");
-               d_printf("----------------------------------------------------------------------------------------\n");
+               d_printf("Pid          Uid        DenyMode   Access      R/W        Oplock           SharePath   Name   Time\n");
+               d_printf("--------------------------------------------------------------------------------------------------\n");
        }
        count++;
 
        if (Ucrit_checkPid(procid_to_pid(&e->pid))) {
                d_printf("%-11s  ",procid_str_static(&e->pid));
+               d_printf("%-9u  ", (unsigned int)e->uid);
                switch (map_share_mode_to_deny_mode(e->share_access,
                                                    e->private_options)) {
                        case DENY_NONE: d_printf("DENY_NONE  "); break;
index 769ab217b3edb3d6746dc6214184fc3efbd4ef1d..cb6fa9117118afaff721e7c873a6b557178340ce 100644 (file)
@@ -119,6 +119,7 @@ static void print_share_mode(const struct share_mode_entry *e, const char *share
                                                    e->private_options);
 
        printf("<tr><td>%s</td>",_(mapPid2Machine(e->pid)));
+       printf("<td>%u</td>",(unsigned int)e->uid);
        printf("<td>");
        switch ((deny_mode>>4)&0xF) {
        case DENY_NONE: printf("DENY_NONE"); break;