diff options
Diffstat (limited to 'ports/uids_generic')
26 files changed, 551 insertions, 0 deletions
diff --git a/ports/uids_generic/guts/COPYRIGHT b/ports/uids_generic/guts/COPYRIGHT new file mode 100644 index 0000000..c96e1b1 --- /dev/null +++ b/ports/uids_generic/guts/COPYRIGHT @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the Lesser GNU General Public License version 2.1 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Lesser GNU General Public License for more details. + * + * You should have received a copy of the Lesser GNU General Public License + * version 2.1 along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ diff --git a/ports/uids_generic/guts/endgrent.c b/ports/uids_generic/guts/endgrent.c new file mode 100644 index 0000000..843cad0 --- /dev/null +++ b/ports/uids_generic/guts/endgrent.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static void + * wrap_endgrent(void) { + * + */ + + pseudo_grp_close(); + +/* return; + * } + */ diff --git a/ports/uids_generic/guts/endpwent.c b/ports/uids_generic/guts/endpwent.c new file mode 100644 index 0000000..f76cf10 --- /dev/null +++ b/ports/uids_generic/guts/endpwent.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static void + * wrap_endpwent(void) { + * + */ + + pseudo_pwd_close(); + +/* return; + * } + */ diff --git a/ports/uids_generic/guts/getegid.c b/ports/uids_generic/guts/getegid.c new file mode 100644 index 0000000..7c14f48 --- /dev/null +++ b/ports/uids_generic/guts/getegid.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static gid_t + * wrap_getegid(void) { + * gid_t rc = 0; + */ + + rc = pseudo_egid; + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/geteuid.c b/ports/uids_generic/guts/geteuid.c new file mode 100644 index 0000000..1745e13 --- /dev/null +++ b/ports/uids_generic/guts/geteuid.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static uid_t + * wrap_geteuid(void) { + * uid_t rc = 0; + */ + + rc = pseudo_euid; + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/getgid.c b/ports/uids_generic/guts/getgid.c new file mode 100644 index 0000000..ca8bad3 --- /dev/null +++ b/ports/uids_generic/guts/getgid.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static gid_t + * wrap_getgid(void) { + * gid_t rc = 0; + */ + + rc = pseudo_rgid; + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/getgrent.c b/ports/uids_generic/guts/getgrent.c new file mode 100644 index 0000000..e8e07f5 --- /dev/null +++ b/ports/uids_generic/guts/getgrent.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static struct group * + * wrap_getgrent(void) { + * struct group * rc = NULL; + */ + static struct group grp; + static char grbuf[PSEUDO_PWD_MAX]; + int r_rc; + + r_rc = wrap_getgrent_r(&grp, grbuf, PSEUDO_PWD_MAX, &rc); + /* different error return conventions */ + if (r_rc != 0) { + errno = r_rc; + } + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/getgrgid.c b/ports/uids_generic/guts/getgrgid.c new file mode 100644 index 0000000..c1824e7 --- /dev/null +++ b/ports/uids_generic/guts/getgrgid.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static struct group * + * wrap_getgrgid(gid_t gid) { + * struct group * rc = NULL; + */ + static struct group grp; + static char grbuf[PSEUDO_PWD_MAX]; + int r_rc; + + r_rc = wrap_getgrgid_r(gid, &grp, grbuf, PSEUDO_PWD_MAX, &rc); + /* different error return conventions */ + if (r_rc != 0) { + errno = r_rc; + } + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/getgrgid_r.c b/ports/uids_generic/guts/getgrgid_r.c new file mode 100644 index 0000000..06a91c9 --- /dev/null +++ b/ports/uids_generic/guts/getgrgid_r.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_getgrgid_r(gid_t gid, struct group *gbuf, char *buf, size_t buflen, struct group **gbufp) { + * int rc = -1; + */ + + setgrent(); + while ((rc = wrap_getgrent_r(gbuf, buf, buflen, gbufp)) == 0) { + /* 0 means no error occurred, and *gbufp == gbuf */ + if (gbuf->gr_gid == gid) { + pseudo_debug(1, "found group gid %d, name %s\n", + gbuf->gr_gid, gbuf->gr_name); + endgrent(); + return rc; + } + } + endgrent(); + /* we never found a match; rc is 0 if there was no error, or + * non-zero if an error occurred. Either way, set the + * pwbufp pointer to NULL to indicate that we didn't find + * something, and leave rc alone. + */ + *gbufp = NULL; + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/getgrnam.c b/ports/uids_generic/guts/getgrnam.c new file mode 100644 index 0000000..0e26444 --- /dev/null +++ b/ports/uids_generic/guts/getgrnam.c @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static struct group * + * wrap_getgrnam(const char *name) { + * struct group * rc = NULL; + */ + + static struct group grp; + static char grbuf[PSEUDO_PWD_MAX]; + int r_rc; + + r_rc = wrap_getgrnam_r(name, &grp, grbuf, PSEUDO_PWD_MAX, &rc); + /* different error return conventions */ + if (r_rc != 0) { + errno = r_rc; + } + + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/getgrnam_r.c b/ports/uids_generic/guts/getgrnam_r.c new file mode 100644 index 0000000..39de641 --- /dev/null +++ b/ports/uids_generic/guts/getgrnam_r.c @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_getgrnam_r(const char *name, struct group *gbuf, char *buf, size_t buflen, struct group **gbufp) { + * int rc = -1; + */ + + setgrent(); + while ((rc = wrap_getgrent_r(gbuf, buf, buflen, gbufp)) == 0) { + /* 0 means no error occurred, and *gbufp == gbuf */ + if (gbuf->gr_name && !strcmp(gbuf->gr_name, name)) { + endgrent(); + return rc; + } + } + endgrent(); + /* we never found a match; rc is 0 if there was no error, or + * non-zero if an error occurred. Either way, set the + * pwbufp pointer to NULL to indicate that we didn't find + * something, and leave rc alone. + */ + *gbufp = NULL; + + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/getpwent.c b/ports/uids_generic/guts/getpwent.c new file mode 100644 index 0000000..3b1f837 --- /dev/null +++ b/ports/uids_generic/guts/getpwent.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static struct passwd * + * wrap_getpwent(void) { + * struct passwd * rc = NULL; + */ + static struct passwd pwd; + static char pwbuf[PSEUDO_PWD_MAX]; + int r_rc; + + r_rc = wrap_getpwent_r(&pwd, pwbuf, PSEUDO_PWD_MAX, &rc); + /* different error return conventions */ + if (r_rc != 0) { + errno = r_rc; + } + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/getpwnam.c b/ports/uids_generic/guts/getpwnam.c new file mode 100644 index 0000000..024b3d8 --- /dev/null +++ b/ports/uids_generic/guts/getpwnam.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static struct passwd * + * wrap_getpwnam(const char *name) { + * struct passwd * rc = NULL; + */ + static struct passwd pwd; + static char pwbuf[PSEUDO_PWD_MAX]; + int r_rc; + + r_rc = wrap_getpwnam_r(name, &pwd, pwbuf, PSEUDO_PWD_MAX, &rc); + /* different error return conventions */ + if (r_rc != 0) { + errno = r_rc; + } + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/getpwnam_r.c b/ports/uids_generic/guts/getpwnam_r.c new file mode 100644 index 0000000..5d7a4ea --- /dev/null +++ b/ports/uids_generic/guts/getpwnam_r.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_getpwnam_r(const char *name, struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) { + * int rc = -1; + */ + + setpwent(); + while ((rc = wrap_getpwent_r(pwbuf, buf, buflen, pwbufp)) == 0) { + /* 0 means no error occurred, and *pwbufp == pwbuf */ + if (pwbuf->pw_name && !strcmp(pwbuf->pw_name, name)) { + endpwent(); + return rc; + } + } + endpwent(); + /* we never found a match; rc is 0 if there was no error, or + * non-zero if an error occurred. Either way, set the + * pwbufp pointer to NULL to indicate that we didn't find + * something, and leave rc alone. + */ + *pwbufp = NULL; + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/getpwuid.c b/ports/uids_generic/guts/getpwuid.c new file mode 100644 index 0000000..11142de --- /dev/null +++ b/ports/uids_generic/guts/getpwuid.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static struct passwd * + * wrap_getpwuid(uid_t uid) { + * struct passwd * rc = NULL; + */ + static struct passwd pwd; + static char pwbuf[PSEUDO_PWD_MAX]; + int r_rc; + + r_rc = wrap_getpwuid_r(uid, &pwd, pwbuf, PSEUDO_PWD_MAX, &rc); + /* different error return conventions */ + if (r_rc != 0) { + errno = r_rc; + } + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/getpwuid_r.c b/ports/uids_generic/guts/getpwuid_r.c new file mode 100644 index 0000000..06b920e --- /dev/null +++ b/ports/uids_generic/guts/getpwuid_r.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) { + * int rc = -1; + */ + + setpwent(); + while ((rc = wrap_getpwent_r(pwbuf, buf, buflen, pwbufp)) == 0) { + /* 0 means no error occurred, and *pwbufp == pwbuf */ + if (pwbuf->pw_uid == uid) { + endpwent(); + return rc; + } + } + endpwent(); + /* we never found a match; rc is 0 if there was no error, or + * non-zero if an error occurred. Either way, set the + * pwbufp pointer to NULL to indicate that we didn't find + * something, and leave rc alone. + */ + *pwbufp = NULL; + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/getuid.c b/ports/uids_generic/guts/getuid.c new file mode 100644 index 0000000..e783cc8 --- /dev/null +++ b/ports/uids_generic/guts/getuid.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static uid_t + * wrap_getuid(void) { + * uid_t rc = 0; + */ + + rc = pseudo_ruid; + +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/setegid.c b/ports/uids_generic/guts/setegid.c new file mode 100644 index 0000000..ff777a0 --- /dev/null +++ b/ports/uids_generic/guts/setegid.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_setegid(gid_t egid) { + * int rc = -1; + */ + if (pseudo_euid == 0 || egid == pseudo_egid || egid == pseudo_rgid || egid == pseudo_sgid) { + pseudo_egid = egid; + pseudo_fgid = egid; + pseudo_client_touchgid(); + rc = 0; + } else { + rc = -1; + errno = EPERM; + } +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/seteuid.c b/ports/uids_generic/guts/seteuid.c new file mode 100644 index 0000000..430768f --- /dev/null +++ b/ports/uids_generic/guts/seteuid.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_seteuid(uid_t euid) { + * int rc = -1; + */ + if (pseudo_euid == 0 || euid == pseudo_euid || euid == pseudo_ruid || euid == pseudo_suid) { + pseudo_euid = euid; + pseudo_fuid = euid; + pseudo_client_touchuid(); + rc = 0; + } else { + rc = -1; + errno = EPERM; + } +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/setgid.c b/ports/uids_generic/guts/setgid.c new file mode 100644 index 0000000..b94db1a --- /dev/null +++ b/ports/uids_generic/guts/setgid.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_setgid(gid_t gid) { + * int rc = -1; + */ + if (pseudo_euid == 0) { + pseudo_rgid = gid; + pseudo_egid = gid; + pseudo_sgid = gid; + pseudo_fgid = gid; + pseudo_client_touchgid(); + rc = 0; + } else if (pseudo_egid == gid || pseudo_sgid == gid || pseudo_rgid == gid) { + pseudo_egid = gid; + pseudo_fgid = gid; + pseudo_client_touchgid(); + rc = 0; + } else { + rc = -1; + errno = EPERM; + } +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/setgrent.c b/ports/uids_generic/guts/setgrent.c new file mode 100644 index 0000000..75aab61 --- /dev/null +++ b/ports/uids_generic/guts/setgrent.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static void + * wrap_setgrent(void) { + * + */ + + pseudo_grp_open(); + +/* return; + * } + */ diff --git a/ports/uids_generic/guts/setpwent.c b/ports/uids_generic/guts/setpwent.c new file mode 100644 index 0000000..fb35e07 --- /dev/null +++ b/ports/uids_generic/guts/setpwent.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static void + * wrap_setpwent(void) { + * + */ + + pseudo_pwd_open(); + +/* return; + * } + */ diff --git a/ports/uids_generic/guts/setregid.c b/ports/uids_generic/guts/setregid.c new file mode 100644 index 0000000..78b2037 --- /dev/null +++ b/ports/uids_generic/guts/setregid.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_setregid(gid_t rgid, gid_t egid) { + * int rc = -1; + */ + rc = 0; + if (pseudo_euid != 0 && rgid != (gid_t) -1 && + rgid != pseudo_egid && rgid != pseudo_rgid && rgid != pseudo_sgid) { + rc = -1; + errno = EPERM; + } + if (pseudo_euid != 0 && egid != (gid_t) -1 && + egid != pseudo_egid && egid != pseudo_rgid && egid != pseudo_sgid) { + rc = -1; + errno = EPERM; + } + if (rc != -1) { + if (rgid != (gid_t) -1) + pseudo_rgid = rgid; + if (egid != (gid_t) -1) + pseudo_egid = egid; + pseudo_fgid = pseudo_egid; + pseudo_client_touchuid(); + } +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/setreuid.c b/ports/uids_generic/guts/setreuid.c new file mode 100644 index 0000000..3ff82ab --- /dev/null +++ b/ports/uids_generic/guts/setreuid.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_setreuid(uid_t ruid, uid_t euid) { + * int rc = -1; + */ + rc = 0; + if (pseudo_euid != 0 && ruid != (uid_t) -1 && + ruid != pseudo_euid && ruid != pseudo_ruid && ruid != pseudo_suid) { + rc = -1; + errno = EPERM; + } + if (pseudo_euid != 0 && euid != (uid_t) -1 && + euid != pseudo_euid && euid != pseudo_ruid && euid != pseudo_suid) { + rc = -1; + errno = EPERM; + } + if (rc != -1) { + if (ruid != (uid_t) -1) + pseudo_ruid = ruid; + if (euid != (uid_t) -1) + pseudo_euid = euid; + pseudo_fuid = pseudo_euid; + pseudo_client_touchuid(); + } +/* return rc; + * } + */ diff --git a/ports/uids_generic/guts/setuid.c b/ports/uids_generic/guts/setuid.c new file mode 100644 index 0000000..6bfdf6c --- /dev/null +++ b/ports/uids_generic/guts/setuid.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * static int + * wrap_setuid(uid_t uid) { + * int rc = -1; + */ + if (pseudo_euid == 0) { + pseudo_ruid = uid; + pseudo_euid = uid; + pseudo_suid = uid; + pseudo_fuid = uid; + pseudo_client_touchuid(); + rc = 0; + } else if (pseudo_euid == uid || pseudo_suid == uid || pseudo_ruid == uid) { + pseudo_euid = uid; + pseudo_fuid = uid; + pseudo_client_touchuid(); + rc = 0; + } else { + rc = -1; + errno = EPERM; + } +/* return rc; + * } + */ diff --git a/ports/uids_generic/wrapfuncs.in b/ports/uids_generic/wrapfuncs.in new file mode 100644 index 0000000..38aa558 --- /dev/null +++ b/ports/uids_generic/wrapfuncs.in @@ -0,0 +1,25 @@ +# I bet you never knew there were this many of these! +gid_t getegid(void); +gid_t getgid(void); +int getgrgid_r(gid_t gid, struct group *gbuf, char *buf, size_t buflen, struct group **gbufp); +int getgrnam_r(const char *name, struct group *gbuf, char *buf, size_t buflen, struct group **gbufp); +int getpwnam_r(const char *name, struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp); +int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp); +int setegid(gid_t egid); +int seteuid(uid_t euid); +int setgid(gid_t gid); +int setregid(gid_t rgid, gid_t egid); +int setreuid(uid_t ruid, uid_t euid); +int setuid(uid_t uid); +struct group *getgrent(void); +struct group *getgrgid(gid_t gid); +struct group *getgrnam(const char *name); +struct passwd *getpwent(void); +struct passwd *getpwnam(const char *name); +struct passwd *getpwuid(uid_t uid); +uid_t geteuid(void); +uid_t getuid(void); +void endgrent(void); +void endpwent(void); +void setgrent(void); +void setpwent(void); |