Debian Codegraph @

secmem/util.c

raw symbols SCIP
1 /* Quintuple Agent
2 * Copyright (C) 1999 Robert Bihlmeyer <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301.
17 */
18
19 #define _GNU_SOURCEcxx . . $ `secmem/util.c:19:9`! 1
20
21 #include <unistd.h>
22 #include <errno.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <assert.h>
28
29 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:412:9`!
30 #include "config.h"cxx . . $ `<file>/config.h`/
31 #endif
32
33 #include "util.h"cxx . . $ `<file>/secmem/util.h`/
34
35 #ifndef TEMP_FAILURE_RETRYcxx . . $ `<external>/12628407106812493757/unistd.h:1134:10`!
36 #define TEMP_FAILURE_RETRY(expression) \
37 (__extension__ \
38 ({ long int __result; \
39 do __result = (long int) (expression); \
40 while (__result == -1L && errno == EINTR); \
41 __result; }))
42 #endif
43
44 #ifndef HAVE_DOSISH_SYSTEM
45 static int uid_setcxx . . $ uid_set. = 0;
46 static uid_tcxx . . $ uid_t# real_uidcxx . . $ real_uid., file_uidcxx . . $ file_uid.;
47 #endif /*!HAVE_DOSISH_SYSTEM*/
48
49 /* write DATA of size BYTES to FD, until all is written or an error occurs */
50 ssize_tcxx . . $ ssize_t# xwritecxx . . $ xwrite(41184a59d38b4f65).(int fd, const void *data, size_tcxx . . $ size_t# bytes)
51 {
52 char *ptr;
53 size_tcxx . . $ size_t# todo;
54 ssize_tcxx . . $ ssize_t# written = 0;
55
56 for (ptr = (char *)data, todo = bytes; todo; ptr += written, todo -= written)
57 if ((written = TEMP_FAILURE_RETRYcxx . . $ `<external>/12628407106812493757/unistd.h:1134:10`!(write(fd, ptr, todo))) < 0)
58 break;
59 return written;
60 }
61
62 #if 0
63 extern int debug;
64
65 int debugmsg(const char *fmt, ...)
66 {
67 va_list va;
68 int ret;
69
70 if (debug) {
71 va_start(va, fmt);
72 fprintf(stderr, "\e[4m");
73 ret = vfprintf(stderr, fmt, va);
74 fprintf(stderr, "\e[24m");
75 va_end(va);
76 return ret;
77 } else
78 return 0;
79 }
80 #endif
81
82 /* initialize uid variables */
83 #ifndef HAVE_DOSISH_SYSTEM
84 static void init_uidscxx . . $ init_uids(49f6e7a06ebc5aa8).(void)
85 {
86 real_uidcxx . . $ real_uid. = getuidcxx . . $ getuid(db52760e79bf9054).();
87 file_uidcxx . . $ file_uid. = geteuidcxx . . $ geteuid(db52760e79bf9054).();
88 uid_setcxx . . $ uid_set. = 1;
89 }
90 #endif
91
92
93 #if 0 /* Not used. */
94 /* lower privileges to the real user's */
95 void lower_privs()
96 {
97 if (!uid_set)
98 init_uids();
99 if (real_uid != file_uid) {
100 #ifdef HAVE_SETEUID
101 if (seteuid(real_uid) < 0) {
102 perror("lowering privileges failed");
103 exit(EXIT_FAILURE);
104 }
105 #else
106 fprintf(stderr, _("Warning: running q-agent setuid on this system is dangerous\n"));
107 #endif /* HAVE_SETEUID */
108 }
109 }
110 #endif /* if 0 */
111
112 #if 0 /* Not used. */
113 /* raise privileges to the effective user's */
114 void raise_privs()
115 {
116 assert(real_uid >= 0); /* lower_privs() must be called before this */
117 #ifdef HAVE_SETEUID
118 if (real_uid != file_uid && seteuid(file_uid) < 0) {
119 perror("Warning: raising privileges failed");
120 }
121 #endif /* HAVE_SETEUID */
122 }
123 #endif /* if 0 */
124
125 /* drop all additional privileges */
126 void drop_privscxx . . $ drop_privs(49f6e7a06ebc5aa8).()
127 {
128 #ifndef HAVE_DOSISH_SYSTEM
129 if (!uid_setcxx . . $ uid_set.)
130 init_uidscxx . . $ init_uids(49f6e7a06ebc5aa8).();
131 if (real_uidcxx . . $ real_uid. != file_uidcxx . . $ file_uid.) {
132 if (setuidcxx . . $ setuid(4c679297bf94b9eb).(real_uidcxx . . $ real_uid.) < 0) {
133 perrorcxx . . $ perror(85c52e162fed56f9).("dropping privileges failed");
134 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
135 }
136 file_uidcxx . . $ file_uid. = real_uidcxx . . $ real_uid.;
137 }
138 #endif
139 }