diff -Nur psmisc/src/fuser.c psmisc.nfs/src/fuser.c
--- psmisc/src/fuser.c 2007-08-06 08:29:21.000000000 +0200
+++ psmisc.nfs/src/fuser.c 2007-08-06 08:32:13.000000000 +0200
@@ -68,7 +68,7 @@
static void kill_matched_proc(struct procs *pptr, const opt_type opts, const int sig_number);
int parse_mount(struct names *this_name, struct device_list **dev_list);
-static void add_device(struct device_list **dev_list, struct names *this_name, dev_t device);
+static void add_device(struct device_list **dev_list, struct names *this_name, dev_t device, DEVICE_TYPE dev_type);
void scan_mount_devices(const opt_type opts, struct mountdev_list **mount_devices);
void fill_unix_cache(struct unixsocket_list **unixsocket_head);
static dev_t find_net_dev(void);
@@ -162,12 +162,15 @@
exe_stat = get_pidstat(pid, "exe");
/* Scan the devices */
for (dev_tmp = dev_head ; dev_tmp != NULL ; dev_tmp = dev_tmp->next) {
- if (exe_stat != NULL && exe_stat->st_dev == dev_tmp->device)
+ if (exe_stat != NULL && exe_stat->st_dev == dev_tmp->device) {
add_matched_proc(dev_tmp->name, pid, uid, ACCESS_EXE);
- if (root_stat != NULL && root_stat->st_dev == dev_tmp->device)
+ }
+ if (root_stat != NULL && root_stat->st_dev == dev_tmp->device) {
add_matched_proc(dev_tmp->name, pid, uid, ACCESS_ROOT);
- if (cwd_stat != NULL && cwd_stat->st_dev == dev_tmp->device)
+ }
+ if (cwd_stat != NULL && cwd_stat->st_dev == dev_tmp->device) {
add_matched_proc(dev_tmp->name, pid, uid, ACCESS_CWD);
+ }
}
for (ino_tmp = ino_head ; ino_tmp != NULL ; ino_tmp = ino_tmp->next) {
if (exe_stat != NULL) {
@@ -210,11 +213,11 @@
*ino_list = ino_tmp;
}
-static void add_device(struct device_list **dev_list, struct names *this_name, dev_t device)
+static void add_device(struct device_list **dev_list, struct names *this_name, dev_t device, DEVICE_TYPE dev_type)
{
struct device_list *dev_tmp, *dev_head;
- /*printf("Adding device %s %d\n", this_name->filename, device);*/
+ /*printf("Adding device %s %d\n", this_name->filename, (int) device);*/
dev_head = *dev_list;
if ( (dev_tmp = malloc(sizeof(struct device_list))) == NULL)
@@ -222,6 +225,7 @@
dev_tmp->name = this_name;
dev_tmp->device = device;
dev_tmp->next = dev_head;
+ dev_tmp->type = dev_type;
*dev_list = dev_tmp;
}
@@ -321,7 +325,7 @@
#ifdef DEBUG
printf("Debug: parse_mount() adding %s\n", this_name->filename);
#endif /* DEBUG */
- add_device(dev_list, this_name, st.st_dev);
+ add_device(dev_list, this_name, st.st_dev, DEV_TYPE_OTHER);
return 0;
}
@@ -370,6 +374,7 @@
struct stat st;
struct mountdev_list *mountptr;
dev_t match_device;
+ DEVICE_TYPE dev_type;
if (stat(this_name->filename, &st) != 0) {
fprintf(stderr,_("Cannot stat %s: %s\n"), this_name->filename,
@@ -381,10 +386,15 @@
else
match_device = st.st_dev;
for (mountptr = mounts ; mountptr != NULL ; mountptr = mountptr->next) {
+ if (strcmp(mountptr->fstype, "nfs") == 0) {
+ dev_type = DEV_TYPE_NFS;
+ } else {
+ dev_type = DEV_TYPE_OTHER;
+ }
if (mountptr->device == match_device) {
/*printf("Debug: adding parse_mounts() adding %s\n",
this_name->filename);*/
- add_device(dev_list, this_name, match_device);
+ add_device(dev_list, this_name, match_device, dev_type);
}
}
return 0;
@@ -994,7 +1004,7 @@
static void check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, struct inode_list *ino_head, const uid_t uid, const char access)
{
- char *dirpath, *filepath;
+ char *dirpath, *filepath, *realfile;
DIR *dirp;
struct dirent *direntry;
struct inode_list *ino_tmp;
@@ -1020,10 +1030,26 @@
} else {
for (dev_tmp = dev_head ; dev_tmp != NULL ; dev_tmp = dev_tmp->next) {
if (st.st_dev == dev_tmp->device) {
- if (access == ACCESS_FILE && (lstat(filepath, &lst)==0) && (lst.st_mode & S_IWUSR)) {
- add_matched_proc(dev_tmp->name, pid,uid, ACCESS_FILEWR|access);
- } else {
- add_matched_proc(dev_tmp->name, pid,uid, access);
+ if (dev_tmp->type == DEV_TYPE_NFS) {
+ if ((realfile = (char *)alloca(strlen(dev_tmp->name->filename))) == NULL) {
+ fprintf(stderr, "Cannot allocate buffer memory\n");
+ }
+ if (readlink(filepath, realfile, strlen(dev_tmp->name->filename)) == -1) {
+ fprintf(stderr, "Cannot read link %s\n", filepath);
+ }
+ if (strncmp(dev_tmp->name->filename, realfile, strlen(dev_tmp->name->filename)) == 0) {
+ if (access == ACCESS_FILE && (lstat(filepath, &lst)==0) && (lst.st_mode & S_IWUSR)) {
+ add_matched_proc(dev_tmp->name, pid,uid, ACCESS_FILEWR|access);
+ } else {
+ add_matched_proc(dev_tmp->name, pid,uid, access);
+ }
+ }
+ } else {
+ if (access == ACCESS_FILE && (lstat(filepath, &lst)==0) && (lst.st_mode & S_IWUSR)) {
+ add_matched_proc(dev_tmp->name, pid,uid, ACCESS_FILEWR|access);
+ } else {
+ add_matched_proc(dev_tmp->name, pid,uid, access);
+ }
}
}
}
@@ -1082,7 +1108,7 @@
return st.st_uid;
}
-void add_mount_device(struct mountdev_list **mount_head,const char *fsname, const char *dir, dev_t device)
+void add_mount_device(struct mountdev_list **mount_head,const char *fsname, const char *fstype, const char *dir, dev_t device)
{
struct mountdev_list *newmount;
/*printf("Adding mount Path: %s Dir:%s dev:%0x\n",dir, fsname, device);*/
@@ -1090,6 +1116,7 @@
if ( (newmount = malloc(sizeof(struct mountdev_list))) == NULL)
return;
newmount->fsname = strdup(fsname);
+ newmount->fstype = strdup(fstype);
newmount->dir = strdup(dir);
newmount->device = device;
newmount->next = *mount_head;
@@ -1152,7 +1179,7 @@
}
while ( (mnt_ptr = getmntent(mntfp)) != NULL) {
if (stat(mnt_ptr->mnt_dir, &st) == 0) {
- add_mount_device(mount_devices, mnt_ptr->mnt_fsname, mnt_ptr->mnt_dir, st.st_dev);
+ add_mount_device(mount_devices, mnt_ptr->mnt_fsname, mnt_ptr->mnt_type, mnt_ptr->mnt_dir, st.st_dev);
}
}
}
diff -Nur psmisc/src/fuser.h psmisc.nfs/src/fuser.h
--- psmisc/src/fuser.h 2007-08-06 08:29:21.000000000 +0200
+++ psmisc.nfs/src/fuser.h 2007-08-06 08:33:35.000000000 +0200
@@ -60,14 +60,20 @@
struct mountdev_list {
char *fsname;
+ char *fstype;
char *dir;
dev_t device;
struct mountdev_list *next;
};
+typedef enum {
+ DEV_TYPE_NFS = 0,
+ DEV_TYPE_OTHER
+} DEVICE_TYPE;
struct device_list {
struct names *name;
+ DEVICE_TYPE type;
dev_t device;
struct device_list *next;
};