/* * Copyright (c) 2022 Daniel Kroczynski * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include "blind.h" #include "log.h" struct blind * config_init(void); int config_perm(int, const char *); struct blind * config_init(void) { struct blind *cfg; if ((cfg = calloc(1, sizeof(*cfg))) == NULL) return cfg; if (strlcpy(cfg->bl_sock, BL_SOCK, PATH_MAX) >= PATH_MAX) log_fatal("socket file name exceeds PATH_MAX"); cfg->bl_ttl = BL_TTL; cfg->bl_opt = BL_OPT_DEFAULT; return cfg; } int config_perm(int fd, const char *name) { struct stat st; if (fstat(fd, &st)) { log_debug("cannot stat config file"); return (-1); } if (st.st_uid != 0 && st.st_uid != getuid()) { log_debug("not root or current user owned"); return (-1); } if (st.st_mode & (S_IWGRP | S_IXGRP | S_IRWXO)) { log_debug("insecure config file"); return (-1); } return (0); }