ipsvd patch
Nikola Vladov <[email protected]>
| Newsgroups | gmane.comp.misc.pape.general |
|---|---|
| Message-ID | <[email protected]> |
I sudjest a replacemat of uidgid.c
I'll spport numeric UID/GID
expample:
-u 123:456
It can be also dangerous. Let for example /etc/passwd has line:
123:x:1000:1000:Bad user:/home/Bad_user:/bin/bash
If one use option -u 123
the program will have UID=123 instad of 1000.
In this case use -u 1000 instead of -u 123.
Have anybody seen such /etc/passwd?
Nikola
----------------------- uidgid.c --------------------------
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#include "uidgid.h"
#include "str.h"
#include "error.h"
#include "scan.h"
unsigned int uidgid_get(struct uidgid *u, char *ug, unsigned int dogrp) {
char *g =0;
struct passwd *pwd =0;
struct group *gr =0;
int d =0;
unsigned long ul;
uid_t uid;
gid_t gid;
if (dogrp)
if (ug[(d =str_chr(ug, ':'))] == ':') {
ug[d] =0;
g =ug +d +1;
}
errno =0;
if (scan_ulong(ug, &ul)) {
uid =ul;
gid =ul;
} else {
pwd =getpwnam(ug);
if (! pwd) {
if (g) ug[d] =':';
return(0);
}
uid =pw->pw_uid;
gid =pw->pw_gid;
}
if (g) {
ug[d] =':';
errno =0;
if (scan_ulong(g, &ul)) {
gid =ul;
} else {
gr =getgrnam(g);
if (! gr) return(0);
gid =gr->gr_gid;
}
}
u->gid =gid;
u->uid =uid;
return(1);
}