1N/A/*
1N/A * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
1N/A */
1N/A/*
1N/A * Ucred.xs contains XS wrappers for the process privilege maniplulation
1N/A * functions.
1N/A */
1N/A
1N/A
1N/A/* Solaris includes. */
1N/A#include <ucred.h>
1N/A#include <priv.h>
1N/A
1N/A/* Perl includes. */
1N/A#include "EXTERN.h"
1N/A#include "perl.h"
1N/A#include "XSUB.h"
1N/A
1N/Atypedef int sysret;
1N/Atypedef priv_set_t Sun__Solaris__Privilege__Privset;
1N/Atypedef ucred_t Sun__Solaris__Ucred__Ucred;
1N/A
1N/Astatic priv_set_t *
1N/Adupset(const priv_set_t *s)
1N/A{
1N/A priv_set_t *new = priv_allocset();
1N/A if (new == NULL)
1N/A return (NULL);
1N/A
1N/A priv_copyset(s, new);
1N/A return (new);
1N/A}
1N/A
1N/A#define RETPRIVSET(set) \
1N/A ST(0) = sv_newmortal(); \
1N/A sv_setref_pv(ST(0), "Sun::Solaris::Privilege::PrivsetPtr", \
1N/A (void*)(set)); \
1N/A SvREADONLY_on(SvRV(ST(0)))
1N/A
1N/A#define RETUCRED(uc) \
1N/A ST(0) = sv_newmortal(); \
1N/A sv_setref_pv(ST(0), "Sun::Solaris::Ucred::UcredPtr", \
1N/A (void*)(uc)); \
1N/A SvREADONLY_on(SvRV(ST(0)))
1N/A/*
1N/A * The XS code exported to perl is below here. Note that the XS preprocessor
1N/A * has its own commenting syntax, so all comments from this point on are in
1N/A * that form.
1N/A */
1N/A
1N/AMODULE = Sun::Solaris::Ucred PACKAGE = Sun::Solaris::Ucred
1N/APROTOTYPES: ENABLE
1N/A
1N/ASun::Solaris::Ucred::Ucred *
1N/Aucred_get(pid);
1N/A pid_t pid;
1N/A
1N/Auid_t
1N/Aucred_geteuid(uc)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/A
1N/Auid_t
1N/Aucred_getruid(uc)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/A
1N/Auid_t
1N/Aucred_getsuid(uc)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/A
1N/Agid_t
1N/Aucred_getegid(uc)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/A
1N/Agid_t
1N/Aucred_getrgid(uc)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/A
1N/Agid_t
1N/Aucred_getsgid(uc)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/A
1N/Apid_t
1N/Aucred_getpid(uc)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/A
1N/Azoneid_t
1N/Aucred_getzoneid(uc)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/A
1N/Aprojid_t
1N/Aucred_getprojid(uc)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/A
1N/Auint_t
1N/Aucred_getpflags(uc, flags)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/A uint_t flags;
1N/A
1N/ASun::Solaris::Privilege::Privset *
1N/Aucred_getprivset(uc, which)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/A const char *which;
1N/APREINIT:
1N/A const priv_set_t *val;
1N/ACODE:
1N/A /*
1N/A * Since this function returns a pointer into the ucred_t, we need
1N/A * to copy it or perl may free one before the other; and the
1N/A * priv_set_t * returned by it doesn't react kindly to free().
1N/A */
1N/A val = ucred_getprivset(uc, which);
1N/A if (val == NULL || (RETVAL = dupset(val)) == NULL)
1N/A XSRETURN_UNDEF;
1N/A RETPRIVSET(RETVAL);
1N/A
1N/ASun::Solaris::Ucred::Ucred *
1N/Agetpeerucred(fd)
1N/A int fd;
1N/ACODE:
1N/A RETVAL = NULL;
1N/A if (getpeerucred(fd, &RETVAL) != 0)
1N/A XSRETURN_UNDEF;
1N/A RETUCRED(RETVAL);
1N/A
1N/Avoid
1N/Aucred_getgroups(uc)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/APREINIT:
1N/A const gid_t *gids;
1N/A int n;
1N/APPCODE:
1N/A n = ucred_getgroups(uc, &gids);
1N/A if (n < 0)
1N/A XSRETURN_UNDEF;
1N/A
1N/A PUTBACK;
1N/A if (GIMME_V == G_SCALAR) {
1N/A EXTEND(SP, 1);
1N/A PUSHs(sv_2mortal(newSViv(n)));
1N/A PUTBACK;
1N/A XSRETURN(1);
1N/A } else if (GIMME_V == G_ARRAY) {
1N/A int i;
1N/A EXTEND(SP, n);
1N/A
1N/A for (i = 0; i < n; i++)
1N/A PUSHs(sv_2mortal(newSViv(gids[i])));
1N/A PUTBACK;
1N/A XSRETURN(n);
1N/A } else {
1N/A PUTBACK;
1N/A XSRETURN(0);
1N/A }
1N/A
1N/A
1N/A
1N/A
1N/AMODULE = Sun::Solaris::Ucred PACKAGE = Sun::Solaris::Ucred::UcredPtr PREFIX = Ucred_
1N/A
1N/Avoid
1N/AUcred_DESTROY(uc)
1N/A Sun::Solaris::Ucred::Ucred *uc;
1N/ACODE:
1N/A ucred_free(uc);
1N/A