blob: 7970e7cfafbb39cb5980058153b42925c8168470 [file] [log] [blame]
Elliott Hughesde727ca2012-08-13 15:45:36 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <ctype.h>
30#include <errno.h>
31#include <grp.h>
32#include <mntent.h>
33#include <netdb.h>
Elliott Hughesde727ca2012-08-13 15:45:36 -070034#include <pthread.h>
35#include <pwd.h>
36#include <stdio.h>
37#include <stdlib.h>
Mark Salyzyn56b27682015-03-31 16:55:42 -070038#include <string.h>
Elliott Hughesde727ca2012-08-13 15:45:36 -070039#include <unistd.h>
40
Elliott Hughes3e898472013-02-12 16:40:24 +000041#include "private/android_filesystem_config.h"
Elliott Hughes3e898472013-02-12 16:40:24 +000042#include "private/ErrnoRestorer.h"
Elliott Hughes8f2a5a02013-03-15 15:30:25 -070043#include "private/libc_logging.h"
Yabin Cuia04c79b2014-11-18 16:14:54 -080044#include "private/ThreadLocalBuffer.h"
Elliott Hughes3e898472013-02-12 16:40:24 +000045
Elliott Hughes7874f1d2014-12-18 13:36:25 -080046// POSIX seems to envisage an implementation where the <pwd.h> functions are
47// implemented by brute-force searching with getpwent(3), and the <grp.h>
48// functions are implemented similarly with getgrent(3). This means that it's
49// okay for all the <grp.h> functions to share state, and all the <passwd.h>
50// functions to share state, but <grp.h> functions can't clobber <passwd.h>
51// functions' state and vice versa.
Yabin Cuia04c79b2014-11-18 16:14:54 -080052
Elliott Hughes7874f1d2014-12-18 13:36:25 -080053GLOBAL_INIT_THREAD_LOCAL_BUFFER(group);
54
55struct group_state_t {
Elliott Hughesde727ca2012-08-13 15:45:36 -070056 group group_;
57 char* group_members_[2];
Elliott Hughesde727ca2012-08-13 15:45:36 -070058 char group_name_buffer_[32];
Elliott Hughes7874f1d2014-12-18 13:36:25 -080059};
60
61static group_state_t* __group_state() {
62 LOCAL_INIT_THREAD_LOCAL_BUFFER(group_state_t*, group, sizeof(group_state_t));
63 if (group_tls_buffer != NULL) {
64 memset(group_tls_buffer, 0, sizeof(group_state_t));
65 group_tls_buffer->group_.gr_mem = group_tls_buffer->group_members_;
66 }
67 return group_tls_buffer;
68}
69
70GLOBAL_INIT_THREAD_LOCAL_BUFFER(passwd);
71
72struct passwd_state_t {
73 passwd passwd_;
Elliott Hughes8b5df392015-01-21 16:19:07 -080074 char name_buffer_[32];
Elliott Hughesde727ca2012-08-13 15:45:36 -070075 char dir_buffer_[32];
76 char sh_buffer_[32];
77};
78
Elliott Hughes7874f1d2014-12-18 13:36:25 -080079static passwd_state_t* __passwd_state() {
80 LOCAL_INIT_THREAD_LOCAL_BUFFER(passwd_state_t*, passwd, sizeof(passwd_state_t));
81 return passwd_tls_buffer;
82}
83
Elliott Hughesde727ca2012-08-13 15:45:36 -070084static int do_getpw_r(int by_name, const char* name, uid_t uid,
85 passwd* dst, char* buf, size_t byte_count,
86 passwd** result) {
87 // getpwnam_r and getpwuid_r don't modify errno, but library calls we
88 // make might.
Elliott Hughes3e898472013-02-12 16:40:24 +000089 ErrnoRestorer errno_restorer;
Elliott Hughesde727ca2012-08-13 15:45:36 -070090 *result = NULL;
91
92 // Our implementation of getpwnam(3) and getpwuid(3) use thread-local
93 // storage, so we can call them as long as we copy everything out
94 // before returning.
95 const passwd* src = by_name ? getpwnam(name) : getpwuid(uid); // NOLINT: see above.
96
97 // POSIX allows failure to find a match to be considered a non-error.
98 // Reporting success (0) but with *result NULL is glibc's behavior.
99 if (src == NULL) {
Elliott Hughes3e898472013-02-12 16:40:24 +0000100 return (errno == ENOENT) ? 0 : errno;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700101 }
102
103 // Work out where our strings will go in 'buf', and whether we've got
104 // enough space.
105 size_t required_byte_count = 0;
106 dst->pw_name = buf;
107 required_byte_count += strlen(src->pw_name) + 1;
108 dst->pw_dir = buf + required_byte_count;
109 required_byte_count += strlen(src->pw_dir) + 1;
110 dst->pw_shell = buf + required_byte_count;
111 required_byte_count += strlen(src->pw_shell) + 1;
112 if (byte_count < required_byte_count) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700113 return ERANGE;
114 }
115
116 // Copy the strings.
Elliott Hughes3e898472013-02-12 16:40:24 +0000117 snprintf(buf, byte_count, "%s%c%s%c%s", src->pw_name, 0, src->pw_dir, 0, src->pw_shell);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700118
Calin Juravlec7688742014-05-09 21:50:53 +0100119 // pw_passwd and pw_gecos are non-POSIX and unused (always NULL) in bionic.
Elliott Hughesde727ca2012-08-13 15:45:36 -0700120 dst->pw_passwd = NULL;
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800121#if defined(__LP64__)
Calin Juravlec7688742014-05-09 21:50:53 +0100122 dst->pw_gecos = NULL;
123#endif
Elliott Hughesde727ca2012-08-13 15:45:36 -0700124
125 // Copy the integral fields.
126 dst->pw_gid = src->pw_gid;
127 dst->pw_uid = src->pw_uid;
128
129 *result = dst;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700130 return 0;
131}
132
133int getpwnam_r(const char* name, passwd* pwd,
134 char* buf, size_t byte_count, passwd** result) {
135 return do_getpw_r(1, name, -1, pwd, buf, byte_count, result);
136}
137
138int getpwuid_r(uid_t uid, passwd* pwd,
139 char* buf, size_t byte_count, passwd** result) {
140 return do_getpw_r(0, NULL, uid, pwd, buf, byte_count, result);
141}
142
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800143static passwd* android_iinfo_to_passwd(passwd_state_t* state,
Elliott Hughesde727ca2012-08-13 15:45:36 -0700144 const android_id_info* iinfo) {
Elliott Hughes8b5df392015-01-21 16:19:07 -0800145 snprintf(state->name_buffer_, sizeof(state->name_buffer_), "%s", iinfo->name);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700146 snprintf(state->dir_buffer_, sizeof(state->dir_buffer_), "/");
147 snprintf(state->sh_buffer_, sizeof(state->sh_buffer_), "/system/bin/sh");
148
149 passwd* pw = &state->passwd_;
Elliott Hughes8b5df392015-01-21 16:19:07 -0800150 pw->pw_name = state->name_buffer_;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700151 pw->pw_uid = iinfo->aid;
152 pw->pw_gid = iinfo->aid;
153 pw->pw_dir = state->dir_buffer_;
154 pw->pw_shell = state->sh_buffer_;
155 return pw;
156}
157
Elliott Hughes8b5df392015-01-21 16:19:07 -0800158static group* android_iinfo_to_group(group_state_t* state,
Elliott Hughesde727ca2012-08-13 15:45:36 -0700159 const android_id_info* iinfo) {
Elliott Hughes8b5df392015-01-21 16:19:07 -0800160 snprintf(state->group_name_buffer_, sizeof(state->group_name_buffer_), "%s", iinfo->name);
161
162 group* gr = &state->group_;
163 gr->gr_name = state->group_name_buffer_;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700164 gr->gr_gid = iinfo->aid;
165 gr->gr_mem[0] = gr->gr_name;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700166 return gr;
167}
168
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800169static passwd* android_id_to_passwd(passwd_state_t* state, unsigned id) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700170 for (size_t n = 0; n < android_id_count; ++n) {
171 if (android_ids[n].aid == id) {
172 return android_iinfo_to_passwd(state, android_ids + n);
173 }
174 }
175 return NULL;
176}
177
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800178static passwd* android_name_to_passwd(passwd_state_t* state, const char* name) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700179 for (size_t n = 0; n < android_id_count; ++n) {
180 if (!strcmp(android_ids[n].name, name)) {
181 return android_iinfo_to_passwd(state, android_ids + n);
182 }
183 }
184 return NULL;
185}
186
Elliott Hughes8b5df392015-01-21 16:19:07 -0800187static group* android_id_to_group(group_state_t* state, unsigned id) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700188 for (size_t n = 0; n < android_id_count; ++n) {
189 if (android_ids[n].aid == id) {
Elliott Hughes8b5df392015-01-21 16:19:07 -0800190 return android_iinfo_to_group(state, android_ids + n);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700191 }
192 }
193 return NULL;
194}
195
Elliott Hughes8b5df392015-01-21 16:19:07 -0800196static group* android_name_to_group(group_state_t* state, const char* name) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700197 for (size_t n = 0; n < android_id_count; ++n) {
198 if (!strcmp(android_ids[n].name, name)) {
Elliott Hughes8b5df392015-01-21 16:19:07 -0800199 return android_iinfo_to_group(state, android_ids + n);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700200 }
201 }
202 return NULL;
203}
204
205// Translate a user/group name to the corresponding user/group id.
Yabin Cuia04c79b2014-11-18 16:14:54 -0800206// all_a1234 -> 0 * AID_USER + AID_SHARED_GID_START + 1234 (group name only)
Elliott Hughesde727ca2012-08-13 15:45:36 -0700207// u0_a1234 -> 0 * AID_USER + AID_APP + 1234
208// u2_i1000 -> 2 * AID_USER + AID_ISOLATED_START + 1000
209// u1_system -> 1 * AID_USER + android_ids['system']
210// returns 0 and sets errno to ENOENT in case of error
Elliott Hughesc56af082015-01-22 11:02:59 -0800211static id_t app_id_from_name(const char* name, bool is_group) {
Yabin Cuia04c79b2014-11-18 16:14:54 -0800212 char* end;
213 unsigned long userid;
214 bool is_shared_gid = false;
215
216 if (is_group && name[0] == 'a' && name[1] == 'l' && name[2] == 'l') {
217 end = const_cast<char*>(name+3);
218 userid = 0;
219 is_shared_gid = true;
220 } else if (name[0] == 'u' && isdigit(name[1])) {
221 userid = strtoul(name+1, &end, 10);
222 } else {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700223 errno = ENOENT;
224 return 0;
225 }
226
Elliott Hughesde727ca2012-08-13 15:45:36 -0700227 if (end[0] != '_' || end[1] == 0) {
228 errno = ENOENT;
229 return 0;
230 }
231
232 unsigned long appid = 0;
233 if (end[1] == 'a' && isdigit(end[2])) {
Yabin Cuia04c79b2014-11-18 16:14:54 -0800234 if (is_shared_gid) {
235 // end will point to \0 if the strtoul below succeeds.
236 appid = strtoul(end+2, &end, 10) + AID_SHARED_GID_START;
237 if (appid > AID_SHARED_GID_END) {
238 errno = ENOENT;
239 return 0;
240 }
241 } else {
242 // end will point to \0 if the strtoul below succeeds.
243 appid = strtoul(end+2, &end, 10) + AID_APP;
244 }
Elliott Hughesde727ca2012-08-13 15:45:36 -0700245 } else if (end[1] == 'i' && isdigit(end[2])) {
246 // end will point to \0 if the strtoul below succeeds.
247 appid = strtoul(end+2, &end, 10) + AID_ISOLATED_START;
248 } else {
249 for (size_t n = 0; n < android_id_count; n++) {
250 if (!strcmp(android_ids[n].name, end + 1)) {
251 appid = android_ids[n].aid;
252 // Move the end pointer to the null terminator.
253 end += strlen(android_ids[n].name) + 1;
254 }
255 }
256 }
257
258 // Check that the entire string was consumed by one of the 3 cases above.
259 if (end[0] != 0) {
260 errno = ENOENT;
261 return 0;
262 }
263
264 // Check that user id won't overflow.
265 if (userid > 1000) {
266 errno = ENOENT;
267 return 0;
268 }
269
270 // Check that app id is within range.
271 if (appid >= AID_USER) {
272 errno = ENOENT;
273 return 0;
274 }
275
Elliott Hughesc56af082015-01-22 11:02:59 -0800276 return (appid + userid*AID_USER);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700277}
278
Yabin Cuia04c79b2014-11-18 16:14:54 -0800279static void print_app_name_from_uid(const uid_t uid, char* buffer, const int bufferlen) {
280 const uid_t appid = uid % AID_USER;
281 const uid_t userid = uid / AID_USER;
Kenny Root8a05a012012-09-13 14:31:50 -0700282 if (appid >= AID_ISOLATED_START) {
283 snprintf(buffer, bufferlen, "u%u_i%u", userid, appid - AID_ISOLATED_START);
Kenny Root8a05a012012-09-13 14:31:50 -0700284 } else if (appid < AID_APP) {
285 for (size_t n = 0; n < android_id_count; n++) {
286 if (android_ids[n].aid == appid) {
287 snprintf(buffer, bufferlen, "u%u_%s", userid, android_ids[n].name);
288 return;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700289 }
290 }
Elliott Hughesde727ca2012-08-13 15:45:36 -0700291 } else {
Kenny Root8a05a012012-09-13 14:31:50 -0700292 snprintf(buffer, bufferlen, "u%u_a%u", userid, appid - AID_APP);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700293 }
294}
295
Yabin Cuia04c79b2014-11-18 16:14:54 -0800296static void print_app_name_from_gid(const gid_t gid, char* buffer, const int bufferlen) {
297 const uid_t appid = gid % AID_USER;
298 const uid_t userid = gid / AID_USER;
299 if (appid >= AID_ISOLATED_START) {
300 snprintf(buffer, bufferlen, "u%u_i%u", userid, appid - AID_ISOLATED_START);
301 } else if (userid == 0 && appid >= AID_SHARED_GID_START && appid <= AID_SHARED_GID_END) {
302 snprintf(buffer, bufferlen, "all_a%u", appid - AID_SHARED_GID_START);
303 } else if (appid < AID_APP) {
304 for (size_t n = 0; n < android_id_count; n++) {
305 if (android_ids[n].aid == appid) {
306 snprintf(buffer, bufferlen, "u%u_%s", userid, android_ids[n].name);
307 return;
308 }
309 }
310 } else {
311 snprintf(buffer, bufferlen, "u%u_a%u", userid, appid - AID_APP);
312 }
Kenny Root2a54e5e2012-09-13 10:52:52 -0700313}
314
Elliott Hughesde727ca2012-08-13 15:45:36 -0700315// Translate a uid into the corresponding name.
316// 0 to AID_APP-1 -> "system", "radio", etc.
317// AID_APP to AID_ISOLATED_START-1 -> u0_a1234
318// AID_ISOLATED_START to AID_USER-1 -> u0_i1234
319// AID_USER+ -> u1_radio, u1_a1234, u2_i1234, etc.
320// returns a passwd structure (sets errno to ENOENT on failure).
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800321static passwd* app_id_to_passwd(uid_t uid, passwd_state_t* state) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700322 if (uid < AID_APP) {
323 errno = ENOENT;
324 return NULL;
325 }
326
Elliott Hughes8b5df392015-01-21 16:19:07 -0800327 print_app_name_from_uid(uid, state->name_buffer_, sizeof(state->name_buffer_));
Yabin Cuia04c79b2014-11-18 16:14:54 -0800328
Kenny Root2a54e5e2012-09-13 10:52:52 -0700329 const uid_t appid = uid % AID_USER;
Kenny Root2a54e5e2012-09-13 10:52:52 -0700330 if (appid < AID_APP) {
331 snprintf(state->dir_buffer_, sizeof(state->dir_buffer_), "/");
332 } else {
333 snprintf(state->dir_buffer_, sizeof(state->dir_buffer_), "/data");
334 }
335
Elliott Hughesde727ca2012-08-13 15:45:36 -0700336 snprintf(state->sh_buffer_, sizeof(state->sh_buffer_), "/system/bin/sh");
337
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800338 passwd* pw = &state->passwd_;
Elliott Hughes8b5df392015-01-21 16:19:07 -0800339 pw->pw_name = state->name_buffer_;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700340 pw->pw_dir = state->dir_buffer_;
341 pw->pw_shell = state->sh_buffer_;
342 pw->pw_uid = uid;
343 pw->pw_gid = uid;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700344 return pw;
345}
346
347// Translate a gid into the corresponding app_<gid>
348// group structure (sets errno to ENOENT on failure).
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800349static group* app_id_to_group(gid_t gid, group_state_t* state) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700350 if (gid < AID_APP) {
351 errno = ENOENT;
352 return NULL;
353 }
354
Yabin Cuia04c79b2014-11-18 16:14:54 -0800355 print_app_name_from_gid(gid, state->group_name_buffer_, sizeof(state->group_name_buffer_));
Elliott Hughesde727ca2012-08-13 15:45:36 -0700356
357 group* gr = &state->group_;
358 gr->gr_name = state->group_name_buffer_;
359 gr->gr_gid = gid;
360 gr->gr_mem[0] = gr->gr_name;
Elliott Hughesde727ca2012-08-13 15:45:36 -0700361 return gr;
362}
363
Elliott Hughesde727ca2012-08-13 15:45:36 -0700364passwd* getpwuid(uid_t uid) { // NOLINT: implementing bad function.
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800365 passwd_state_t* state = __passwd_state();
Elliott Hughesde727ca2012-08-13 15:45:36 -0700366 if (state == NULL) {
367 return NULL;
368 }
369
370 passwd* pw = android_id_to_passwd(state, uid);
371 if (pw != NULL) {
372 return pw;
373 }
374 return app_id_to_passwd(uid, state);
375}
376
377passwd* getpwnam(const char* login) { // NOLINT: implementing bad function.
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800378 passwd_state_t* state = __passwd_state();
Elliott Hughesde727ca2012-08-13 15:45:36 -0700379 if (state == NULL) {
380 return NULL;
381 }
382
383 passwd* pw = android_name_to_passwd(state, login);
384 if (pw != NULL) {
385 return pw;
386 }
Yabin Cuia04c79b2014-11-18 16:14:54 -0800387 return app_id_to_passwd(app_id_from_name(login, false), state);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700388}
389
Elliott Hughes6fa26e22012-10-22 16:04:56 -0700390// All users are in just one group, the one passed in.
391int getgrouplist(const char* /*user*/, gid_t group, gid_t* groups, int* ngroups) {
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800392 if (*ngroups < 1) {
393 *ngroups = 1;
394 return -1;
395 }
396 groups[0] = group;
397 return (*ngroups = 1);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700398}
399
400char* getlogin() { // NOLINT: implementing bad function.
401 passwd *pw = getpwuid(getuid()); // NOLINT: implementing bad function in terms of bad function.
402 return (pw != NULL) ? pw->pw_name : NULL;
403}
404
405group* getgrgid(gid_t gid) { // NOLINT: implementing bad function.
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800406 group_state_t* state = __group_state();
Elliott Hughesde727ca2012-08-13 15:45:36 -0700407 if (state == NULL) {
408 return NULL;
409 }
410
Elliott Hughes8b5df392015-01-21 16:19:07 -0800411 group* gr = android_id_to_group(state, gid);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700412 if (gr != NULL) {
413 return gr;
414 }
Elliott Hughesde727ca2012-08-13 15:45:36 -0700415 return app_id_to_group(gid, state);
416}
417
418group* getgrnam(const char* name) { // NOLINT: implementing bad function.
Elliott Hughes7874f1d2014-12-18 13:36:25 -0800419 group_state_t* state = __group_state();
Elliott Hughesde727ca2012-08-13 15:45:36 -0700420 if (state == NULL) {
421 return NULL;
422 }
423
Elliott Hughes8b5df392015-01-21 16:19:07 -0800424 if (android_name_to_group(state, name) != 0) {
Elliott Hughesde727ca2012-08-13 15:45:36 -0700425 return &state->group_;
426 }
Yabin Cuia04c79b2014-11-18 16:14:54 -0800427 return app_id_to_group(app_id_from_name(name, true), state);
Elliott Hughesde727ca2012-08-13 15:45:36 -0700428}
429
Elliott Hughes6fa26e22012-10-22 16:04:56 -0700430// We don't have an /etc/networks, so all inputs return NULL.
431netent* getnetbyname(const char* /*name*/) {
432 return NULL;
433}
434
435// We don't have an /etc/networks, so all inputs return NULL.
436netent* getnetbyaddr(uint32_t /*net*/, int /*type*/) {
437 return NULL;
438}
439
440// We don't have an /etc/protocols, so all inputs return NULL.
441protoent* getprotobyname(const char* /*name*/) {
442 return NULL;
443}
444
445// We don't have an /etc/protocols, so all inputs return NULL.
446protoent* getprotobynumber(int /*proto*/) {
447 return NULL;
448}
449
Elliott Hughes0e44bc32014-02-24 15:55:31 -0800450// Portable code should use sysconf(_SC_PAGE_SIZE) directly instead.
Bernhard Rosenkraenzer9ae59c02013-09-18 23:29:08 +0200451int getpagesize() {
Elliott Hughes91570ce2014-07-10 12:34:23 -0700452 // We dont use sysconf(3) here because that drags in stdio, which makes static binaries fat.
453 return PAGE_SIZE;
Bernhard Rosenkraenzer9ae59c02013-09-18 23:29:08 +0200454}