예제 #1
0
파일: tx.c 프로젝트: CoryXie/opensolaris
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);
}
예제 #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);
}
예제 #3
0
파일: seg.c 프로젝트: boundles/MergeWav
/*
 * Set segment labels where the labels are given as a string of names
 * separated by a + sign. Return number of labels created or -1 in
 * case of error.
 */
int set_seg_label(asseg_t *p, char *name)
{
  if (name) {
    if (p->label)
      seg_label_free(p->label);
    
    if ((p->label = str_to_label(name)) == NULL) {
      fprintf(stderr, "set_seg_label() -- cannot convert string '%s' to label\n", name);
      return(-1);
    }
  }
  else {
    p->label = NULL;
    return(0);
  }

  return(p->label->nlabels);
}
예제 #4
0
파일: seg.c 프로젝트: boundles/MergeWav
/*
 * Create a segment with the specified attributes.
 */
asseg_t *seg_create(char *name, float st, float et, float score)
{
  asseg_t *p;

  if ((p = (asseg_t *)malloc(sizeof(asseg_t))) == NULL) {
    fprintf(stderr, "seg_create() -- unable to allocate %d bytes\n", sizeof(asseg_t));
    return(NULL);
  }

  p->label = (seglab_t *)NULL;
  p->st = st;
  p->et = et;
  p->score = score;
  p->next = p->prev = NULL;

  if (name) {
    if ((p->label = str_to_label(name)) == NULL) {
      fprintf(stderr, "seg_create() -- cannot set segment label\n");
      seg_free(p);
    }
  }

  return(p);
}
예제 #5
0
파일: seg.c 프로젝트: boundles/MergeWav
/*
 * Add segment labels where the labels are given as a string of names
 * separated by a + sign. Return number of labels added or -1 in
 * case of error.
 */
int add_seg_label(asseg_t *p, char *name)
{
  unsigned short i, j, nadded = 0;
  seglab_t *lab;
  
  if (name) {
    
    if (p->label == NULL)
      return(set_seg_label(p, name));
    
    if ((lab = str_to_label(name)) == NULL) {
      fprintf(stderr, "add_seg_label() -- cannot convert string '%s' to label\n", name);
      return(-1);
    }
    
    nadded = lab->nlabels;
    
    if ((p->label->name = (char **)realloc(p->label->name, (p->label->nlabels + nadded) * sizeof(char *))) == NULL) {
      fprintf(stderr, "set_seg_label() -- cannot allocate %d bytes\n", (p->label->nlabels + nadded) * sizeof(char *));
      p->label->nlabels = 0;
      return(-1);
    }
    
    for (i = 0, j = p->label->nlabels; i < nadded; i++, j++) {
      if ((p->label->name[j] = strdup(lab->name[i])) == NULL) {
	fprintf(stderr, "set_seg_label() -- cannot allocate %d bytes\n", strlen(lab->name[i]));
	return(-1);
      }
      p->label->nlabels++;
    }

    seg_label_free(lab);
  }

  return(nadded);
}
예제 #6
0
tsol_zcent_t *
tsol_sgetzcent(const char *instr, int *errp, char **errstrp)
{
	int err;
	m_label_t *slp;
	char *errstr;
	tsol_zcent_t *zc;
	const char *nextf;
	char *cp;
	char fieldbuf[1024];

	/*
	 * The user can specify NULL pointers for these.  Make sure that we
	 * don't have to deal with checking for NULL everywhere by just
	 * pointing to our own variables if the user gives NULL.
	 */
	if (errp == NULL)
		errp = &err;
	if (errstrp == NULL)
		errstrp = &errstr;

	/* The default, unless we find a more specific error locus. */
	*errstrp = (char *)instr;

	if ((zc = calloc(1, sizeof (*zc))) == NULL) {
		*errp = LTSNET_SYSERR;
		return (NULL);
	}

	/* First, parse off the zone name. */
	instr = parse_entry(zc->zc_name, sizeof (zc->zc_name), instr, "#;:\n");
	if (zc->zc_name[0] == '\0') {
		*errstrp = (char *)instr;
		if (*instr == '\0' || *instr == '#' || *instr == '\n')
			*errp = LTSNET_EMPTY;
		else if (*instr == ':')
			*errp = LTSNET_NO_NAME;
		else
			*errp = LTSNET_ILL_NAME;
		goto err_ret;
	}
	if (*instr != ':') {
		*errstrp = (char *)instr;
		if (*instr == '=' || *instr == ';')
			*errp = LTSNET_ILL_NAME;
		else
			*errp = LTSNET_ILL_ENTRY;
		goto err_ret;
	}
	instr++;

	/* Field two: parse off the label. */
	nextf = parse_entry(fieldbuf, sizeof (fieldbuf), instr, "#;:\n");
	if (*nextf != ':') {
		*errstrp = (char *)nextf;
		*errp = LTSNET_ILL_ENTRY;
		goto err_ret;
	}
	if (fieldbuf[0] == '\0') {
		*errstrp = (char *)instr;
		*errp = LTSNET_NO_LABEL;
		goto err_ret;
	}

	slp = &zc->zc_label;
	if (str_to_label(fieldbuf, &slp, MAC_LABEL, L_NO_CORRECTION, NULL)
	    != 0) {
		*errstrp = (char *)instr;
		*errp = LTSNET_ILL_LABEL;
		goto err_ret;
	}
	instr = nextf + 1;

	/* The kernel will apply the system doi to the zone label later */
	zc->zc_doi = 0;

	/* Field three: get match flag */
	errno = 0;
	zc->zc_match = (uchar_t)strtol(instr, &cp, 0);
	if (errno != 0 || (*cp != ':' && *cp != '\0')) {
		*errp = LTSNET_ILL_FLAG;
		*errstrp = (char *)instr;
		goto err_ret;
	}
	if (*cp != ':') {
		*errp = LTSNET_ILL_VALDELIM;
		*errstrp = cp;
		goto err_ret;
	}
	instr = cp + 1;

	/* Field four: get zone-specific MLP list. */
	nextf = parse_entry(fieldbuf, sizeof (fieldbuf), instr, "#:\n");
	if (*nextf != ':') {
		*errstrp = (char *)nextf;
		*errp = LTSNET_ILL_ENTRY;
		goto err_ret;
	}
	if (!parse_mlp_list(&zc->zc_private_mlp, fieldbuf, errp, errstrp)) {
		*errstrp = (char *)instr + (*errstrp - fieldbuf);
		goto err_ret;
	}
	instr = nextf + 1;

	/* Field five: get global MLP list. */
	nextf = parse_entry(fieldbuf, sizeof (fieldbuf), instr, "#:\n");
	if (*nextf != '\0' && *nextf != '#' && !isspace(*nextf)) {
		*errstrp = (char *)nextf;
		*errp = LTSNET_ILL_ENTRY;
		goto err_ret;
	}
	if (!parse_mlp_list(&zc->zc_shared_mlp, fieldbuf, errp, errstrp)) {
		*errstrp = (char *)instr + (*errstrp - fieldbuf);
		goto err_ret;
	}

	return (zc);

err_ret:
	err = errno;
	tsol_freezcent(zc);
	errno = err;
	return (NULL);
}