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

📄 lprsetup.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 4 页
字号:
    *  save names for rewrite    **************************/    if ((ptr = (char *)index(bp, ':')) > 0) {	strncpy (longname, bp, ptr - bp);	/* was &bp */    }    longname[ptr - bp] = '\0';	/* was &bp */    /****************************************************    * loop thru table, changing values where appropriate    ****************************************************/    for (i = 0; tab[i].name != 0; ++i)    {	switch (tab[i].stype)	{	    case BOOL:				if (pgetflag (tab[i].name) == TRUE)		{		    if ((tab[i].nvalue = (char *) malloc (strlen ("on") + 1)) == NULL)		    {			printf ("\nCannot malloc space for %s\n", tab[i].name);		    }		    else		    {		        strcpy (tab[i].nvalue, "on");		        tab[i].used = YES;		    }		}		break;	    case INT:		if ((num = pgetnum (tab[i].name)) >= 0)		{		    /* fc, fs, xc, xs are in octal, all others are decimal */		    if ((strcmp(tab[i].name, "fc") == 0) ||			(strcmp(tab[i].name, "fs") == 0) ||			(strcmp(tab[i].name, "xc") == 0) ||			(strcmp(tab[i].name, "xs") == 0)) {			(void) sprintf (tmpline, "%o", num);			strcpy(line, "0");	/* put the zero out in front */			strcat(line, tmpline);		    } else {		    	(void) sprintf (line, "%d", num);		    }		    if ((tab[i].nvalue = (char *) malloc (strlen (line) + 1)) == NULL)		    {			printf ("\nCannot malloc space for %s\n", tab[i].name);		    }		    else		    {		    	strcpy (tab[i].nvalue, line);		    	tab[i].used = YES;		    }		}		break;	    case STR:		lineptr = line;		if (pgetstr (tab[i].name, &lineptr) != NULL)		{		    *lineptr = 0;		    if ((tab[i].nvalue = (char *) malloc (strlen (line) + 1)) == NULL)		    {			printf ("\nCannot malloc space for %s\n", tab[i].name);		    }		    else		    {		   	strcpy(tab[i].nvalue, line);		    	tab[i].used = YES;		    }		}		break;	    default:		printf ("\nBad type (%d) for %s\n", tab[i].stype, tab[i].name);		break;	}    }    return(OK);}/*******************************  write comments for next entry********************************/WriteComments (fp)FILE *fp;{    int  i;        for (i = 0; i < numcomments; i++) {        fprintf (fp, "%s\n", printercomments[i]);    }}/*******************************  write single entry to file*******************************/WriteEntry (fp)FILE * fp;{    int     i;			/* temp index			 */    char   *curval;		/* pointer to current value	 */    char localname[LEN];	/* output filter, lp2 or whatever */    fprintf (fp, "%s:", pname);	/* here, pname is really the longname */    for (i = 0; tab[i].name != 0; ++i)    {	if (tab[i].used == YES)	{	    curval = (tab[i].nvalue ? tab[i].nvalue : tab[i].svalue);	    switch (tab[i].stype)	    {		case BOOL:		    if (strcmp ("on", curval) == 0)			fprintf (fp, "\\\n\t:%s:", tab[i].name);		    break;		case INT:		    if (strcmp ("none", curval) != 0)		        fprintf (fp, "\\\n\t:%s#%s:", tab[i].name, curval);		    break;		case STR:		    fprintf (fp, "\\\n\t:%s=%s:", tab[i].name, curval);		    break;		default:		    printf ("\nbad type (%d) for %s\n", tab[i].stype, tab[i].name);		    break;	    }	}    }    fprintf (fp, "\n");    return(OK);}/********************************  create accounting file *******************************/MakeAcct (passwd)struct passwd  *passwd;		/* password file entry	 */{    char   *acct;		/* parameter value ptr	 */    int    i, j;		/* temp index	*/    int    done;    char   intermediate[MAXPATH];   /* intermediate directories */    struct stat sb;    int filedescriptor;    for (i = 0; tab[i].name != 0; ++i)	if (strcmp (tab[i].name, "af") == 0)	    break;    if (tab[i].name == 0)    {	printf ("\nCannot find accounting file entry in table!\n");	printf ("No accounting file created.\n");	return (ERROR);    }    if (tab[i].used != YES) {	/* No account file specified */	return (OK);    }    acct = tab[i].nvalue ? tab[i].nvalue : tab[i].svalue;    if (stat(acct, &sb) < 0)     {	if (errno == ENOENT)	{            /*            * Accounting file does not exist, make any necessary            * intermediate directories as needed  DJG#1	    */            done = 0;            j = 1;            while (!done) {	        while (acct[j] != '/' && acct[j] != '\0') j++;	        if (acct[j] == '\0') break; /* Create file */	        strncpy (intermediate, acct, j);	        intermediate[j++] = '\0';                if (stat(intermediate, &sb) < 0) {	            if (mkdir(intermediate, DIRMODE) == -1) {	                printf ("\nCannot make intermediate accounting directory: %s\n", 			        intermediate);	                perror (intermediate);	                return (ERROR);                    }	            if (safechmod (intermediate, 00755) == -1)  /* incase root umask is not 022 */	            {		        printf ("\nCannot chmod %s to mode 0755\n", intermediate);		        perror (intermediate);		        return (ERROR);	            }                } else {	            /* this portion of the accounting file path exists... */	            if ((sb.st_mode&S_IFMT) != S_IFDIR) {	                printf ("\nIntermediate account directory: %s already exists\n",			        intermediate);		        printf ("But it is not a directory!\n");	                return (ERROR);	            }                }	    }            /* Create actual accounting file */	    filedescriptor=open(acct,O_CREAT,00644);	    if (filedescriptor == -1)	    {		printf("\nCannot create accounting file %s\n",acct);		perror (acct);		return (ERROR);	    }/*    	    if (safechmod (acct, 00644) == -1)    	    {		printf ("\nCannot chmod %s to mode 0644\n", acct);		perror (acct);	        close(filedescriptor);		return (ERROR);    	    }*/    	    if (safechown (acct, passwd -> pw_uid, passwd -> pw_gid) == -1)    	    {	        printf ("\nCannot chown %s to (%o/%o)\n", acct, passwd->pw_uid, passwd->pw_gid);		perror (acct);	        close(filedescriptor);		return (ERROR);    	    }	    close(filedescriptor);    	    return(OK);	}	else	{	    printf("\nCannot create accounting file %s\n",acct);	    perror (acct);	    return (ERROR);	}    }    else    {	printf("\nFile with same name as accounting file %s already exists\n",acct);	return (ERROR);    }}/********************************  create error log file if it doesn't already exist*******************************/MakeErrorlog (passwd)struct passwd  *passwd;		/* password file entry	 */{    char   *errlog;		/* parameter value ptr	 */    int    i, j;		/* temp index	*/    int    done;    char   intermediate[MAXPATH];   /* intermediate directories */    struct stat sb;    int filedescriptor;    for (i = 0; tab[i].name != 0; ++i)	if (strcmp (tab[i].name, "lf") == 0)	    break;    if (tab[i].name == 0)    {	printf ("\nCannot find error log file entry in table!\n");	printf ("No error log file created.\n");	return (ERROR);    }    if (tab[i].used != YES) {	/* No error log file specified */	return (OK);    }    errlog = tab[i].nvalue ? tab[i].nvalue : tab[i].svalue;    if (stat(errlog, &sb) < 0)     {	if (errno == ENOENT)	{           /*            * Error Log file does not exist, make any necessary            * intermediate directories as needed  DJG#1	    */            done = 0;            j = 1;            while (!done) {	        while (errlog[j] != '/' && errlog[j] != '\0') j++;	        if (errlog[j] == '\0') break; /* Create file */	        strncpy (intermediate, errlog, j);	        intermediate[j++] = '\0';                if (stat(intermediate, &sb) < 0) {	            if (mkdir(intermediate, DIRMODE) == -1) {	                printf ("\nCannot make intermediate error log directory: %s\n", 			        intermediate);	                perror (intermediate);	                return (ERROR);                    }	            if (safechmod (intermediate, 00755) == -1)  /* incase root umask is not 022 */	            {		        printf ("\nCannot chmod %s to mode 0755\n", intermediate);		        perror (intermediate);		        return (ERROR);	            }                } else {	            /* this portion of the error log file path exists... */	            if ((sb.st_mode&S_IFMT) != S_IFDIR) {	                printf ("\nIntermediate error log directory: %s already exists\n",			        intermediate);		        printf ("But it is not a directory!\n");	                return (ERROR);	            }                }	    }            /* Create error log file */	    filedescriptor=open(errlog,O_CREAT,00644);	    if (filedescriptor == -1)	    {		printf("\nCannot create error log file %s\n",errlog);		perror (errlog);		return (ERROR);	    }/*    	    if (safechmod (errlog, 00644) == -1)    	    {		printf ("\nCannot chmod %s to mode 0644\n", errlog);		perror (errlog);	        close(filedescriptor);		return (ERROR);    	    }*/    	    if (safechown (errlog, passwd -> pw_uid, passwd -> pw_gid) == -1)    	    {	        printf ("\nCannot chown %s to (%o/%o)\n", errlog, passwd->pw_uid, passwd->pw_gid);		perror (errlog);	        close(filedescriptor);		return (ERROR);    	    }	    close(filedescriptor);    	    return(OK);	}    }    else    {	if ((sb.st_mode & S_IFMT) == S_IFREG)         {	    printf("\nWarning: regular file with same name as error log file %s already exists.\n",errlog);	    return (OK);	}	if ((sb.st_mode & S_IFMT) == S_IFLNK)	{	    printf("\nWarning: symbolic link with same name as error log file %s already exists.\n",errlog);	    printf("\nThis may result in printers sharing an error log file.\n");	    return (OK);	}    }    printf("\nInvalid name for error log file %s\n",errlog);    printf("File with same name as error log file %s already exists,\n",errlog);    printf("but it is not a regular file or a symbolic link.\n");    printf("Status information word S_IFMT = %d\n",sb.st_mode&S_IFMT);    return(ERROR);}/********************************  create spooling directory*******************************/MakeSpool (passwd)struct passwd  *passwd;		/* password file entry	 */{    char   *spool;		/* parameter value ptr	 */    int    i;			/* temp index	*/    int    j;                   /* spool index  */    struct stat sb;    int	   done;		/* loop flag    */    char   intermediate[MAXPATH];   /* to create intermediate directories */    for (i = 0; tab[i].name != 0; ++i)	if (strcmp (tab[i].name, "sd") == 0)	    break;    if (tab[i].name == 0)    {	printf ("\nCannot find spooler directory entry in table!\n");	printf ("No spooling directory created.\n");	return (ERROR);    }    if (tab[i].used != YES) {	/*	 * If spool directory is not specified in the printcap entry,	 * lpd will use the default directory	 */	printf ("Warning: queue will use default spool directory [/usr/spool/lpd]\n");	return (OK);    }    spool = tab[i].nvalue ? tab[i].nvalue : tab[i].svalue;    /*     * Try creating intermediate directories if they do not exist.     * If stat fails, and then cannot mkdir, so exit. DJG#1     */    done = 0;    j = 1;    while (!done) {	while (spool[j] != '/' && spool[j] != '\0') j++;	if (spool[j] == '\0') done++;	strncpy (intermediate, spool, j);	intermediate[j++] = '\0';        if (stat(intermediate, &sb) < 0) {	    if (mkdir(intermediate, DIRMODE) == -1) {	        printf ("\nCannot make spooling directory path: %s\n", 			intermediate);	        perror (intermediate);	        return (ERROR);            }	    if (safechmod (intermediate, 00755) == -1)  /* incase root umask is not 022 */	    {		printf ("\nCannot chmod %s to mode 0755\n", intermediate);		perror (intermediate);		return (ERROR);	    }        } else {	    /* this portion of the spooling directory exists... */	    if ((sb.st_mode&S_IFMT) != S_IFDIR) {	        printf ("\nSpooling directory path: %s already exists\n",			intermediate);		printf ("But it is not a directory!\n");	        return (ERROR);	    }        }    }    if (safechown (spool, passwd -> pw_uid, passwd -> pw_gid) == -1)    {	printf ("\nCannot chown %s to (%o/%o)\n", spool, passwd->pw_uid,	    passwd->pw_gid);	perror (spool);	return (ERROR);    }    return(OK);}/***************************  Switch the line off in*  the /etc/ttys file**************************/DisableGetty (){    char   *curval;		/* pointer to current value	 */    int    i;			/* temp index	*/    /*     * Change the /etc/ttys file entry     *   change mode from on to off. (disable logins).     */    for (i = 0; tab[i].name != 0; ++i) {	if (strcmp(tab[i].name, "lp") == 0) {	    curval=(tab[i].nvalue ? tab[i].nvalue : tab[i].svalue);	    if (strncmp(curval, "/dev/tty", 8) == 0) {		curval=(char *)index(curval, 't');		/* fixtty(ttyname,0=off - 1=on) */		fixtty(curval,0);	/* yes, it is "/dev/ttyxx" */		break;	    }        }    }    return(OK);}/*************************************************************  unlink spooler directory - removes all files in spool *  directory first - DJG#5*************************************************************/UnLinkSpooler(){    int    i;    char  *spooler;    char  unfile[MAXPATH];    DIR    *dptr, *opendir();    struct direct *dp, *readdir();    struct stat sb;    for (i = 0; tab[i].name != 0; ++i)	if (strcmp (tab[i].name, "sd") == 0)	    break;    if (tab[i].name == 0)	/* can't find 'sd' symbol */	return;		/* spool directory is just left laying around */    spooler = tab[i].nvalue ? tab[i].nvalue : tab[i].svalue;    if (stat(spooler, &sb) == 0) {        dptr = opendir (spooler);        for (dp = readdir (dptr); dp != NULL; dp = readdir(dptr)) {	    if ((strcmp (dp->d_name, ".") != 0) && (strcmp (dp->d_name, "..") != 0)) {	        (void) sprintf (unfile, "%s/%s", spooler, dp->d_name);	        if (safeunlink (unfile) != 0)	            printf ("Couldn't unlink spooler file %s\n", unfile);	    }        }        if (safermdir(spooler) < 0) {	    printf("couldn't unlink old spooler directory (%s)\n", spooler);        }        else {            printf("Removed spooling directory: %s\n", spooler);        }    }    else {  /* There is a problem */        if (errno == ENOENT) {            printf("\nSpooling directory %s does not exist\n",spooler);        }        else {            printf("\nCan not unlink spooling directory %s because of errno %d\n",                      spooler, errno);        }        perror (spooler);    }}/* * UnLinkSymFile - Removes the file associated with the specified symbol. * DJG#10 */intUnLinkSymFile (symbol)char	*symbol;{    int    i;    char *filename;    int yn;    for (i = 0; tab[i].name != 0; i++) {	if (strcmp (tab[i].name, symbol) == 0) {	    if (tab[i].used) {		filename = tab[i].nvalue ? tab[i].nvalue : tab[i].svalue;		printf("Do you want to delete '%s' file '%s' [n] ", symbol, filename);		yn = 'n';		if (YesNo (yn) == TRUE) {		    if (safeunlink(filename) != 0)		    printf ("Couldn't unlink :%s: file: %s\n", symbol, filename);		    else		    printf ("Deleted file: %s\n", filename);		}	    }	    break;	}    }}/************************** * badfile: print "cannot open * <filename>", and exit(1). **************************/badfile(s)char *s;{	printf("\nCannot open %s\n", s);	perror(s);	leave(ERROR);}/******************************************************************************* end of lprsetup.c******************************************************************************/

⌨️ 快捷键说明

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