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 (!smack_smackfs_path()) 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) { const char *tmp = smack_smackfs_path(); if (argc < 2) { fprintf(stderr, "Usage: %s <action>\n", argv[0]); exit(1); } if (!strcmp(argv[1], "apply")) { if (apply_all()) exit(1); } else if (!strcmp(argv[1], "clear")) { if (clear()) exit(1); } else if (!strcmp(argv[1], "status")) { if (smack_smackfs_path()) printf("SmackFS is mounted to %s.\n", smack_smackfs_path()); else printf("SmackFS is not mounted.\n"); exit(0); } fprintf(stderr, "Uknown action: %s\n", argv[1]); exit(1); }
void SmackRules::uninstallRules(const std::string &path) { if (access(path.c_str(), F_OK) == -1) { if (errno == ENOENT) { LogWarning("Smack rules not found in file: " << path); return; } LogWarning("Cannot access smack rules path: " << path); ThrowMsg(SmackException::FileError, "Cannot access smack rules path: " << path); } try { SmackRules rules; rules.loadFromFile(path); if (smack_smackfs_path()) rules.clear(); } catch (const SmackException::Base &e) { LogWarning("Failed to clear smack kernel rules from file: " << path); // don't stop uninstallation } if (unlink(path.c_str()) == -1) { LogWarning("Failed to remove smack rules file: " << path); ThrowMsg(SmackException::FileError, "Failed to remove smack rules file: " << path); } }
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); }
void SmackRules::updatePackageRules(const std::string &pkgId, const std::vector<std::string> &pkgContents) { SmackRules smackRules; std::string pkgPath = getPackageRulesFilePath(pkgId); smackRules.generatePackageCrossDeps(pkgContents); if (smack_smackfs_path() != NULL) smackRules.apply(); smackRules.saveToFile(pkgPath); }
void SmackRules::installApplicationRules(const std::string &appId, const std::string &pkgId, const std::vector<std::string> &pkgContents) { SmackRules smackRules; std::string appPath = getApplicationRulesFilePath(appId); smackRules.addFromTemplateFile(appId, pkgId); if (smack_smackfs_path() != NULL) smackRules.apply(); smackRules.saveToFile(appPath); updatePackageRules(pkgId, pkgContents); }
static int apply_all(void) { if (!smack_smackfs_path()) { fprintf(stderr, "SmackFS is not mounted.\n"); return -1; } if (clear()) return -1; if (apply_rules(ACCESSES_D_PATH, 0)) return -1; if (apply_cipso(CIPSO_D_PATH)) return -1; return 0; }
int main(int argc, char **argv) { int c; for ( ; ; ) { c = getopt_long(argc, argv, short_options, options, NULL); if (c == -1) break; switch (c) { case 'v': printf("%s (libsmack) version " PACKAGE_VERSION "\n", basename(argv[0])); exit(0); case 'h': printf(usage, basename(argv[0])); exit(0); default: printf(usage, basename(argv[0])); exit(1); } } if (!smack_smackfs_path()) { fprintf(stderr, "SmackFS is not mounted.\n"); exit(1); } if ((argc - optind) > 1) { printf(usage, basename(argv[0])); exit(1); } if (argc == 1) { if (apply_cipso(NULL)) exit(1); } else { if (apply_cipso(argv[1])) exit(1); } exit(0); }
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; }
int main(int argc, char **argv) { if (!smack_smackfs_path()) { fprintf(stderr, "SmackFS is not mounted.\n"); exit(1); } if (argc > 2) { fprintf(stderr, "Usage: %s <path>\n", argv[0]); exit(1); } if (argc == 1) { if (apply_cipso_file(STDIN_FILENO)) exit(1); } else { if (apply_cipso(argv[1])) exit(1); } exit(0); }
int is_smackfs_mounted(void) { struct statfs sfs; int ret; const char * smack_mnt; smack_mnt = smack_smackfs_path(); if (!smack_mnt) { errno = EFAULT; return -1; } do { ret = statfs(smack_mnt, &sfs); } while (ret < 0 && errno == EINTR); if (ret) return -1; if (sfs.f_type == SMACK_MAGIC) return 1; return 0; }