diff options
Diffstat (limited to 'auto-uid.c')
| -rw-r--r-- | auto-uid.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/auto-uid.c b/auto-uid.c new file mode 100644 index 0000000..326051c --- /dev/null +++ b/auto-uid.c | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | #include <sys/types.h> | ||
| 2 | #include <pwd.h> | ||
| 3 | #include "subfd.h" | ||
| 4 | #include "substdio.h" | ||
| 5 | #include "readwrite.h" | ||
| 6 | #include "exit.h" | ||
| 7 | #include "scan.h" | ||
| 8 | #include "fmt.h" | ||
| 9 | |||
| 10 | char buf1[256]; | ||
| 11 | substdio ss1 = SUBSTDIO_FDBUF(write,1,buf1,sizeof(buf1)); | ||
| 12 | |||
| 13 | void outs(s) /* was named puts, but Solaris pwd.h includes stdio.h. dorks. */ | ||
| 14 | char *s; | ||
| 15 | { | ||
| 16 | if (substdio_puts(&ss1,s) == -1) _exit(111); | ||
| 17 | } | ||
| 18 | |||
| 19 | void main(argc,argv) | ||
| 20 | int argc; | ||
| 21 | char **argv; | ||
| 22 | { | ||
| 23 | char *name; | ||
| 24 | char *value; | ||
| 25 | struct passwd *pw; | ||
| 26 | char strnum[FMT_ULONG]; | ||
| 27 | |||
| 28 | name = argv[1]; | ||
| 29 | if (!name) _exit(100); | ||
| 30 | value = argv[2]; | ||
| 31 | if (!value) _exit(100); | ||
| 32 | |||
| 33 | pw = getpwnam(value); | ||
| 34 | if (!pw) { | ||
| 35 | substdio_puts(subfderr,"fatal: unable to find user "); | ||
| 36 | substdio_puts(subfderr,value); | ||
| 37 | substdio_puts(subfderr,"\n"); | ||
| 38 | substdio_flush(subfderr); | ||
| 39 | _exit(111); | ||
| 40 | } | ||
| 41 | |||
| 42 | strnum[fmt_ulong(strnum,(unsigned long) pw->pw_uid)] = 0; | ||
| 43 | |||
| 44 | outs("int "); | ||
| 45 | outs(name); | ||
| 46 | outs(" = "); | ||
| 47 | outs(strnum); | ||
| 48 | outs(";\n"); | ||
| 49 | if (substdio_flush(&ss1) == -1) _exit(111); | ||
| 50 | _exit(0); | ||
| 51 | } | ||
