|
|
1.1 root 1: /*
2: * Change the group owner of specified files.
3: */
4:
5: /*
6: * chgrp didn't check numerical group id; prints out strange
7: * error messages, didn't check effective uid. Fixed 1-06-91. Vlad.
8: */
9:
10: #include <stdio.h>
11: #include <sys/stat.h>
12: #include <grp.h>
13: #include <ctype.h> /* Vlad */
14:
15: main(argc, argv)
16: char *argv[];
17: {
18: register struct group *grp;
19: register int c;
20: register short owner, group;
21: struct stat sb;
22: register short status = 0;
23:
24: /* Only superuser can invoke chgrp under COHERENT. Vlad */
25: if (geteuid())
26: cherr("not a super user\n");
27:
28: if (argc < 3)
29: usage();
30:
31: /* You can specify group by numeric id or by name. Vlad */
32: if (isdigit((int) *argv[1])) {
33: if ((grp = getgrgid(atoi(argv[1]))) == NULL)
34: cherr("bad numeric group id `%s'\n", argv[1]);
35: } else
36: if ((grp = getgrnam(argv[1])) == NULL)
37: cherr("bad group name `%s'\n", argv[1]);
38:
39: group = grp->gr_gid;
40:
41: for (c = 2; c < argc; c++) {
42: owner = 0;
43: if (stat(argv[c], &sb) >= 0)
44: owner = sb.st_uid;
45: if (chown(argv[c], owner, group) < 0) {
46: perror(argv[c]);
47: status = 2;
48: }
49: }
50: exit (status);
51: }
52:
53: usage()
54: {
55: fprintf(stderr, "Usage: chgrp group file ...\n");
56: exit(1);
57: }
58:
59: /* VARARGS */
60: cherr(x)
61: {
62: fprintf(stderr, "chgrp: %r", &x);
63: exit(2);
64: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.