|
|
1.1 root 1: /*
2: * chown uid file ...
3: */
4:
5: #include <stdio.h>
6: #include <ctype.h>
7: #include <sys/types.h>
8: #include <sys/stat.h>
9: #include <pwd.h>
10:
11: struct passwd *pwd,*getpwnam();
12: struct stat stbuf;
13: int uid;
14: int status;
15:
16: main(argc, argv)
17: char *argv[];
18: {
19: register c;
20:
21: if(argc < 3) {
22: printf("usage: chown uid file ...\n");
23: exit(4);
24: }
25: if(isnumber(argv[1])) {
26: uid = atoi(argv[1]);
27: goto cho;
28: }
29: if((pwd=getpwnam(argv[1])) == NULL) {
30: printf("unknown user id: %s\n",argv[1]);
31: exit(4);
32: }
33: uid = pwd->pw_uid;
34:
35: cho:
36: for(c=2; c<argc; c++) {
37: stat(argv[c], &stbuf);
38: if(chown(argv[c], uid, stbuf.st_gid) < 0) {
39: perror(argv[c]);
40: status = 1;
41: }
42: }
43: exit(status);
44: }
45:
46: isnumber(s)
47: char *s;
48: {
49: register c;
50:
51: while(c = *s++)
52: if(!isdigit(c))
53: return(0);
54: return(1);
55: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.