diff options
Diffstat (limited to 'usr/src/lib')
-rw-r--r-- | usr/src/lib/libproc/common/libproc.h | 2 | ||||
-rw-r--r-- | usr/src/lib/libproc/common/mapfile-vers | 1 | ||||
-rw-r--r-- | usr/src/lib/libproc/common/pr_getsockname.c | 60 |
3 files changed, 61 insertions, 2 deletions
diff --git a/usr/src/lib/libproc/common/libproc.h b/usr/src/lib/libproc/common/libproc.h index 8f3730c3a0..b4374324a1 100644 --- a/usr/src/lib/libproc/common/libproc.h +++ b/usr/src/lib/libproc/common/libproc.h @@ -53,6 +53,7 @@ #include <proc_service.h> #include <rtld_db.h> #include <procfs.h> +#include <ucred.h> #include <rctl.h> #include <libctf.h> #include <sys/stat.h> @@ -347,6 +348,7 @@ extern offset_t pr_llseek(struct ps_prochandle *, int, offset_t, int); extern int pr_rename(struct ps_prochandle *, const char *, const char *); extern int pr_link(struct ps_prochandle *, const char *, const char *); extern int pr_unlink(struct ps_prochandle *, const char *); +extern int pr_getpeerucred(struct ps_prochandle *, int, ucred_t **); extern int pr_getpeername(struct ps_prochandle *, int, struct sockaddr *, socklen_t *); extern int pr_getsockname(struct ps_prochandle *, diff --git a/usr/src/lib/libproc/common/mapfile-vers b/usr/src/lib/libproc/common/mapfile-vers index 9143637cf2..c3e2eb2e8a 100644 --- a/usr/src/lib/libproc/common/mapfile-vers +++ b/usr/src/lib/libproc/common/mapfile-vers @@ -170,6 +170,7 @@ SYMBOL_VERSION SUNWprivate_1.1 { pr_fstatvfs; pr_getitimer; pr_getpeername; + pr_getpeerucred; pr_getprojid; pr_getrctl; pr_getrlimit; diff --git a/usr/src/lib/libproc/common/pr_getsockname.c b/usr/src/lib/libproc/common/pr_getsockname.c index ce29c9bdca..ce86b11468 100644 --- a/usr/src/lib/libproc/common/pr_getsockname.c +++ b/usr/src/lib/libproc/common/pr_getsockname.c @@ -24,8 +24,6 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <stdlib.h> #include <unistd.h> #include <errno.h> @@ -33,6 +31,9 @@ #include <sys/stream.h> #include <sys/socket.h> #include <sys/socketvar.h> +#include <procfs.h> +#include <ucred.h> +#include <sys/ucred.h> #include "libproc.h" static int @@ -167,3 +168,58 @@ pr_getsockopt(struct ps_prochandle *Pr, } return (0); } + +/* + * getpeerucred() system call -- executed by subject process + */ +int +pr_getpeerucred(struct ps_prochandle *Pr, int fd, ucred_t **ucp) +{ + sysret_t rval; /* return value from getpeerucred() */ + argdes_t argd[3]; /* arg descriptors for getpeerucred() */ + argdes_t *adp; + int error; + ucred_t *uc = *ucp; + + if (Pr == NULL) /* no subject process */ + return (getpeerucred(fd, ucp)); + + if (uc == NULL) { + uc = _ucred_alloc(); + if (uc == NULL) + return (-1); + } + + adp = &argd[0]; /* code argument */ + adp->arg_value = UCREDSYS_GETPEERUCRED; + adp->arg_object = NULL; + adp->arg_type = AT_BYVAL; + adp->arg_inout = AI_INPUT; + adp->arg_size = 0; + + adp++; /* fd argument */ + adp->arg_value = fd; + adp->arg_object = NULL; + adp->arg_type = AT_BYVAL; + adp->arg_inout = AI_INPUT; + adp->arg_size = 0; + + adp++; /* ucred argument */ + adp->arg_value = 0; + adp->arg_object = uc; + adp->arg_type = AT_BYREF; + adp->arg_inout = AI_OUTPUT; + adp->arg_size = ucred_size(); + + error = Psyscall(Pr, &rval, SYS_ucredsys, 3, &argd[0]); + + if (error) { + errno = (error > 0)? error : ENOSYS; + if (*ucp == NULL) + ucred_free(uc); + + return (-1); + } + *ucp = uc; + return (0); +} |