#include #include #include #include #include #include int main(argc,argv) int argc; char *argv[]; { int euid; struct passwd *p; char *user; euid=geteuid(); seteuid(geteuid()); if (argc != 2) { fprintf(stderr, "Usage: %s netid\n", argv[0]); exit(1); } if (strlen(argv[1]) > 8) { fprintf(stderr, "Username too long.\nUsage: %s netid\n", argv[0]); exit(1); } /* make sure the user exists */ if ((p=getpwnam(argv[1])) == NULL) { fprintf(stderr, "Username %s does not exist!\nUsage: %s netid\n", argv[1], argv[0]); } /* only check quotas of users with uid 100 or above */ if (p->pw_uid < 100) { fprintf(stderr, "You may not check that user's quota.\nUsage: %s netid\n", argv[0]); exit(1); } /* * set our real/effective uid to that of the user we're checking and * run the real quota program */ if (0 != seteuid(euid)) { fprintf(stderr, "Could not set euid\n"); perror("magicquota: seteuid"); exit(1); } /* * quota -v will fail silently if the homedir is not mounted. * changing to the user's home directory will force an automount. */ if (chdir(p->pw_dir) != 0) { fprintf(stderr, "Could not change to the user's homedir.\n"); perror("magicquota: chdir"); } execl("/usr/sbin/quota","quota","-v",argv[1],NULL); fprintf(stderr, "exec failed!\n"); exit(1); }