/* SPDX-License-Identifier: GPL-3.0-only */ /* SPDX-FileCopyrightText: 2026 afiw */ /* * can - query filesystem permissions * Copyright (C) 2026 afiw * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, exclusively version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include "action.h" int action_of_cstring(char const* cstring) { if (strcmp(cstring, "read") == 0) { return ACTION_READ; } else if (strcmp(cstring, "write") == 0) { return ACTION_WRITE; } else if (strcmp(cstring, "edit") == 0) { return ACTION_WRITE; } else if (strcmp(cstring, "execute") == 0) { return ACTION_EXECUTE; } else if (strcmp(cstring, "run") == 0) { return ACTION_EXECUTE; } errno = EINVAL; return -1; } mode_t user_bit_of_action(enum action action) { return (mode_t[]){ [ACTION_READ] = S_IRUSR, [ACTION_WRITE] = S_IWUSR, [ACTION_EXECUTE] = S_IXUSR }[action]; } mode_t group_bit_of_action(enum action action) { return (mode_t[]){ [ACTION_READ] = S_IRGRP, [ACTION_WRITE] = S_IWGRP, [ACTION_EXECUTE] = S_IXGRP }[action]; } mode_t other_bit_of_action(enum action action) { return (mode_t[]){ [ACTION_READ] = S_IROTH, [ACTION_WRITE] = S_IWOTH, [ACTION_EXECUTE] = S_IXOTH }[action]; }