#include <fs_secure.h>
#endif
-#define Do(x) (flags & PROC_ ## x) /* convenient shorthand */
-
/* initiate a process table scan
*/
PROCTAB* openproc(int flags, ...) {
va_list ap;
PROCTAB* PT = xmalloc(sizeof(PROCTAB));
- if (Do(PID))
+ if (flags & PROC_PID)
PT->procfs = NULL;
else if (!(PT->procfs = opendir("/proc")))
return NULL;
PT->flags = flags;
va_start(ap, flags); /* Init args list */
- if (Do(PID))
+ if (flags & PROC_PID)
PT->pids = va_arg(ap, pid_t*);
- else if (Do(TTY))
- PT->ttys = va_arg(ap, dev_t*);
- else if (Do(UID)) {
+ else if (flags & PROC_UID) {
PT->uids = va_arg(ap, uid_t*);
PT->nuid = va_arg(ap, int);
}
/*printf("PT->flags is 0x%08x\n", PT->flags);*/
#define flags (PT->flags)
- if (Do(PID)) {
+ if (flags & PROC_PID) {
if (!*PT->pids) /* set to next item in pids */
return NULL;
sprintf(path, "/proc/%d", *(PT->pids)++);
#endif
goto next_proc;
- if (Do(UID) && !XinLN(uid_t, sb.st_uid, PT->uids, PT->nuid))
+ if ((flags & PROC_UID) && !XinLN(uid_t, sb.st_uid, PT->uids, PT->nuid))
goto next_proc; /* not one of the requested uids */
if (!p)
goto next_proc; /* error reading /proc/#/stat */
stat2proc(sbuf, p); /* parse /proc/#/stat */
- if (!matched && Do(TTY) && !XinL(dev_t, p->tty, PT->ttys))
- goto next_proc; /* not one of the requested ttys */
-
- if (Do(FILLMEM)) { /* read, parse /proc/#/statm */
+ if (flags & PROC_FILLMEM) { /* read, parse /proc/#/statm */
if ((file2str(path, "statm", sbuf, sizeof sbuf)) != -1 )
statm2proc(sbuf, p); /* ignore statm errors here */
} /* statm fields just zero */
- if (Do(FILLSTATUS)) { /* read, parse /proc/#/status */
+ if (flags & PROC_FILLSTATUS) { /* read, parse /proc/#/status */
if ((file2str(path, "status", sbuf, sizeof sbuf)) != -1 ){
status2proc(sbuf, p, 0 /*FIXME*/);
}
}
/* some number->text resolving which is time consuming */
- if (Do(FILLUSR)){
+ if (flags & PROC_FILLUSR){
strncpy(p->euser, user_from_uid(p->euid), sizeof p->euser);
- if(Do(FILLSTATUS)) {
+ if(flags & PROC_FILLSTATUS) {
strncpy(p->ruser, user_from_uid(p->ruid), sizeof p->ruser);
strncpy(p->suser, user_from_uid(p->suid), sizeof p->suser);
strncpy(p->fuser, user_from_uid(p->fuid), sizeof p->fuser);
}
/* some number->text resolving which is time consuming */
- if (Do(FILLGRP)){
+ if (flags & PROC_FILLGRP){
strncpy(p->egroup, group_from_gid(p->egid), sizeof p->egroup);
- if(Do(FILLSTATUS)) {
+ if(flags & PROC_FILLSTATUS) {
strncpy(p->rgroup, group_from_gid(p->rgid), sizeof p->rgroup);
strncpy(p->sgroup, group_from_gid(p->sgid), sizeof p->sgroup);
strncpy(p->fgroup, group_from_gid(p->fgid), sizeof p->fgroup);
}
}
- if (Do(FILLCOM) || Do(FILLARG)) /* read+parse /proc/#/cmdline */
+ if ((flags & PROC_FILLCOM) || (flags & PROC_FILLARG)) /* read+parse /proc/#/cmdline */
p->cmdline = file2strvec(path, "cmdline");
else
p->cmdline = NULL;
- if (Do(FILLENV)) /* read+parse /proc/#/environ */
+ if (flags & PROC_FILLENV) /* read+parse /proc/#/environ */
p->environ = file2strvec(path, "environ");
else
p->environ = NULL;
goto next_proc; /* error reading /proc/#/stat */
stat2proc(sbuf, p); /* parse /proc/#/stat */
- if (Do(FILLMEM)) { /* read, parse /proc/#/statm */
+ if (flags & PROC_FILLMEM) { /* read, parse /proc/#/statm */
if ((file2str(path, "statm", sbuf, sizeof sbuf)) != -1 )
statm2proc(sbuf, p); /* ignore statm errors here */
} /* statm fields just zero */
- /* if (Do(FILLSTATUS)) { */ /* read, parse /proc/#/status */
+ /* if (flags & PROC_FILLSTATUS) { */ /* read, parse /proc/#/status */
if ((file2str(path, "status", sbuf, sizeof sbuf)) != -1 ){
status2proc(sbuf, p, 0 /*FIXME*/);
}
/* }*/
/* some number->text resolving which is time consuming */
- if (Do(FILLUSR)){
+ if (flags & PROC_FILLUSR){
strncpy(p->euser, user_from_uid(p->euid), sizeof p->euser);
-/* if(Do(FILLSTATUS)) { */
+/* if(flags & PROC_FILLSTATUS) { */
strncpy(p->ruser, user_from_uid(p->ruid), sizeof p->ruser);
strncpy(p->suser, user_from_uid(p->suid), sizeof p->suser);
strncpy(p->fuser, user_from_uid(p->fuid), sizeof p->fuser);
}
/* some number->text resolving which is time consuming */
- if (Do(FILLGRP)){
+ if (flags & PROC_FILLGRP){
strncpy(p->egroup, group_from_gid(p->egid), sizeof p->egroup);
-/* if(Do(FILLSTATUS)) { */
+/* if(flags & PROC_FILLSTATUS) { */
strncpy(p->rgroup, group_from_gid(p->rgid), sizeof p->rgroup);
strncpy(p->sgroup, group_from_gid(p->sgid), sizeof p->sgroup);
strncpy(p->fgroup, group_from_gid(p->fgid), sizeof p->fgroup);
/* }*/
}
- if (Do(FILLCOM) || Do(FILLARG)) /* read+parse /proc/#/cmdline */
+ if ((flags & PROC_FILLCOM) || (flags & PROC_FILLARG)) /* read+parse /proc/#/cmdline */
p->cmdline = file2strvec(path, "cmdline");
else
p->cmdline = NULL;
- if (Do(FILLENV)) /* read+parse /proc/#/environ */
+ if (flags & PROC_FILLENV) /* read+parse /proc/#/environ */
p->environ = file2strvec(path, "environ");
else
p->environ = NULL;
va_list ap;
va_start(ap, flags); /* pass through args to openproc */
- if (Do(UID)) {
+ if (flags & PROC_UID) {
/* temporary variables to ensure that va_arg() instances
* are called in the right order
*/
i = va_arg(ap, int);
PT = openproc(flags, u, i);
}
- else if (Do(PID) || Do(TTY))
+ else if (flags & PROC_PID)
PT = openproc(flags, va_arg(ap, void*)); /* assume ptr sizes same */
else
PT = openproc(flags);
DIR* procfs;
int flags;
pid_t* pids; /* pids of the procs */
- dev_t* ttys; /* devnos of the cttys */
uid_t* uids; /* uids of procs */
int nuid; /* cannot really sentinel-terminate unsigned short[] */
- char* stats; /* status chars (actually output into /proc//stat) */
#ifdef FLASK_LINUX
-security_id_t* sids; /* SIDs of the procs */
+ security_id_t* sids; /* SIDs of the procs */
#endif
} PROCTAB;
* `flags' (a bitwise-or of PROC_* below) modifies the default behavior. The
* "fill" options will cause more of the proc_t to be filled in. The "filter"
* options all use the second argument as the pointer to a list of objects:
- * process status', process id's, user id's, and tty device numbers. The third
+ * process status', process id's, user id's. The third
* argument is the length of the list (currently only used for lists of user
- * id's since unsigned short[] supports no convenient termination sentinel.)
+ * id's since uid_t supports no convenient termination sentinel.)
*/
#define PROC_FILLMEM 0x0001 /* read statm */
#define PROC_FILLCOM 0x0002 /* alloc and fill in `cmdline' */
#define PROC_FILLSTATUS 0x0020 /* read status -- currently unconditional */
#define PROC_FILLSTAT 0x0040 /* read stat -- currently unconditional */
#define PROC_FILLWCHAN 0x0080 /* look up WCHAN name */
-#define PROC_FILLARG 0x1000 /* alloc and fill in `cmdline' */
+#define PROC_FILLARG 0x0100 /* alloc and fill in `cmdline' */
-#define PROC_FILLBUG 0xf0ff /* No idea what we need */
+#define PROC_FILLBUG 0x0fff /* No idea what we need */
#define PROC_FILLANY 0x0000 /* either stat or status will do */
/* Obsolete, consider only processes with one of the passed: */
-#define PROC_PID 0x0100 /* process id numbers ( 0 terminated) */
-#define PROC_TTY 0x0200 /* ctty device nos. ( 0 terminated) */
-#define PROC_UID 0x0400 /* user id numbers ( length needed ) */
+#define PROC_PID 0x1000 /* process id numbers ( 0 terminated) */
+#define PROC_UID 0x4000 /* user id numbers ( length needed ) */
#endif