Exemple #1
0
/*
 * The same, only for integers.
 */
static int
capdb_getaltnum(char *bp, const char *shrt, const char *lng, long dflt,
    long *result)
{
	int status;

	status = cgetnum(bp, (char *)/*XXX*/lng, result);
	if (status >= 0)
		return status;
	status = cgetnum(bp, (char *)/*XXX*/shrt, result);
	if (status >= 0)
		return status;
	*result = dflt;
	return 0;
}	
Exemple #2
0
/*
 * Perform lookup for printer name or abbreviation --
 */
static void
chkprinter(const char *s)
{
	char *cp;

	getprintcap(s);
	RG = cgetstr(bp, "rg", &cp) == -1 ? NULL : cp;
	if (cgetnum(bp, "mx", &MX) < 0)
		MX = DEFMX;
	if (cgetnum(bp,"mc", &MC) < 0)
		MC = DEFMAXCOPIES;
	if (cgetnum(bp, "du", &DU) < 0)
		DU = DEFUID;
	SC = (cgetcap(bp, "sc", ':') != NULL);
}
Exemple #3
0
/*
 * Perform lookup for printer name or abbreviation --
 */
static int
chkprinter(const char *s)
{
	int stat;
	int len;

	if ((stat = cgetent(&bp, printcapdb, s)) == -2) {
		printf("pac: can't open printer description file\n");
		exit(3);
	} else if (stat == -1)
		return(0);
	else if (stat == -3)
		fatal("potential reference loop detected in printcap file");

	if (cgetstr(bp, "af", &acctfile) == -1) {
		printf("accounting not enabled for printer %s\n", printer);
		exit(2);
	}
	if (!pflag && (cgetnum(bp, "pc", &price100) == 0))
		price = price100/10000.0;
	len = strlen(acctfile) + 5;
	sumfile = (char *) malloc(len);
	if (sumfile == NULL)
		err(1, "pac");
	strlcpy(sumfile, acctfile, len);
	strlcat(sumfile, "_sum", len);
	return(1);
}
Exemple #4
0
static int getmodemparms (const char *modem)
{
	char *bp, *db_array [3], *modempath;
	int ndx, stat;
	modem_parm_t *mpp;

	modempath = getenv ("MODEMS");

	ndx = 0;

	if (modempath != NULL)
		db_array [ndx++] = modempath;

	db_array [ndx++] = _PATH_MODEMS;
	db_array [ndx] = NULL;

	if ((stat = cgetent (&bp, db_array, (char *)modem)) < 0) {
		switch (stat) {
		case -1:
			warnx ("unknown modem %s", modem);
			break;
		case -2:
			warnx ("can't open modem description file");
			break;
		case -3:
			warnx ("possible reference loop in modem description file");
			break;
		}
		return 0;
	}
	for (mpp = modem_parms; mpp->name; mpp++)
	{
		switch (mpp->modem_parm_type)
		{
		case mpt_string:
			if (cgetstr (bp, (char *)mpp->name, mpp->value.string) == -1)
				*mpp->value.string = mpp->default_value.string;
			break;
		case mpt_number:
		{
			long l;
			if (cgetnum (bp, (char *)mpp->name, &l) == -1)
				*mpp->value.number = mpp->default_value.number;
			else
				*mpp->value.number = (unsigned int)l;
		}
			break;
		case mpt_boolean:
			*mpp->value.number = cgetflag ((char *)mpp->name);
			break;
		default:
			break;
		}
	}
	strncpy (modem_name, modem, sizeof (modem_name) - 1);
	modem_name [sizeof (modem_name) - 1] = '\0';
	return 1;
}
Exemple #5
0
/*
 * Perform lookup for printer name or abbreviation --
 */
static void
chkprinter(char *s)
{
	int status;

	if ((status = cgetent(&bp, printcapdb, s)) == -2)
		errx(1, "cannot open printer description file");
	else if (status == -1)
		errx(1, "%s: unknown printer", s);
	if (cgetstr(bp, "sd", &SD) == -1)
		SD = _PATH_DEFSPOOL;
	if (cgetstr(bp, "lo", &LO) == -1)
		LO = DEFLOCK;
	cgetstr(bp, "rg", &RG);
	if (cgetnum(bp, "mx", &MX) < 0)
		MX = DEFMX;
	if (cgetnum(bp, "mc", &MC) < 0)
		MC = DEFMAXCOPIES;
	if (cgetnum(bp, "du", &DU) < 0)
		DU = DEFUID;
	SC = (cgetcap(bp, "sc", ':') != NULL);
	SH = (cgetcap(bp, "sh", ':') != NULL);
}
Exemple #6
0
/*
 * Get a table entry.
 */
