⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lsdbf.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * rd_dbf_line:	Returns the next non-comment line into the *		given buffer (up to DBFLINESZ bytes). *		Skips 'ignore' lines. * *		Returns:	0 = done, -1 = error,  * 				other = cmd line size incl. terminating null. *				*svc_code_p = service code; *				*id_p = user id string *				*res_p = reserved for future use *				*flags_p = decoded flags; *				cnd_line_p points to null terminated cmd line; * * When logging errors, the extern Dbflineno is used. */intrd_dbf_line(fp, bp, svc_code_p, flags_p, id_p, res_p, module_p, cmd_line_p)register FILE *fp;register char *bp;char **svc_code_p;int *flags_p;char **id_p;char **res_p;char **module_p;char **cmd_line_p;{	register int length;	register char *p;	do {		++Dbflineno;		length = 0;		if (!fgets(bp, DBFLINESZ, fp))  {			if (feof(fp))  {				return(0);	/* EOF	*/			}			if (ferror(fp))  {				sprintf(bp,dbfrderror,Dbflineno);				logmessage(bp);				return(-1);			}			sprintf(bp,dbfunknown,Dbflineno);			logmessage(bp);			return(-1);		/* Unknown error (?)	*/		}		if (*(bp+strlen(bp)-1) != '\n')  {  /* terminating newline? */			sprintf(bp, dbfbadlmsg, Dbflineno);			logmessage(bp);			return(-1);		}		*(bp + strlen(bp) -1) = (char)0; /* delete newline	*/		if (strlen(bp) && (p = strchr(bp, DBFCOMMENT)))			*p = (char)0;		/* delete comments	*/		if (!strlen(bp))			continue;		p = bp + strlen(bp) - 1;	/* bp->start; p->end	*/		while ((p != bp) && (isspace(*p)))  {			*p = (char)0;		/* delete terminating spaces */			--p;		}		while (*bp)			/* del beginning white space*/			if (isspace(*bp))				++bp;			else				break;		if (strlen(bp)) {		/* anything left?	*/		   if (!(length=scan_line(bp,svc_code_p,flags_p,id_p,res_p,module_p,cmd_line_p)) ||		     (*flags_p & DBF_UNKNOWN))  {  /* if bad line...	*/			DEBUG((1, "rd_dbf_line line %d, unknown flag character",			  Dbflineno));			sprintf(bp, dbfbadlmsg, Dbflineno);			logmessage(bp);			return(-1);		    }		}	}  while (!length);		/* until we have something */	DEBUG((5,"rd_dbf_line: line: %d,cmd line len: %d",Dbflineno, length+1));	return(length + 6);}/* * scan a non-white space line *		0 = error; *		other = length of cmd line; * *	non-null lines have the following format: * *	service_code: flags: id: reserved: modules: cmd_line # comments */intscan_line(bp, svc_code_p, flags_p, id_p, res_p, module_p, cmd_line_p)register char *bp;register char **svc_code_p;register int *flags_p;char **id_p;char **res_p;char **module_p;register char **cmd_line_p;{	register char *p;	int length;	extern isdigits();	*flags_p = 0;	length = strlen(bp);	if (!(p = strtok(bp, DBFTOKENS))) {	/* look for service code string */		DEBUG((9,"scan_line failed 1st strtok"));		return(0);	}	DEBUG((9,"scan_line: service code: <%s>", p));	*svc_code_p = p;	if (!(p = strtok((char *)0, DBFTOKENS)))  {		DEBUG((9,"scan_line failed 2nd strtok"));		return(0);	}	while (*p)  {		switch (*p)  {		case 'a':		/* administrative entry		*/		case 'A':			*flags_p |= DBF_ADMIN;			break;		case 'x':		/* service is turned off	*/		case 'X':			*flags_p |= DBF_OFF;			break;		case 'n':		/* null flag			*/		case 'N':			break;		default:			DEBUG((1,"scan_line: unknown flag char: 0x%x",*p));			*flags_p = DBF_UNKNOWN;			return(0);		}		++p;	}	if (!(p = strtok((char *)0, DBFTOKENS))) {		DEBUG((9,"scan_line failed 3rd strtok"));		return(0);	}	*id_p = p;	if (!(p = strtok((char *)0, DBFTOKENS))) {		DEBUG((9,"scan_line failed 4th strtok"));		return(0);	}	*res_p = p;	if (!(p = strtok((char *)0, DBFTOKENS))) {		DEBUG((9,"scan_line failed 5th strtok"));		return(0);	}	*module_p = p;	p += strlen(p) + 1;			/* go past separator */	if ((p - bp) >= length)		return(0);	DEBUG((9,"scan_line: modules: %s; line: %s; len: %d", *module_p, p, strlen(*module_p)+strlen(p)));	*cmd_line_p = p;	return(strlen(*svc_code_p)+strlen(*id_p)+strlen(*res_p)+strlen(*module_p)+strlen(p));}/* * getdbfentry:	Given a service code, return a pointer to the dbf_t *		entry.  Return NULL if the entry doesn't exist. */dbf_t *getdbfentry(svc_code_p)register char *svc_code_p;{	register dbf_t 	*dbp = Dbfhead;	if (!Dbfhead)		/* no services in database file */		return((dbf_t *)0);	if ((svc_code_p) && strlen(svc_code_p))		for (dbp = Dbfhead;  dbp->dbf_svc_code;   ++dbp)			if (!strcmp(dbp->dbf_svc_code, svc_code_p))				return(dbp);	return((dbf_t *)0);	/* svc code not in list	*/}/* * mkdbfargv:	Given a pointer to a dbf_t, construct argv *		for an exec system call. *		Warning: returns a pointer to static data which are *			 overritten by each call. * *		There is a practical limit of 50 arguments (including argv[0]) * *		Warning: calling mkdbfargv destroys the data (by writing null *		characters via strtok) pointed to by dbp->dbf_cmd_line. */static char *dbfargv[50];static char *delim = " \t'\"";		/* delimiters */char **mkdbfargv(dbp)register dbf_t	*dbp;{	register char **argvp = dbfargv;	register char *p = dbp->dbf_cmd_line;	char delch;	register char *savep;	register char *tp;	char scratch[BUFSIZ];	char *strpbrk();#ifdef	DEBUGMODE	register int i = 0;#endif	*argvp = 0;	savep = p;	while (p && *p) {		if (p = strpbrk(p, delim)) {			switch (*p) {			case ' ':			case '\t':				/* "normal" cases */				*p++ = '\0';				*argvp++ = savep;				DEBUG((9, "argv[%d] = %s", i++, savep));				/* zap trailing white space */				while (isspace(*p))					p++;				savep = p;				break;			case '"':			case '\'':				/* found a string */				delch = *p; /* remember the delimiter */				savep = ++p;/* * We work the string in place, embedded instances of the string delimiter, * i.e. \" must have the '\' removed.  Since we'd have to do a compare to * decide if a copy were needed, it's less work to just do the copy, even * though it is most likely unnecessary. */				tp = p;				for (;;) {					if (*p == '\0') {						sprintf(scratch, "invalid command line, non-terminated string for service code %s", dbp->dbf_svc_code);						logmessage(scratch);						exit(2); /* server, don't log */					}					if (*p == delch) {						if (*(tp - 1) == '\\') { /* \delim */							*(tp - 1) = *p;							p++;						}						else { /* end of string */							*tp = 0;							*argvp++ = savep;							DEBUG((9, "argv[%d] = %s", i++, savep));							p++;							/* zap trailing white space */							while (isspace(*p))								p++;							savep = p;							break;						}					}					else {						*tp++ = *p++;					}				}				break;			default:				logmessage("Internal error in parse routine");				exit(2); /* server, don't log */			}		}		else {			*argvp++ = savep;			DEBUG((9, "argv[%d] = %s", i++, savep));		}	}	*argvp = 0;	return(dbfargv);}#define VERSIONSTR	"# VERSION="check_version(){	FILE *fp;	char *line, *p, *tmp;	int version;	if ((fp = fopen(DBFNAME, "r")) == NULL) {		logmessage(dbfopenmsg);		error(E_DBF_IO, EXIT | NOCORE | NO_MSG);	}	if ((line = (char *) malloc(DBFLINESZ)) == NULL)		error(E_DBF_ALLOC, EXIT | NOCORE);	p = line;	while (fgets(p, DBFLINESZ, fp)) {		if (!strncmp(p, VERSIONSTR, strlen(VERSIONSTR))) {			/* pitch the newline */			tmp = strchr(p, '\n');			if (tmp)				*tmp = '\0';			else {				logmessage(dbfcorrupt);				error(E_DBF_CORRUPT, EXIT | NOCORE);			}			p += strlen(VERSIONSTR);			if (*p)				version = atoi(p);			else {				logmessage(dbfcorrupt);				error(E_DBF_CORRUPT, EXIT | NOCORE);			}			free(line);			fclose(fp);			if (version != VERSION)				return(1);	/* wrong version */			else				return(0);	/* version ok */		}		p = line;	}	logmessage(dbfcorrupt);	error(E_DBF_CORRUPT, EXIT | NOCORE);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -