#include <sys/types.h>
#include <sys/zone.h>
#include <syslog.h>
#include <strings.h>
#include <ucred.h>
#include "tsol/label.h"
#if defined PS_FAULTED
#undef PS_FAULTED
#endif
#include "lp.h"
#include <sys/tsol/label_macro.h>
char *
get_labeled_zonename(char *slabel)
{
m_label_t *bsl = NULL;
int err = 0;
ssize_t zonename_size = -1;
zoneid_t zid = -1;
char *zname = NULL;
syslog(LOG_DEBUG, "lpsched: get_labeled_zonename %s", slabel);
if (str_to_label(slabel, &bsl, USER_CLEAR,
L_NO_CORRECTION, &err) == -1) {
syslog(LOG_WARNING,
"lpsched: %s: label not recognized (error==%d)",
slabel, err);
return ((char *)-1);
}
if ((zid = getzoneidbylabel(bsl)) < 0) {
syslog(LOG_WARNING,
"lpsched: cannot send mail, no zone with %s label",
slabel);
m_label_free(bsl);
return ((char *)-1);
}
zname = Malloc(ZONENAME_MAX + 1);
if ((zonename_size = getzonenamebyid(zid, zname, ZONENAME_MAX + 1))
== -1) {
syslog(LOG_WARNING,
"lpsched: cannot send mail, no zone name for %s",
slabel);
m_label_free(bsl);
Free(zname);
return ((char *)-1);
} else {
m_label_free(bsl);
if (strcmp(zname, GLOBAL_ZONENAME) == 0) {
Free(zname);
zname = NULL;
}
}
return (zname);
}
int
get_peer_label(int fd, char **slabel)
{
if (is_system_labeled()) {
ucred_t *uc = NULL;
m_label_t *sl;
m_label_t admin_low;
m_label_t admin_high;
char *pslabel = NULL;
if ((fd < 0) || (slabel == NULL)) {
errno = EINVAL;
return (-1);
}
bsllow(&admin_low);
bslhigh(&admin_high);
if (getpeerucred(fd, &uc) == -1)
return (-1);
sl = ucred_getlabel(uc);
if (blequal(sl, &admin_low)) {
sl = &admin_high;
syslog(LOG_DEBUG, "get_peer_label(): upgrade"
" admin_low label to admin_high");
}
if (label_to_str(sl, &pslabel, M_INTERNAL, DEF_NAMES) != 0)
syslog(LOG_WARNING, "label_to_str(): %m");
ucred_free(uc);
if (pslabel != NULL) {
syslog(LOG_DEBUG, "get_peer_label(%d, %s): becomes %s",
fd, (*slabel ? *slabel : "NULL"), pslabel);
if (*slabel != NULL)
free(*slabel);
*slabel = strdup(pslabel);
}
}
return (0);
}