void
gettable(char *name, char *buf)
{
	struct gettystrs *sp;
	struct gettynums *np;
	struct gettyflags *fp;
	long n;
	char *dba[2];
	dba[0] = _PATH_GETTYTAB;
	dba[1] = 0;

	if (cgetent(&buf, dba, name) != 0)
		return;

	for (sp = gettystrs; sp->field; sp++)
		cgetstr(buf, sp->field, &sp->value);
	for (np = gettynums; np->field; np++) {
		if (cgetnum(buf, np->field, &n) == -1)
			np->set = 0;
		else {
			np->set = 1;
			np->value = n;
		}
	}
	for (fp = gettyflags; fp->field; fp++) {
		if (cgetcap(buf, fp->field, ':') == NULL)
			fp->set = 0;
		else {
			fp->set = 1;
			fp->value = 1 ^ fp->invrt;
		}
	}
#ifdef DEBUG
	printf("name=\"%s\", buf=\"%s\"\n", name, buf);
	for (sp = gettystrs; sp->field; sp++)
		printf("cgetstr: %s=%s\n", sp->field, sp->value);
	for (np = gettynums; np->field; np++)
		printf("cgetnum: %s=%d\n", np->field, np->value);
	for (fp = gettyflags; fp->field; fp++)
		printf("cgetflags: %s='%c' set='%c'\n", fp->field,
		    fp->value + '0', fp->set + '0');
	exit(1);
#endif /* DEBUG */
}
Exemple #7
0
void
try_remote(const char *host, const char *path, const char *entry)
{
	const char	*paths[] = { "/etc/remote", NULL, NULL };
	char		*cp, *s;
	long		 l;
	int		 error;

	if (path != NULL) {
		paths[0] = path;
		paths[1] = "/etc/remote";
	}

	if (entry != NULL && cgetset(entry) != 0)
		cu_errx(1, "cgetset failed");
	error = cgetent(&cp, (char**)paths, (char*)host);
	if (error < 0) {
		switch (error) {
		case -1:
			cu_errx(1, "unknown host %s", host);
		case -2:
			cu_errx(1, "can't open remote file");
		case -3:
			cu_errx(1, "loop in remote file");
		default:
			cu_errx(1, "unknown error in remote file");
		}
	}

	if (line_path == NULL && cgetstr(cp, "dv", &s) >= 0)
		line_path = s;

	if (line_speed == -1 && cgetnum(cp, "br", &l) >= 0) {
		if (l < 0 || l > INT_MAX)
			cu_errx(1, "speed out of range");
		line_speed = l;
	}
}
Exemple #8
0
struct disklabel *
getdiskbyname(const char *name)
{
	static struct	disklabel disk;
	struct	disklabel *dp = &disk;
	struct partition *pp;
	char	*buf;
	char  	*db_array[2] = { _PATH_DISKTAB, 0 };
	char	*cp, *cq;	/* can't be register */
	char	p, max, psize[3], pbsize[3],
		pfsize[3], poffset[3], ptype[3];
	u_int32_t *dx;

	if (cgetent(&buf, db_array, (char *) name) < 0)
		return NULL;

	bzero((char *)&disk, sizeof(disk));
	/*
	 * typename
	 */
	cq = dp->d_typename;
	cp = buf;
	while (cq < dp->d_typename + sizeof(dp->d_typename) - 1 &&
	    (*cq = *cp) && *cq != '|' && *cq != ':')
		cq++, cp++;
	*cq = '\0';

	if (cgetstr(buf, "ty", &cq) > 0 && strcmp(cq, "removable") == 0)
		dp->d_flags |= D_REMOVABLE;
	else  if (cq && strcmp(cq, "simulated") == 0)
		dp->d_flags |= D_RAMDISK;
	if (cgetcap(buf, "sf", ':') != NULL)
		dp->d_flags |= D_BADSECT;

#define getnumdflt(field, dname, dflt) \
        { long f; (field) = (cgetnum(buf, dname, &f) == -1) ? (dflt) : f; }

	getnumdflt(dp->d_secsize, "se", DEV_BSIZE);
	getnumdflt(dp->d_ntracks, "nt", 0);
	getnumdflt(dp->d_nsectors, "ns", 0);
	getnumdflt(dp->d_ncylinders, "nc", 0);

	if (cgetstr(buf, "dt", &cq) > 0)
		dp->d_type = gettype(cq, dktypenames);
	else
		getnumdflt(dp->d_type, "dt", 0);
	getnumdflt(dp->d_secpercyl, "sc", dp->d_nsectors * dp->d_ntracks);
	getnumdflt(dp->d_secperunit, "su", dp->d_secpercyl * dp->d_ncylinders);
	getnumdflt(dp->d_rpm, "rm", 3600);
	getnumdflt(dp->d_interleave, "il", 1);
	getnumdflt(dp->d_trackskew, "sk", 0);
	getnumdflt(dp->d_cylskew, "cs", 0);
	getnumdflt(dp->d_headswitch, "hs", 0);
	getnumdflt(dp->d_trkseek, "ts", 0);
	getnumdflt(dp->d_bbsize, "bs", BBSIZE);
	getnumdflt(dp->d_sbsize, "sb", 0);
	strcpy(psize, "px");
	strcpy(pbsize, "bx");
	strcpy(pfsize, "fx");
	strcpy(poffset, "ox");
	strcpy(ptype, "tx");
	max = 'a' - 1;
	pp = &dp->d_partitions[0];
	for (p = 'a'; p < 'a' + MAXPARTITIONS; p++, pp++) {
		long l;
		psize[1] = pbsize[1] = pfsize[1] = poffset[1] = ptype[1] = p;
		if (cgetnum(buf, psize, &l) == -1)
			pp->p_size = 0;
		else {
			pp->p_size = l;
			cgetnum(buf, poffset, &l);
			pp->p_offset = l;
			getnumdflt(pp->p_fsize, pfsize, 0);
			if (pp->p_fsize) {
				long bsize;

				if (cgetnum(buf, pbsize, &bsize) == 0)
					pp->p_frag = bsize / pp->p_fsize;
				else
					pp->p_frag = 8;
			}
			getnumdflt(pp->p_fstype, ptype, 0);
			if (pp->p_fstype == 0 && cgetstr(buf, ptype, &cq) > 0)
				pp->p_fstype = gettype(cq, fstypenames);
			max = p;
		}
	}
	dp->d_npartitions = max + 1 - 'a';
	(void)strcpy(psize, "dx");
	dx = dp->d_drivedata;
	for (p = '0'; p < '0' + NDDATA; p++, dx++) {
		psize[1] = p;
		getnumdflt(*dx, psize, 0);
	}
	dp->d_magic = DISKMAGIC;
	dp->d_magic2 = DISKMAGIC;
	free(buf);
	return (dp);
}
Exemple #9
0
struct disklabel *
getdiskbyname(const char *name)
{
	static struct	disklabel disk;
	struct	disklabel *dp = &disk;
	struct partition *pp;
	char	*buf;
	char	*db_array[2] = { _PATH_DISKTAB, 0 };
	char	*cp, *cq;
	char	p, max, psize[3], pbsize[3],
		pfsize[3], poffset[3], ptype[3];
	u_int32_t *dx;

	if (cgetent(&buf, db_array, (char *) name) < 0)
		return NULL;

	bzero((char *)&disk, sizeof(disk));
	/*
	 * typename
	 */
	cq = dp->d_typename;
	cp = buf;
	while (cq < dp->d_typename + sizeof(dp->d_typename) - 1 &&
	    (*cq = *cp) && *cq != '|' && *cq != ':')
		cq++, cp++;
	*cq = '\0';

	if (cgetcap(buf, "sf", ':') != NULL)
		dp->d_flags |= D_BADSECT;

#define getnumdflt(field, dname, dflt) \
	{ long f; (field) = (cgetnum(buf, dname, &f) == -1) ? (dflt) : f; }
#define	getnum(field, dname) \
	{ long f; cgetnum(buf, dname, &f); field = f; }

	getnumdflt(dp->d_secsize, "se", DEV_BSIZE);
	getnum(dp->d_ntracks, "nt");
	getnum(dp->d_nsectors, "ns");
	getnum(dp->d_ncylinders, "nc");

	if (cgetstr(buf, "dt", &cq) > 0)
		dp->d_type = (u_short)gettype(cq, dktypenames);
	else
		getnumdflt(dp->d_type, "dt", 0);
	getnumdflt(dp->d_secpercyl, "sc", dp->d_nsectors * dp->d_ntracks);
	/* XXX */
	dp->d_secperunith = 0;
	getnumdflt(dp->d_secperunit, "su", dp->d_secpercyl * dp->d_ncylinders);
	getnumdflt(dp->d_bbsize, "bs", BBSIZE);
	getnumdflt(dp->d_sbsize, "sb", SBSIZE);
	strlcpy(psize, "px", sizeof psize);
	strlcpy(pbsize, "bx", sizeof pbsize);
	strlcpy(pfsize, "fx", sizeof pfsize);
	strlcpy(poffset, "ox", sizeof poffset);
	strlcpy(ptype, "tx", sizeof ptype);
	max = 'a' - 1;
	pp = &dp->d_partitions[0];
	dp->d_version = 1;
	for (p = 'a'; p < 'a' + MAXPARTITIONS; p++, pp++) {
		long f;

		psize[1] = pbsize[1] = pfsize[1] = poffset[1] = ptype[1] = p;
		/* XXX */
		if (cgetnum(buf, psize, &f) == -1)
			DL_SETPSIZE(pp, 0);
		else {
			u_int32_t fsize, frag = 8;

			DL_SETPSIZE(pp, f);
			/* XXX */
			pp->p_offseth = 0;
			getnum(pp->p_offset, poffset);
			getnumdflt(fsize, pfsize, 0);
			if (fsize) {
				long bsize;

				if (cgetnum(buf, pbsize, &bsize) == 0)
					frag = bsize / fsize;
				pp->p_fragblock =
				    DISKLABELV1_FFS_FRAGBLOCK(fsize, frag);
			}
			getnumdflt(pp->p_fstype, ptype, 0);
			if (pp->p_fstype == 0 && cgetstr(buf, ptype, &cq) > 0)
				pp->p_fstype = (u_char)gettype(cq, fstypenames);
			max = p;
		}
	}
	dp->d_npartitions = max + 1 - 'a';
	(void)strlcpy(psize, "dx", sizeof psize);
	dx = dp->d_drivedata;
	for (p = '0'; p < '0' + NDDATA; p++, dx++) {
		psize[1] = p;
		getnumdflt(*dx, psize, 0);
	}
	dp->d_magic = DISKMAGIC;
	dp->d_magic2 = DISKMAGIC;
	free(buf);
	return (dp);
}
Exemple #10
0
struct disklabel *
getdiskbyname(const char *name)
{
	static struct	disklabel disk;
	struct	disklabel *dp = &disk;
	struct partition *pp;
	char	*buf;
	char	*cp, *cq;	/* can't be */
	char	p, max, psize[3], pbsize[3],
		pfsize[3], poffset[3], ptype[3];
	u_int32_t *dx;
	long f;

	_DIAGASSERT(name != NULL);

	if (cgetent(&buf, db_array, name) < 0)
		return NULL;

	memset(&disk, 0, sizeof(disk));
	/*
	 * typename
	 */
	cq = dp->d_typename;
	cp = buf;
	while (cq < dp->d_typename + sizeof(dp->d_typename) - 1 &&
	    (*cq = *cp) && *cq != '|' && *cq != ':')
		cq++, cp++;
	*cq = '\0';
	/*
	 * boot name (optional)  xxboot, bootxx
	 */
	cgetstr(buf, "b0", &dp->d_boot0);
	cgetstr(buf, "b1", &dp->d_boot1);

	if (cgetstr(buf, "ty", &cq) >= 0) {
		if (strcmp(cq, "removable") == 0)
			dp->d_flags |= D_REMOVABLE;
		else if (strcmp(cq, "simulated") == 0)
			dp->d_flags |= D_RAMDISK;
		free(cq);
	}
	if (cgetcap(buf, "sf", ':') != NULL)
		dp->d_flags |= D_BADSECT;

#define getnumdflt(field, dname, dflt) \
    (field) = ((cgetnum(buf, dname, &f) == -1) ? (dflt) : (u_int32_t) f)
#define	getnum(field, dname) \
	if (cgetnum(buf, dname, &f) != -1) field = (u_int32_t)f

	getnumdflt(dp->d_secsize, "se", DEV_BSIZE);
	getnum(dp->d_ntracks, "nt");
	getnum(dp->d_nsectors, "ns");
	getnum(dp->d_ncylinders, "nc");

	if (cgetstr(buf, "dt", &cq) >= 0) {
		dp->d_type = gettype(cq, dktypenames);
		free(cq);
	} else
		getnumdflt(dp->d_type, "dt", 0);
	getnumdflt(dp->d_secpercyl, "sc", dp->d_nsectors * dp->d_ntracks);
	getnumdflt(dp->d_secperunit, "su", dp->d_secpercyl * dp->d_ncylinders);
	getnumdflt(dp->d_rpm, "rm", 3600);
	getnumdflt(dp->d_interleave, "il", 1);
	getnumdflt(dp->d_trackskew, "sk", 0);
	getnumdflt(dp->d_cylskew, "cs", 0);
	getnumdflt(dp->d_headswitch, "hs", 0);
	getnumdflt(dp->d_trkseek, "ts", 0);
	getnumdflt(dp->d_bbsize, "bs", BBSIZE);
	getnumdflt(dp->d_sbsize, "sb", SBLOCKSIZE);
	strcpy(psize, "px");	/* XXX: strcpy is safe */
	strcpy(pbsize, "bx");	/* XXX: strcpy is safe */
	strcpy(pfsize, "fx");	/* XXX: strcpy is safe */
	strcpy(poffset, "ox");	/* XXX: strcpy is safe */
	strcpy(ptype, "tx");	/* XXX: strcpy is safe */
	max = 'a' - 1;
	pp = &dp->d_partitions[0];
	for (p = 'a'; p < 'a' + MAXPARTITIONS; p++, pp++) {
		long ff;

		psize[1] = pbsize[1] = pfsize[1] = poffset[1] = ptype[1] = p;
		if (cgetnum(buf, psize, &ff) == -1)
			pp->p_size = 0;
		else {
			pp->p_size = (u_int32_t)ff;
			getnum(pp->p_offset, poffset);
			getnumdflt(pp->p_fsize, pfsize, 0);
			if (pp->p_fsize) {
				long bsize;

				if (cgetnum(buf, pbsize, &bsize) == -1)
					pp->p_frag = 8;
				else
					pp->p_frag =
					    (u_int8_t)(bsize / pp->p_fsize);
			}
			getnumdflt(pp->p_fstype, ptype, 0);
			if (pp->p_fstype == 0)
				if (cgetstr(buf, ptype, &cq) >= 0) {
					pp->p_fstype = gettype(cq, fstypenames);
					free(cq);
				}
			max = p;
		}
	}
	dp->d_npartitions = max + 1 - 'a';
	strcpy(psize, "dx");	/* XXX: strcpy is safe */
	dx = dp->d_drivedata;
	for (p = '0'; p < '0' + NDDATA; p++, dx++) {
		psize[1] = p;
		getnumdflt(*dx, psize, 0);
	}
	dp->d_magic = DISKMAGIC;
	dp->d_magic2 = DISKMAGIC;
	free(buf);
	return (dp);
}
Exemple #11
0
static void
getremcap(char *host)
{
	char **p, ***q;
	char *bp;
	char *rempath;
	int   stat;

	rempath = getenv("REMOTE");
	if (rempath != NULL) {
		if (*rempath != '/')
			/* we have an entry */
			cgetset(rempath);
		else {	/* we have a path */
			db_array[1] = rempath;
			db_array[2] = _PATH_REMOTE;
		}
	}

	if ((stat = cgetent(&bp, db_array, host)) < 0) {
		if (DV ||
		    (host[0] == '/' && access(DV = host, R_OK | W_OK) == 0)) {
			CU = DV;
			HO = host;
			HW = 1;
			DU = 0;
			if (!BR)
				BR = DEFBR;
			FS = BUFSIZ;
			return;
		}
		switch(stat) {
		case -1:
			warnx("unknown host %s", host);
			break;
		case -2:
			warnx("can't open host description file");
			break;
		case -3:
			warnx("possible reference loop in host description file");
			break;
		}
		exit(3);
	}

	for (p = capstrings, q = caps; *p != NULL; p++, q++)
		if (**q == NULL)
			cgetstr(bp, *p, *q);
	if (!BR && (cgetnum(bp, "br", &BR) == -1))
		BR = DEFBR;
	if (cgetnum(bp, "fs", &FS) == -1)
		FS = BUFSIZ;
	if (DU < 0)
		DU = 0;
	else
		DU = cgetflag("du");
	if (DV == NULL) {
		fprintf(stderr, "%s: missing device spec\n", host);
		exit(3);
	}
	if (DU && CU == NULL)
		CU = DV;
	if (DU && PN == NULL) {
		fprintf(stderr, "%s: missing phone number\n", host);
		exit(3);
	}

	HD = cgetflag("hd");

	/*
	 * This effectively eliminates the "hw" attribute
	 *   from the description file
	 */
	if (!HW)
		HW = (CU == NULL) || (DU && equal(DV, CU));
	HO = host;

	/*
		If login script, verify access
	*/
	if (LI != NULL) {
		if (*LI == '~')
			(void) expand_tilde (&LI, NULL);
		if (access (LI, F_OK | X_OK) != 0) {
			printf("tip (warning): can't open login script \"%s\"\n", LI);
			LI = NULL;
		}
	}

	/*
		If logout script, verify access
	*/
	if (LO != NULL) {
		if (*LO == '~')
			(void) expand_tilde (&LO, NULL);
		if (access (LO, F_OK | X_OK) != 0) {
			printf("tip (warning): can't open logout script \"%s\"\n", LO);
			LO = NULL;
		}
	}

	/*
	 * see if uppercase mode should be turned on initially
	 */
	if (cgetflag("ra"))
		boolean(value(RAISE)) = 1;
	if (cgetflag("ec"))
		boolean(value(ECHOCHECK)) = 1;
	if (cgetflag("be"))
		boolean(value(BEAUTIFY)) = 1;
	if (cgetflag("nb"))
		boolean(value(BEAUTIFY)) = 0;
	if (cgetflag("sc"))
		boolean(value(SCRIPT)) = 1;
	if (cgetflag("tb"))
		boolean(value(TABEXPAND)) = 1;
	if (cgetflag("vb"))
		boolean(value(VERBOSE)) = 1;
	if (cgetflag("nv"))
		boolean(value(VERBOSE)) = 0;
	if (cgetflag("ta"))
		boolean(value(TAND)) = 1;
	if (cgetflag("nt"))
		boolean(value(TAND)) = 0;
	if (cgetflag("rw"))
		boolean(value(RAWFTP)) = 1;
	if (cgetflag("hd"))
		boolean(value(HALFDUPLEX)) = 1;
	if (RE == NULL)
		RE = (char *)"tip.record";
	if (EX == NULL)
		EX = (char *)"\t\n\b\f";
	if (ES != NULL)
		vstring("es", ES);
	if (FO != NULL)
		vstring("fo", FO);
	if (PR != NULL)
		vstring("pr", PR);
	if (RC != NULL)
		vstring("rc", RC);
	if (cgetnum(bp, "dl", &DL) == -1)
		DL = 0;
	if (cgetnum(bp, "cl", &CL) == -1)
		CL = 0;
	if (cgetnum(bp, "et", &ET) == -1)
		ET = 10;
}
Exemple #12
0
/*
 * Get a table entry.
 */
