chiark / gitweb /
Upgrade licence to GPLv3+.
[tripe] / common / util.h
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 it under
13  * the terms of the GNU General Public License as published by the Free
14  * Software Foundation; either version 3 of the License, or (at your
15  * option) any later version.
16  *
17  * TrIPE is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with TrIPE.  If not, see <https://www.gnu.org/licenses/>.
24  */
25
26 #ifndef UTIL_H
27 #define UTIL_H
28
29 #ifndef CONFIG_H
30 #  include "config.h"
31 #endif
32
33 #include <sys/types.h>
34
35 #include <mLib/macros.h>
36
37 #ifdef __cplusplus
38   extern "C" {
39 #endif
40
41 /*----- Functions provided ------------------------------------------------*/
42
43 /* --- @u_quotify@ --- *
44  *
45  * Arguments:   @dstr *d@ = where to write the answer
46  *              @const char *p@ = string to quotify
47  *
48  * Returns:     ---
49  *
50  * Use:         Quotes the given string if necessary, according to our
51  *              quoting rules.
52  */
53
54 extern void u_quotify(dstr */*d*/, const char */*p*/);
55
56 /* --- @u_getuser@ --- *
57  *
58  * Arguments:   @const char *name@ = user name or id requested
59  *              @gid_t *gg@ = where to store corresponding gid
60  *
61  * Returns:     Corresponding uid.
62  *
63  * Use:         Resolves a user name into a uid.  Dies on failure; suitable
64  *              for use in argument parsing.
65  */
66
67 extern uid_t u_getuser(const char */*name*/, gid_t */*gg*/);
68
69 /* --- @u_getgroup@ --- *
70  *
71  * Arguments:   @const char *name@ = user name or id requested
72  *
73  * Returns:     Corresponding gid.
74  *
75  * Use:         Resolves a group name into a gid.  Dies on failure; suitable
76  *              for use in argument parsing.
77  */
78
79 extern gid_t u_getgroup(const char */*name*/);
80
81 /* --- @u_setugid@ --- *
82  *
83  * Arguments:   @uid_t u@ = user to set
84  *              @gid_t g@ = group to set
85  *
86  * Returns:     ---
87  *
88  * Use:         Sets user and group to the given values; aborts on failure.
89  */
90
91 extern void u_setugid(uid_t /*u*/, gid_t /*g*/);
92
93 /*----- That's all, folks -------------------------------------------------*/
94
95 #ifdef __cplusplus
96   }
97 #endif
98
99 #endif