debian: added giffgaff chatscripts
[barry.git] / src / getpwuidandroid.cc
blobe762386c6c31af2845458bc3ed3a87658ffdefe9
1 ///
2 /// \file getpwuidandroid.cc
3 /// Replacements for getpwuid*() calls on Android
4 ///
6 /*
7 Copyright (C) 2011, RealVNC Ltd.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "getpwuid.h"
24 #include <string.h>
25 #include <errno.h>
27 #define SDCARD_PATH "/mnt/sdcard"
29 static void fillInData(uid_t uid, char* emptyString, char* sdcardPath, struct barry_passwd* pwd)
31 pwd->pw_name = emptyString;
32 pwd->pw_passwd = emptyString;
33 pwd->pw_uid = uid;
34 pwd->pw_gid = 0;
35 pwd->pw_gecos = emptyString;
36 // This is the important value for Barry, as it's where to store
37 // config files.
39 // For Android the best place is probably on the sdcard, as then
40 // it doesn't matter which application is calling it, as long
41 // as it has android.permission.WRITE_EXTERNAL_STORAGE
42 pwd->pw_dir = sdcardPath;
43 pwd->pw_shell = emptyString;
46 extern "C" struct barry_passwd *barry_getpwuid(uid_t uid)
48 static char emptyString[1] = {0};
49 static char sdcardString[sizeof(SDCARD_PATH)] = SDCARD_PATH;
50 static struct barry_passwd gPasswdStruct;
51 fillInData(uid, emptyString, sdcardString, &gPasswdStruct);
52 return &gPasswdStruct;
55 extern "C" int barry_getpwuid_r(uid_t uid, struct barry_passwd *pwd,
56 char *buf, size_t buflen, struct barry_passwd **result)
58 if (buflen < sizeof(SDCARD_PATH))
59 return ERANGE;
60 memcpy(buf, SDCARD_PATH, sizeof(SDCARD_PATH));
61 // Point all the empty entries at the '\0' at the end of the buffer
62 fillInData(uid, buf + sizeof(SDCARD_PATH) - 1, buf, pwd);
63 *result = pwd;
64 return 0;