better handling of long usernames

This commit is contained in:
albert 2004-07-20 23:31:12 +00:00
parent 5a8a11c88d
commit f1db79c042
7 changed files with 59 additions and 51 deletions

7
NEWS
View File

@ -1,3 +1,10 @@
procps-3.2.2 --> procps-3.2.3
avoid truncating long usernames
avoid warning about -lncurses when not linking (more)
new names for shared libraries (packagers: watch out!)
"make install" no longer rebuilds everything
procps-3.2.1 --> procps-3.2.2
new packager (downstream maintainer) guidelines in README

View File

@ -17,15 +17,13 @@
# numbers for future use, the ELF soname can be set equal to the
# file name until some future date when a stable ABI is declared.
SHARED := 1
# for lib$(NAME).so and /usr/include/($NAME) and such
NAME := proc
SHARED := 1
###########
LIBVERSION := $(VERSION).$(SUBVERSION).$(MINORVERSION)
ABIVERSION := 1
ABIVERSION := 0
SOFILE := lib$(NAME)-$(LIBVERSION).so
ifneq ($(ABIVERSION),0)
@ -74,7 +72,7 @@ DIRS += proc/
proc/$(ANAME): $(LIBOBJ)
$(AR) rcs $@ $^
proc/$(SONAME): proc/library.map
#proc/$(SONAME): proc/library.map
proc/$(SONAME): $(LIBOBJ)
$(CC) -shared -Wl,-soname,$(SONAME) -Wl,--version-script=proc/library.map -o $@ $^ -lc

View File

@ -20,19 +20,16 @@
#define HASHSIZE 64 /* power of 2 */
#define HASH(x) ((x) & (HASHSIZE - 1))
#define NAMESIZE 20
#define NAMELENGTH "19"
static struct pwbuf {
struct pwbuf *next;
uid_t uid;
char name[NAMESIZE];
char name[P_G_SZ];
} *pwhash[HASHSIZE];
char *user_from_uid(uid_t uid)
{
char *user_from_uid(uid_t uid) {
struct pwbuf **p;
struct passwd *pw;
size_t len;
p = &pwhash[HASH(uid)];
while (*p) {
@ -43,10 +40,11 @@ char *user_from_uid(uid_t uid)
*p = (struct pwbuf *) xmalloc(sizeof(struct pwbuf));
(*p)->uid = uid;
pw = getpwuid(uid);
if (!pw)
sprintf((*p)->name, "%d", uid);
len = pw ? strlen(pw) : 0;
if (len >= P_G_SZ)
sprintf((*p)->name, "%u", uid);
else
sprintf((*p)->name, "%-." NAMELENGTH "s", pw->pw_name);
strcpy((*p)->name, pw->pw_name);
(*p)->next = NULL;
return((*p)->name);
}
@ -54,27 +52,28 @@ char *user_from_uid(uid_t uid)
static struct grpbuf {
struct grpbuf *next;
gid_t gid;
char name[NAMESIZE];
char name[P_G_SZ];
} *grphash[HASHSIZE];
char *group_from_gid(gid_t gid)
{
char *group_from_gid(gid_t gid) {
struct grpbuf **g;
struct group *gr;
size_t len;
g = &grphash[HASH(gid)];
while (*g) {
if ((*g)->gid == gid)
return((*g)->name);
g = &(*g)->next;
if ((*g)->gid == gid)
return((*g)->name);
g = &(*g)->next;
}
*g = (struct grpbuf *) malloc(sizeof(struct grpbuf));
(*g)->gid = gid;
gr = getgrgid(gid);
if (!gr)
sprintf((*g)->name, "%d", gid);
len = gr ? strlen(gr) : 0;
if (len >= P_G_SZ)
sprintf((*g)->name, "%u", gid);
else
sprintf((*g)->name, "%-." NAMELENGTH "s", gr->gr_name);
strcpy((*g)->name, gr->gr_name);
(*g)->next = NULL;
return((*g)->name);
}

View File

@ -6,6 +6,9 @@
EXTERN_C_BEGIN
// used in pwcache and in readproc to set size of username or groupname
#define P_G_SZ 20
extern char *user_from_uid(uid_t uid);
extern char *group_from_gid(gid_t gid);

View File

@ -523,21 +523,21 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
/* some number->text resolving which is time consuming */
if (flags & PROC_FILLUSR){
strncpy(p->euser, user_from_uid(p->euid), sizeof p->euser);
memcpy(p->euser, user_from_uid(p->euid), sizeof p->euser);
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);
memcpy(p->ruser, user_from_uid(p->ruid), sizeof p->ruser);
memcpy(p->suser, user_from_uid(p->suid), sizeof p->suser);
memcpy(p->fuser, user_from_uid(p->fuid), sizeof p->fuser);
}
}
/* some number->text resolving which is time consuming */
if (flags & PROC_FILLGRP){
strncpy(p->egroup, group_from_gid(p->egid), sizeof p->egroup);
memcpy(p->egroup, group_from_gid(p->egid), sizeof p->egroup);
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);
memcpy(p->rgroup, group_from_gid(p->rgid), sizeof p->rgroup);
memcpy(p->sgroup, group_from_gid(p->sgid), sizeof p->sgroup);
memcpy(p->fgroup, group_from_gid(p->fgid), sizeof p->fgroup);
}
}
@ -606,21 +606,21 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, const proc_t *restric
/* some number->text resolving which is time consuming */
if (flags & PROC_FILLUSR){
strncpy(t->euser, user_from_uid(t->euid), sizeof t->euser);
memcpy(t->euser, user_from_uid(t->euid), sizeof t->euser);
if(flags & PROC_FILLSTATUS) {
strncpy(t->ruser, user_from_uid(t->ruid), sizeof t->ruser);
strncpy(t->suser, user_from_uid(t->suid), sizeof t->suser);
strncpy(t->fuser, user_from_uid(t->fuid), sizeof t->fuser);
memcpy(t->ruser, user_from_uid(t->ruid), sizeof t->ruser);
memcpy(t->suser, user_from_uid(t->suid), sizeof t->suser);
memcpy(t->fuser, user_from_uid(t->fuid), sizeof t->fuser);
}
}
/* some number->text resolving which is time consuming */
if (flags & PROC_FILLGRP){
strncpy(t->egroup, group_from_gid(t->egid), sizeof t->egroup);
memcpy(t->egroup, group_from_gid(t->egid), sizeof t->egroup);
if(flags & PROC_FILLSTATUS) {
strncpy(t->rgroup, group_from_gid(t->rgid), sizeof t->rgroup);
strncpy(t->sgroup, group_from_gid(t->sgid), sizeof t->sgroup);
strncpy(t->fgroup, group_from_gid(t->fgid), sizeof t->fgroup);
memcpy(t->rgroup, group_from_gid(t->rgid), sizeof t->rgroup);
memcpy(t->sgroup, group_from_gid(t->sgid), sizeof t->sgroup);
memcpy(t->fgroup, group_from_gid(t->fgid), sizeof t->fgroup);
}
}

