| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * Utilities for the client and the server |
| 4 | * |
| 5 | * (c) 2001 Straylight/Edgeware |
| 6 | */ |
| 7 | |
| 8 | /*----- Licensing notice --------------------------------------------------* |
| 9 | * |
| 10 | * This file is part of Trivial IP Encryption (TrIPE). |
| 11 | * |
| 12 | * TrIPE is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * TrIPE is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with TrIPE; if not, write to the Free Software Foundation, |
| 24 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | */ |
| 26 | |
| 27 | #ifndef UTIL_H |
| 28 | #define UTIL_H |
| 29 | |
| 30 | #ifndef CONFIG_H |
| 31 | # include "config.h" |
| 32 | #endif |
| 33 | |
| 34 | #include <sys/types.h> |
| 35 | |
| 36 | #ifdef __cplusplus |
| 37 | extern "C" { |
| 38 | #endif |
| 39 | |
| 40 | /*----- Macros ------------------------------------------------------------*/ |
| 41 | |
| 42 | /* --- @IGNORE@ --- * |
| 43 | * |
| 44 | * Arguments: @expr@ = an expression whose value is to be ignored |
| 45 | * |
| 46 | * Use: Ignores the value of an expression, even if compilers want |
| 47 | * us not to. |
| 48 | */ |
| 49 | |
| 50 | #define IGNORE(expr) do { if (expr) ; } while (0) |
| 51 | |
| 52 | /*----- Functions provided ------------------------------------------------*/ |
| 53 | |
| 54 | /* --- @u_quotify@ --- * |
| 55 | * |
| 56 | * Arguments: @dstr *d@ = where to write the answer |
| 57 | * @const char *p@ = string to quotify |
| 58 | * |
| 59 | * Returns: --- |
| 60 | * |
| 61 | * Use: Quotes the given string if necessary, according to our |
| 62 | * quoting rules. |
| 63 | */ |
| 64 | |
| 65 | extern void u_quotify(dstr */*d*/, const char */*p*/); |
| 66 | |
| 67 | /* --- @u_getuser@ --- * |
| 68 | * |
| 69 | * Arguments: @const char *name@ = user name or id requested |
| 70 | * @gid_t *gg@ = where to store corresponding gid |
| 71 | * |
| 72 | * Returns: Corresponding uid. |
| 73 | * |
| 74 | * Use: Resolves a user name into a uid. Dies on failure; suitable |
| 75 | * for use in argument parsing. |
| 76 | */ |
| 77 | |
| 78 | extern uid_t u_getuser(const char */*name*/, gid_t */*gg*/); |
| 79 | |
| 80 | /* --- @u_getgroup@ --- * |
| 81 | * |
| 82 | * Arguments: @const char *name@ = user name or id requested |
| 83 | * |
| 84 | * Returns: Corresponding gid. |
| 85 | * |
| 86 | * Use: Resolves a group name into a gid. Dies on failure; suitable |
| 87 | * for use in argument parsing. |
| 88 | */ |
| 89 | |
| 90 | extern gid_t u_getgroup(const char */*name*/); |
| 91 | |
| 92 | /* --- @u_setugid@ --- * |
| 93 | * |
| 94 | * Arguments: @uid_t u@ = user to set |
| 95 | * @gid_t g@ = group to set |
| 96 | * |
| 97 | * Returns: --- |
| 98 | * |
| 99 | * Use: Sets user and group to the given values; aborts on failure. |
| 100 | */ |
| 101 | |
| 102 | extern void u_setugid(uid_t /*u*/, gid_t /*g*/); |
| 103 | |
| 104 | /*----- That's all, folks -------------------------------------------------*/ |
| 105 | |
| 106 | #ifdef __cplusplus |
| 107 | } |
| 108 | #endif |
| 109 | |
| 110 | #endif |