Add support for detecting busy subordinate user ids
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
This commit is contained in:
parent
87253ca906
commit
89f7b0868c
@ -38,11 +38,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
#include "subordinateio.h"
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
static int check_status (const char *sname, uid_t uid);
|
static int check_status (const char *name, const char *sname, uid_t uid);
|
||||||
static int user_busy_processes (const char *name, uid_t uid);
|
static int user_busy_processes (const char *name, uid_t uid);
|
||||||
#else /* !__linux__ */
|
#else /* !__linux__ */
|
||||||
static int user_busy_utmp (const char *name);
|
static int user_busy_utmp (const char *name);
|
||||||
@ -102,7 +104,7 @@ static int user_busy_utmp (const char *name)
|
|||||||
#endif /* !__linux__ */
|
#endif /* !__linux__ */
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
static int check_status (const char *sname, uid_t uid)
|
static int check_status (const char *name, const char *sname, uid_t uid)
|
||||||
{
|
{
|
||||||
/* 40: /proc/xxxxxxxxxx/task/xxxxxxxxxx/status + \0 */
|
/* 40: /proc/xxxxxxxxxx/task/xxxxxxxxxx/status + \0 */
|
||||||
char status[40];
|
char status[40];
|
||||||
@ -125,7 +127,10 @@ static int check_status (const char *sname, uid_t uid)
|
|||||||
&ruid, &euid, &suid) == 3) {
|
&ruid, &euid, &suid) == 3) {
|
||||||
if ( (ruid == (unsigned long) uid)
|
if ( (ruid == (unsigned long) uid)
|
||||||
|| (euid == (unsigned long) uid)
|
|| (euid == (unsigned long) uid)
|
||||||
|| (suid == (unsigned long) uid)) {
|
|| (suid == (unsigned long) uid)
|
||||||
|
|| have_sub_uids(name, ruid, 1)
|
||||||
|
|| have_sub_uids(name, euid, 1)
|
||||||
|
|| have_sub_uids(name, suid, 1)) {
|
||||||
(void) fclose (sfile);
|
(void) fclose (sfile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -153,6 +158,8 @@ static int user_busy_processes (const char *name, uid_t uid)
|
|||||||
struct stat sbroot;
|
struct stat sbroot;
|
||||||
struct stat sbroot_process;
|
struct stat sbroot_process;
|
||||||
|
|
||||||
|
sub_uid_open (O_RDONLY);
|
||||||
|
|
||||||
proc = opendir ("/proc");
|
proc = opendir ("/proc");
|
||||||
if (proc == NULL) {
|
if (proc == NULL) {
|
||||||
perror ("opendir /proc");
|
perror ("opendir /proc");
|
||||||
@ -196,7 +203,7 @@ static int user_busy_processes (const char *name, uid_t uid)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_status (tmp_d_name, uid) != 0) {
|
if (check_status (name, tmp_d_name, uid) != 0) {
|
||||||
(void) closedir (proc);
|
(void) closedir (proc);
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: user %s is currently used by process %d\n"),
|
_("%s: user %s is currently used by process %d\n"),
|
||||||
@ -216,7 +223,7 @@ static int user_busy_processes (const char *name, uid_t uid)
|
|||||||
if (tid == pid) {
|
if (tid == pid) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (check_status (task_path+6, uid) != 0) {
|
if (check_status (name, task_path+6, uid) != 0) {
|
||||||
(void) closedir (proc);
|
(void) closedir (proc);
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: user %s is currently used by process %d\n"),
|
_("%s: user %s is currently used by process %d\n"),
|
||||||
@ -231,6 +238,7 @@ static int user_busy_processes (const char *name, uid_t uid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
(void) closedir (proc);
|
(void) closedir (proc);
|
||||||
|
sub_uid_close();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* __linux__ */
|
#endif /* __linux__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user