View File

@ -11,6 +11,7 @@
#include "procps.h"
#include "pwcache.h"
#define SIGNAL_STRING
@ -111,14 +112,14 @@ typedef struct proc_t {
**cmdline; // (special) command line string vector (/proc/#/cmdline)
char
// Be compatible: Digital allows 16 and NT allows 14 ???
euser[16], // stat(),status effective user name
ruser[16], // status real user name
suser[16], // status saved user name
fuser[16], // status filesystem user name
rgroup[16], // status real group name
egroup[16], // status effective group name
sgroup[16], // status saved group name
fgroup[16], // status filesystem group name
euser[P_G_SZ], // stat(),status effective user name
ruser[P_G_SZ], // status real user name
suser[P_G_SZ], // status saved user name
fuser[P_G_SZ], // status filesystem user name
rgroup[P_G_SZ], // status real group name
egroup[P_G_SZ], // status effective group name
sgroup[P_G_SZ], // status saved group name
fgroup[P_G_SZ], // status filesystem group name
cmd[16]; // stat,status basename of executable file in call to exec(2)
struct proc_t
*ring, // n/a thread group ring

View File

@ -81,7 +81,7 @@ static void hurt_proc(int tty, int uid, int pid, const char *restrict const cmd)
dev_to_tty(dn_buf, 999, tty, pid, ABBREV_DEV);
if(i_flag){
char buf[8];
fprintf(stderr, "%-8.8s %-8.8s %5d %-16.16s ? ",
fprintf(stderr, "%-8s %-8s %5d %-16.16s ? ",
(char*)dn_buf,user_from_uid(uid),pid,cmd
);
if(!fgets(buf,7,stdin)){
@ -95,7 +95,7 @@ static void hurt_proc(int tty, int uid, int pid, const char *restrict const cmd)
else failed=setpriority(PRIO_PROCESS,pid,sig_or_pri);
saved_errno = errno;
if(w_flag && failed){
fprintf(stderr, "%-8.8s %-8.8s %5d %-16.16s ",
fprintf(stderr, "%-8s %-8s %5d %-16.16s ",
(char*)dn_buf,user_from_uid(uid),pid,cmd
);
errno = saved_errno;
@ -104,7 +104,7 @@ static void hurt_proc(int tty, int uid, int pid, const char *restrict const cmd)
}
if(i_flag) return;
if(v_flag){
printf("%-8.8s %-8.8s %5d %-16.16s\n",
printf("%-8s %-8s %5d %-16.16s\n",
(char*)dn_buf,user_from_uid(uid),pid,cmd
);
return;