Ejemplo n.º 1
0
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);
	/*
	 * convert the label to binary.
	 */
	if (str_to_label(slabel, &bsl, USER_CLEAR,
	    L_NO_CORRECTION, &err) == -1) {
		/* label could not be converted, error */
		syslog(LOG_WARNING,
		    "lpsched: %s: label not recognized (error==%d)",
		    slabel, err);
		return ((char *)-1);
	}
	if ((zid = getzoneidbylabel(bsl)) < 0) {
		/* no zone with that label, cannot send mail */
		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) {
		/* cannot get zone name, cannot send mail */
		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);
}
Ejemplo n.º 2
0
static const char *
check_label(const char *labelstr)
{
	int	err;
	m_label_t *lbl = NULL;

	if (!is_system_labeled())
		return (NULL);

	err = str_to_label(labelstr, &lbl, MAC_LABEL, L_NO_CORRECTION, NULL);
	m_label_free(lbl);

	if (err == -1)
		return (labelstr);

	return (NULL);
}
Ejemplo n.º 3
0
int
putsecure(char *file, SECURE *secbufp)
{
	char			*path;

	int fd;

	int			fld;

	if (*file == '/')
		path = Strdup(file);
	else
		path = makepath(Lp_Requests, file, (char *)0);
	if (!path)
		return (-1);

	if ((fd = open_locked(path, "w", MODE_NOREAD)) < 0) {
		Free (path);
		return (-1);
	}
	Free (path);

	if (
		!secbufp->req_id ||
		!secbufp->user
	)
		return (-1);

	for (fld = 0; fld < SC_MAX; fld++)

		switch (fld) {

		case SC_REQID:
			(void)fdprintf(fd, "%s\n", secbufp->req_id);
			break;

		case SC_UID:
			(void)fdprintf(fd, "%u\n", secbufp->uid);
			break;

		case SC_USER:
			(void)fdprintf(fd, "%s\n", secbufp->user);
			break;

		case SC_GID:
			(void)fdprintf(fd, "%u\n", secbufp->gid);
			break;

		case SC_SIZE:
			(void)fdprintf(fd, "%lu\n", secbufp->size);
			break;

		case SC_DATE:
			(void)fdprintf(fd, "%ld\n", secbufp->date);
			break;

		case SC_SLABEL:
			if (secbufp->slabel == NULL) {
				if (is_system_labeled()) {
					m_label_t *sl;

					sl = m_label_alloc(MAC_LABEL);
					(void) getplabel(sl);
					if (label_to_str(sl, &(secbufp->slabel),
					    M_INTERNAL, DEF_NAMES) != 0) {
						perror("label_to_str");
						secbufp->slabel =
						    strdup("bad_label");
					}
					m_label_free(sl);
					(void) fdprintf(fd, "%s\n",
					    secbufp->slabel);
				} else {
					(void) fdprintf(fd, "none\n");
				}
			} else {
				(void) fdprintf(fd, "%s\n", secbufp->slabel);
			}
			break;
		}
	close(fd);

	return (0);
}