int clear(void) { int fd; int ret; const char * smack_mnt; char path[PATH_MAX]; smack_mnt = smack_smackfs_path(); if (!smack_mnt) { errno = EFAULT; return -1; } if (is_smackfs_mounted() != 1) return -1; snprintf(path, sizeof path, "%s/load2", smack_mnt); fd = open(path, O_RDONLY); if (fd < 0) return -1; ret = apply_rules_file(fd, 1); close(fd); return ret; }
int main(int argc, char **argv) { int clear = 0; int c; if (!smack_smackfs_path()) { fprintf(stderr, "SmackFS is not mounted.\n"); exit(1); } while ((c = getopt(argc, argv, "c")) != -1) { switch (c) { case 'c': clear = 1; break; default: usage(argv[0]); } } if (optind == argc) { if (apply_rules_file(STDIN_FILENO, clear)) exit(1); } else { if (apply_rules(argv[optind], clear)) exit(1); } exit(0); }
int apply_rules(const char *path, int clear) { struct stat sbuf; int fd; int ret; if (stat(path, &sbuf)) { fprintf(stderr, "stat() failed for '%s' : %s\n", path, strerror(errno)); return -1; } if (S_ISDIR(sbuf.st_mode)) return nftw(path, apply_rules_cb, 1, FTW_PHYS|FTW_ACTIONRETVAL); fd = open(path, O_RDONLY); if (fd < 0) { fprintf(stderr, "open() failed for '%s' : %s\n", path, strerror(errno)); return -1; } ret = apply_rules_file(fd, clear); if (ret) fprintf(stderr, "Applying rules failed for '%s'.\n", path); close(fd); return ret; }
static int apply_cipso_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { int fd; int ret; if (typeflag == FTW_D) return ftwbuf->level ? FTW_SKIP_SUBTREE : FTW_CONTINUE; else if (typeflag != FTW_F) return FTW_STOP; fd = open(fpath, O_RDONLY); if (fd < 0) return -1; ret = apply_rules_file(fd, 0) ? FTW_STOP : FTW_CONTINUE; close(fd); return ret; }
int apply_rules(const char *path, int clear) { struct stat sbuf; int fd; int ret; errno = 0; if (stat(path, &sbuf)) return -1; if (S_ISDIR(sbuf.st_mode)) return nftw(path, apply_rules_cb, 1, FTW_PHYS|FTW_ACTIONRETVAL); fd = open(path, O_RDONLY); if (fd < 0) return -1; ret = apply_rules_file(fd, clear); close(fd); return ret; }
int clear(void) { int fd; int ret; const char * smack_mnt; char path[PATH_MAX]; smack_mnt = smack_smackfs_path(); if (!smack_mnt) return -1; snprintf(path, sizeof path, "%s/load2", smack_mnt); fd = open(path, O_RDONLY); if (fd < 0) { fprintf(stderr, "open() failed for '%s' : %s\n", path, strerror(errno)); return -1; } ret = apply_rules_file(fd, 1); close(fd); return ret; }
static int apply_rules_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { int fd; int ret; if (typeflag == FTW_D) return ftwbuf->level ? FTW_SKIP_SUBTREE : FTW_CONTINUE; else if (typeflag != FTW_F) return FTW_STOP; fd = open(fpath, O_RDONLY); if (fd < 0) { fprintf(stderr, "open() failed for '%s' : %s\n", fpath, strerror(errno)); return -1; } ret = apply_rules_file(fd, 0) ? FTW_STOP : FTW_CONTINUE; if (ret == FTW_STOP) fprintf(stderr, "Applying rules failed for '%s'.\n", fpath); close(fd); return ret; }