|
|
1.1 ! root 1: /* do_check.c - Execute a file check for the current file context. ! 2: * part of uucheck ! 3: */ ! 4: #include <sys/stat.h> ! 5: #include <pwd.h> ! 6: #include <grp.h> ! 7: #include "y.tab.h" ! 8: #include "checkperms.h" ! 9: ! 10: void ! 11: do_check(message_type, check_type, optional_message) ! 12: int message_type; ! 13: int check_type; ! 14: char *optional_message; ! 15: { ! 16: switch(check_type) { ! 17: case CHMOD_PERMISSION: ! 18: if(!it_exists) break; /* Skip this if the file does not exist. */ ! 19: /* NB: chmod_chk has LOTS of output side effects. */ ! 20: if(!chmod_chk(current_path, chmod_string, ¤t_stat, message_type)) { ! 21: notice(message_type, optional_message, basename(current_path)); ! 22: } ! 23: break; /* CHMOD_PERMISSION */ ! 24: case EXIST: ! 25: if(!it_exists){ ! 26: notice(message_type, "%s does not exist.", current_path); ! 27: notice(message_type, optional_message, basename(current_path)); ! 28: } /* if it does not exist. */ ! 29: break; /* EXIST */ ! 30: case FILE_TOKEN: ! 31: if(!it_exists) { /* Try to fix non-existence. */ ! 32: sprintf(command, "touch %s", current_path); ! 33: sprintf(bigbuf, "You can fix it with \"%s\".\n", command); ! 34: VERBOSE(bigbuf); ! 35: FIX(system(command); it_exists = TRUE;); ! 36: } /* if !it_exists */ ! 37: if (FMODE(current_stat)&S_IFREG == 0){ ! 38: notice(message_type, "%s is not a regular file.", current_path); ! 39: notice(message_type, optional_message, basename(current_path)); ! 40: VERBOSE("You might consider reinstalling everything.\n"); ! 41: } ! 42: break; /* FILE_TOKEN */ ! 43: case DIRECTORY: ! 44: if(!it_exists) { /* Try to fix non-existence. */ ! 45: sprintf(command, "mkdir %s", current_path); ! 46: sprintf(bigbuf, "You can fix it with \"%s\".\n", command); ! 47: VERBOSE(bigbuf); ! 48: FIX(system(command); it_exists = TRUE; ); ! 49: } /* if !it_exists */ ! 50: if (FMODE(current_stat)&S_IFDIR == 0){ ! 51: notice(message_type, "%s is not a directory.", current_path); ! 52: notice(message_type, optional_message, basename(current_path)); ! 53: VERBOSE("You might consider reinstalling everything.\n"); ! 54: } ! 55: break; /* DIRECTORY */ ! 56: case PIPE: ! 57: if(!it_exists) { /* Try to fix non-existence. */ ! 58: sprintf(command, "mknod %s p", current_path); ! 59: sprintf(bigbuf, "You can fix it with \"%s\".\n", command); ! 60: VERBOSE(bigbuf); ! 61: FIX(system(command); it_exists = TRUE; ); ! 62: } /* if !it_exists */ ! 63: if (FMODE(current_stat)&S_IFPIP == 0){ ! 64: notice(message_type, "%s is not a pipe.", current_path); ! 65: notice(message_type, optional_message, basename(current_path)); ! 66: VERBOSE("You might consider reinstalling everything.\n"); ! 67: } ! 68: break; /* PIPE */ ! 69: case CHARACTER_SPECIAL: ! 70: if(!it_exists) { /* Try to fix non-existence. */ ! 71: sprintf(command, "mknod %s c %d %d", current_path, ! 72: major, minor); ! 73: sprintf(bigbuf, "You can fix it with \"%s\".\n", command); ! 74: VERBOSE(bigbuf); ! 75: FIX(system(command); it_exists = TRUE; ); ! 76: } /* if !it_exists */ ! 77: if(!it_exists) break; /* Skip this if the file does not exist. */ ! 78: if (FMODE(current_stat)&S_IFCHR == 0){ ! 79: notice(message_type, "%s is not a character special device.", current_path); ! 80: notice(message_type, optional_message, basename(current_path)); ! 81: VERBOSE("You might consider reinstalling everything.\n"); ! 82: } ! 83: break; /* CHARACTER_SPECIAL */ ! 84: case BLOCK_SPECIAL: ! 85: if(!it_exists) { /* Try to fix non-existence. */ ! 86: sprintf(command, "mknod %s b %d %d", current_path, ! 87: major, minor); ! 88: sprintf(bigbuf, "You can fix it with \"%s\".\n", command); ! 89: VERBOSE(bigbuf); ! 90: FIX(system(command); it_exists = TRUE; ); ! 91: } /* if !it_exists */ ! 92: if(!it_exists) break; /* Skip this if the file does not exist. */ ! 93: if (FMODE(current_stat)&S_IFBLK == 0){ ! 94: notice(message_type, "%s is not a block special device.", current_path); ! 95: notice(message_type, optional_message, basename(current_path)); ! 96: VERBOSE("You might consider reinstalling everything.\n"); ! 97: } ! 98: break; /* BLOCK_SPECIAL */ ! 99: case OWNER: ! 100: if(!it_exists) break; /* Skip this if the file does not exist. */ ! 101: if(!owner_chk(current_path, ! 102: id_string, ! 103: ¤t_stat, ! 104: message_type, ! 105: optional_message)) { ! 106: notice(message_type, optional_message, basename(current_path)); ! 107: } /* if owner does not check out. */ ! 108: break; /* BLOCK_SPECIAL */ break; /* OWNER */ ! 109: case GROUP: ! 110: if(!it_exists) break; /* Skip this if the file does not exist. */ ! 111: if(!group_chk(current_path, ! 112: id_string, ! 113: ¤t_stat, ! 114: message_type, ! 115: optional_message)) { ! 116: notice(message_type, optional_message, basename(current_path)); ! 117: } /* if owner does not check out. */ ! 118: break; /* GROUP */ ! 119: default: ! 120: FATAL("Impossible check type: %d\n", check_type); ! 121: } /* switch check_type */ ! 122: } /* do_check() */ ! 123: ! 124: ! 125: boolean ! 126: owner_chk(path, id_string, statptr, msg_type, optional_message) ! 127: unsigned char *path; ! 128: unsigned char *id_string; ! 129: struct stat *statptr; ! 130: int msg_type; /* Error messages or just warning messages? */ ! 131: char *optional_message; ! 132: { ! 133: struct passwd *tmp_pwd; ! 134: ! 135: /* fill in statptr if it isn't already */ ! 136: if (statptr == (struct stat *) NULL) { ! 137: statptr = (struct stat *) malloc(sizeof(struct stat)); ! 138: stat(path, statptr); ! 139: } ! 140: ! 141: /* Translate the expected user name to a uid. We want to ! 142: * do this instead of converting the uid in the stat struct to a ! 143: * string, because more than one user could have the same uid. ! 144: * With "uucp" this even happens frequently. ! 145: */ ! 146: if ((tmp_pwd = getpwnam(id_string)) == NULL) { ! 147: sprintf(bigbuf, "User %s does not exist!\n", id_string); ! 148: ERROR(bigbuf); ! 149: VERBOSE("Use the newusr command to add this user.\n"); ! 150: FATAL(NULL, NULL); ! 151: } ! 152: ! 153: if (tmp_pwd->pw_uid != statptr->st_uid) { ! 154: sprintf(bigbuf, "%s is not owned by %s.", path, id_string); ! 155: notice(msg_type, bigbuf, NULL); ! 156: notice(msg_type, optional_message, basename(path)); ! 157: sprintf(command, "chown %s %s", id_string, path); ! 158: sprintf(bigbuf, "Use \"%s\" to fix this.\n", command); ! 159: VERBOSE(bigbuf); ! 160: FIX(system(command);); ! 161: } /* if (id != statptr->st_uid) */ ! 162: ! 163: } /* owner_chk() */ ! 164: ! 165: boolean ! 166: group_chk(path, id_string, statptr, msg_type, optional_message) ! 167: unsigned char *path; ! 168: unsigned char *id_string; ! 169: struct stat *statptr; ! 170: int msg_type; /* Error messages or just warning messages? */ ! 171: char *optional_message; ! 172: { ! 173: struct group *tmp_grp; ! 174: ! 175: ! 176: /* fill in statptr if it isn't already */ ! 177: if (statptr == (struct stat *) NULL) { ! 178: statptr = (struct stat *) malloc(sizeof(struct stat)); ! 179: stat(path, statptr); ! 180: } ! 181: ! 182: /* Translate the expected group name to a gid. We want to ! 183: * do this instead of converting the gid in the stat struct to a ! 184: * string, because more than one group could have the same gid. ! 185: */ ! 186: if ((tmp_grp = getgrnam(id_string)) == NULL) { ! 187: sprintf(bigbuf, "Group %s does not exist!\n", id_string); ! 188: ERROR(bigbuf); ! 189: VERBOSE("Edit /etc/group to add this group.\n"); ! 190: FATAL(NULL, NULL); ! 191: } ! 192: ! 193: if (tmp_grp->gr_gid != statptr->st_gid) { ! 194: sprintf(bigbuf, "%s is not group %s.", path, id_string); ! 195: notice(msg_type, bigbuf, NULL); ! 196: notice(msg_type, optional_message, basename(path)); ! 197: sprintf(command, "chgrp %s %s", id_string, path); ! 198: sprintf(bigbuf, "Use \"%s\" to fix this.\n", command); ! 199: VERBOSE(bigbuf); ! 200: FIX(system(command);); ! 201: } /* if (id != statptr->st_uid) */ ! 202: ! 203: } /* group_chk() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.