void
gettable(const char *name, char *buf)
{
	struct gettystrs *sp;
	struct gettynums *np;
	struct gettyflags *fp;
	long n;
	int l;
	char *p;
	char *msg = NULL;
	const char *dba[2];

	static int firsttime = 1;

	dba[0] = _PATH_GETTYTAB;
	dba[1] = NULL;

	if (firsttime) {
		/*
		 * we need to strdup() anything in the strings array
		 * initially in order to simplify things later
		 */
		for (sp = gettystrs; sp->field; sp++)
			if (sp->value != NULL) {
				/* handle these ones more carefully */
				if (sp >= &gettystrs[4] && sp <= &gettystrs[6])
					l = 2;
				else
					l = strlen(sp->value) + 1;
				if ((p = malloc(l)) != NULL) {
					strncpy(p, sp->value, l);
					p[l-1] = '\0';
				}
				/*
				 * replace, even if NULL, else we'll
				 * have problems with free()ing static mem
				 */
				sp->value = p;
			}
		firsttime = 0;
	}

	switch (cgetent(&buf, (char **)dba, (char *)name)) {
	case 1:
		msg = "%s: couldn't resolve 'tc=' in gettytab '%s'";
	case 0:
		break;
	case -1:
		msg = "%s: unknown gettytab entry '%s'";
		break;
	case -2:
		msg = "%s: retrieving gettytab entry '%s': %m";
		break;
	case -3:
		msg = "%s: recursive 'tc=' reference gettytab entry '%s'";
		break;
	default:
		msg = "%s: unexpected cgetent() error for entry '%s'";
		break;
	}

	if (msg != NULL) {
		syslog(LOG_ERR, msg, "getty", name);
		return;
	}

	for (sp = gettystrs; sp->field; sp++) {
		if ((l = cgetstr(buf, (char*)sp->field, &p)) >= 0) {
			if (sp->value) {
				/* prefer existing value */
				if (strcmp(p, sp->value) != 0)
					free(sp->value);
				else {
					free(p);
					p = sp->value;
				}
			}
			sp->value = p;
		} else if (l == -1) {
			free(sp->value);
			sp->value = NULL;
		}
	}

	for (np = gettynums; np->field; np++) {
		if (cgetnum(buf, (char*)np->field, &n) == -1)
			np->set = 0;
		else {
			np->set = 1;
			np->value = n;
		}
	}

	for (fp = gettyflags; fp->field; fp++) {
		if (cgetcap(buf, (char *)fp->field, ':') == NULL)
			fp->set = 0;
		else {
			fp->set = 1;
			fp->value = 1 ^ fp->invrt;
		}
	}

#ifdef DEBUG
	printf("name=\"%s\", buf=\"%s\"\r\n", name, buf);
	for (sp = gettystrs; sp->field; sp++)
		printf("cgetstr: %s=%s\r\n", sp->field, sp->value);
	for (np = gettynums; np->field; np++)
		printf("cgetnum: %s=%d\r\n", np->field, np->value);
	for (fp = gettyflags; fp->field; fp++)
		printf("cgetflags: %s='%c' set='%c'\r\n", fp->field, 
		       fp->value + '0', fp->set + '0');
#endif /* DEBUG */
}
Exemple #13
0
void *
plot_open(const char *name, const char *def, FILE *fp)
{
	struct plotctx *pl;
	char *p, *dba[2];
	long n;
	int err, ontty;

	ontty = isatty(fileno(fp));
	if (name == NULL && ontty && (p = getenv("PLOTCAP")) != NULL) {
		if ((p = strdup(p)) == NULL)
			return (NULL);
	} else {
		dba[0] = _PATH_PLOTCAP;
		dba[1] = NULL;
		if (name == NULL) {
			if (ontty)
				name = getenv("TERM");
			if (name == NULL)
				name = def;
			if (name == NULL)
				return (NULL);
		}
		if (cgetent(&p, dba, name) != 0) {
			if (cgetent(&p, dba, def) != 0)
				return (NULL);
			else
				name = def;
		}
	}

	if ((pl = malloc(sizeof(*pl))) == NULL) {
		free(p);
		return (NULL);
	}
	memset(pl, 0, sizeof(*pl));
	pl->buf = p;

	if (cgetnum(pl->buf, "w", &n) == 0)
		pl->dx = pl->w = n;

	if (cgetnum(pl->buf, "h", &n) < 0)
		pl->dx = pl->w = 0;
	else
		pl->dx = pl->h = n;

	if (cgetcap(pl->buf, "le", ':'))
		pl->flags |= LENDIAN;

	/* scale at 1:1 */
	pl->ox = pl->oy = 0;
	pl->xnum = pl->xdenom = pl->ynum = pl->ydenom = 1;

	pl->fp = fp? fp : stdout;

	if (cgetstr(pl->buf, "in", &p) > 0)
		if (_plot_out(pl, p)) {
			err = errno;
			free(pl->buf);
			free(pl);
			errno = err;
			return (NULL);
		}

	return (pl);
}
Exemple #14
0
static void
getremcap(char *host)
{
	char **p, ***q, *bp, *rempath;
	int   stat;

	rempath = getenv("REMOTE");
	if (rempath != NULL) {
		if (*rempath != '/')
			/* we have an entry */
			cgetset(rempath);
		else {	/* we have a path */
			db_array[1] = rempath;
			db_array[2] = _PATH_REMOTE;
		}
	}

	if ((stat = cgetent(&bp, db_array, host)) < 0) {
		if ((DV != NULL) ||
		    (host[0] == '/' && access(DV = host, R_OK | W_OK) == 0)) {
			CU = DV;
			HO = host;
			HW = 1;
			DU = 0;
			if (!BR)
				BR = DEFBR;
			FS = DEFFS;
			return;
		}
		switch (stat) {
		case -1:
			fprintf(stderr, "%s: unknown host %s\n", __progname,
			    host);
			break;
		case -2:
			fprintf(stderr,
			    "%s: can't open host description file\n",
			    __progname);
			break;
		case -3:
			fprintf(stderr,
			    "%s: possible reference loop in host description file\n", __progname);
			break;
		}
		exit(3);
	}

	for (p = capstrings, q = caps; *p != NULL; p++, q++)
		if (**q == NULL)
			cgetstr(bp, *p, *q);
	if (!BR && (cgetnum(bp, "br", &BR) == -1))
		BR = DEFBR;
	if (!LD && (cgetnum(bp, "ld", &LD) == -1))
		LD = TTYDISC;
	if (cgetnum(bp, "fs", &FS) == -1)
		FS = DEFFS;
	if (DU < 0)
		DU = 0;
	else
		DU = cgetflag("du");
	if (DV == NOSTR) {
		fprintf(stderr, "%s: missing device spec\n", host);
		exit(3);
	}
	if (DU && CU == NOSTR)
		CU = DV;
	if (DU && PN == NOSTR) {
		fprintf(stderr, "%s: missing phone number\n", host);
		exit(3);
	}
	if (DU && AT == NOSTR) {
		fprintf(stderr, "%s: missing acu type\n", host);
		exit(3);
	}

	HD = cgetflag("hd");

	/*
	 * This effectively eliminates the "hw" attribute
	 *   from the description file
	 */
	if (!HW)
		HW = (CU == NOSTR) || (DU && equal(DV, CU));
	HO = host;
	/*
	 * see if uppercase mode should be turned on initially
	 */
	if (cgetflag("ra"))
		setboolean(value(RAISE), 1);
	if (cgetflag("ec"))
		setboolean(value(ECHOCHECK), 1);
	if (cgetflag("be"))
		setboolean(value(BEAUTIFY), 1);
	if (cgetflag("nb"))
		setboolean(value(BEAUTIFY), 0);
	if (cgetflag("sc"))
		setboolean(value(SCRIPT), 1);
	if (cgetflag("tb"))
		setboolean(value(TABEXPAND), 1);
	if (cgetflag("vb"))
		setboolean(value(VERBOSE), 1);
	if (cgetflag("nv"))
		setboolean(value(VERBOSE), 0);
	if (cgetflag("ta"))
		setboolean(value(TAND), 1);
	if (cgetflag("nt"))
		setboolean(value(TAND), 0);
	if (cgetflag("rw"))
		setboolean(value(RAWFTP), 1);
	if (cgetflag("hd"))
		setboolean(value(HALFDUPLEX), 1);
	if (cgetflag("dc"))
		setboolean(value(DC), 1);
	if (cgetflag("hf"))
		setboolean(value(HARDWAREFLOW), 1);
	if (RE == NOSTR)
		RE = (char *)"tip.record";
	if (EX == NOSTR)
		EX = (char *)"\t\n\b\f";
	if (ES != NOSTR)
		vstring("es", ES);
	if (FO != NOSTR)
		vstring("fo", FO);
	if (PR != NOSTR)
		vstring("pr", PR);
	if (RC != NOSTR)
		vstring("rc", RC);
	if (cgetnum(bp, "dl", &DL) == -1)
		DL = 0;
	if (cgetnum(bp, "cl", &CL) == -1)
		CL = 0;
	if (cgetnum(bp, "et", &ET) == -1)
		ET = 10;
}