/* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_misc.c 1.5 92/01/24 19:59:13 SMI */
/*
**=====================================================================
** Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
** @(#)pcnfsd_misc.c 1.5 1/24/92
**=====================================================================
*/
/*
**=====================================================================
** I N C L U D E F I L E S E C T I O N *
** *
** If your port requires different include files, add a suitable *
** #define in the customization section, and make the inclusion or *
** exclusion of the files conditional on this. *
**=====================================================================
*/
/*
**=====================================================================
** C O D E S E C T I O N *
**=====================================================================
*/
/*
**---------------------------------------------------------------------
** Support procedures
**---------------------------------------------------------------------
*/
#ifdef SHADOW_SUPPORT
struct spwd *sp;
int shadowfile;
#endif
#ifdef SHADOW_SUPPORT
/*
**--------------------------------------------------------------
** Check the existence of SHADOW. If it is there, then we are
** running a two-password-file system.
**--------------------------------------------------------------
*/
if (access(SHADOW, 0))
shadowfile = 0; /* SHADOW is not there */
else
shadowfile = 1;
setpwent();
if (shadowfile)
(void) setspent(); /* Setting the shadow password file */
if ((p = getpwnam(usrnam)) == NULL ||
(shadowfile && (sp = getspnam(usrnam)) == NULL))
return (NULL);
#else
p = getpwnam(usrnam);
if (p == NULL)
return (NULL);
pswd = p->pw_passwd;
#endif
#ifdef ISC_2_0
/* *----------------------------------------------------------- * We
* may have an 'x' in which case look in /etc/shadow ..
* *----------------------------------------------------------- */
if (((strlen(pswd)) == 1) && pswd[0] == 'x') {
struct spwd *shadow = getspnam(usrnam);
setusershell();
while (ushell = getusershell()) {
if (!strcmp(ushell, localp.pw_shell)) {
ok = 1;
break;
}
}
endusershell();
if (!ok)
return (NULL);
#else
/*
* the best we can do is to ensure that the shell ends in "sh"
*/
ushell = localp.pw_shell;
if (strlen(ushell) < 2)
return (NULL);
ushell += strlen(ushell) - 2;
if (strcmp(ushell, "sh"))
return (NULL);
#endif
return (&localp);
}
/*
**---------------------------------------------------------------------
** Print support procedures
**---------------------------------------------------------------------
*/
char *
mapfont(char f, char i, char b)
{
static char fontname[64];
fontname[0] = 0; /* clear it out */
switch (f) {
case 'c':
(void) strlcpy(fontname, "Courier", sizeof(fontname));
break;
case 'h':
(void) strlcpy(fontname, "Helvetica", sizeof(fontname));
break;
case 't':
(void) strlcpy(fontname, "Times", sizeof(fontname));
break;
default:
(void) strlcpy(fontname, "Times-Roman", sizeof(fontname));
goto finis;
}
if (i != 'o' && b != 'b') { /* no bold or oblique */
if (f == 't') /* special case Times */
(void) strlcat(fontname, "-Roman", sizeof(fontname));
goto finis;
}
(void) strlcat(fontname, "-", sizeof(fontname));
if (b == 'b')
(void) strlcat(fontname, "Bold", sizeof(fontname));
if (i == 'o') /* o-blique */
(void) strlcat(fontname, f == 't' ? "Italic" : "Oblique",
sizeof(fontname));
finis: return (&fontname[0]);
}
/*
* run_ps630 performs the Diablo 630 emulation filtering process. ps630
* was broken in certain Sun releases: it would not accept point size or
* font changes. If your version is fixed, undefine the symbol
* PS630_IS_BROKEN and rebuild pc-nfsd.
*/
/* #define PS630_IS_BROKEN 1 */
#ifndef PS630_IS_BROKEN
(void) snprintf(commbuf, sizeof(commbuf), "ps630 -s %c%c -p %s -f ",
opts[2], opts[3], temp_file);
(void) strlcat(commbuf, mapfont(opts[4], opts[5], opts[6]),
sizeof(commbuf));
(void) strlcat(commbuf, " -F ", sizeof(commbuf));
(void) strlcat(commbuf, mapfont(opts[7], opts[8], opts[9]),
sizeof(commbuf));
(void) strlcat(commbuf, " ", sizeof(commbuf));
(void) strlcat(commbuf, f, sizeof(commbuf));
#else /* PS630_IS_BROKEN */
/*
* The pitch and font features of ps630 appear to be broken at
* this time.
*/
(void) snprintf(commbuf, sizeof(commbuf), "ps630 -p %s %s",
temp_file, f);
#endif /* PS630_IS_BROKEN */
if ((i = system(commbuf)) != 0) {
/*
* Under (un)certain conditions, ps630 may return -1 even
* if it worked. Hence the commenting out of this error
* report.
*/
/* (void)fprintf(stderr, "\n\nrun_ps630 rc = %d\n", i) */ ;
/* exit(1); */
}
if (rename(temp_file, f)) {
perror("run_ps630: rename");
exit(1);
}
return;
}
/*
**---------------------------------------------------------------------
** WTMP update support
**---------------------------------------------------------------------
*/
/*
* restore old signal handling
*/
sigaction(SIGALRM, &old_action, NULL);
}
FILE *
su_popen(char *user, char *cmd, int maxtime)
{
int p[2];
int parent_fd, child_fd, pid;
struct passwd *pw;
if (strcmp(cached_user, user)) {
pw = getpwnam(user);
if (!pw)
pw = getpwnam("nobody");
if (pw) {
cached_uid = pw->pw_uid;
cached_gid = pw->pw_gid;
strlcpy(cached_user, user, sizeof(cached_user));
} else {
cached_uid = (uid_t) (-2);
cached_gid = (gid_t) (-2);
cached_user[0] = '\0';
}
}
if (pipe(p) < 0) {
msg_out("rpc.pcnfsd: unable to create pipe in su_popen");
return (NULL);
}
parent_fd = p[READER_FD];
child_fd = p[WRITER_FD];
if ((pid = fork()) == 0) {
int i;
for (i = 0; i < 10; i++)
if (i != child_fd)
(void) close(i);
if (child_fd != 1) {
(void) dup2(child_fd, 1);
(void) close(child_fd);
}
dup2(1, 2); /* let's get stderr as well */
/*
** The following routine reads a file "/etc/pcnfsd.conf" if present,
** and uses it to replace certain builtin elements, like the
** name of the print spool directory. The configuration file
** Is the usual kind: Comments begin with '#', blank lines are ignored,
** and valid lines are of the form
**
** <keyword><whitespace><value>
**
** The following keywords are recognized:
**
** spooldir
** printer name alias-for command
** wtmp yes|no
*/
static void
config_from_file(void)
{
FILE *fd;
char buff[1024];
char *cp;
char *kw;
char *val;
char *arg1;
char *arg2;
if ((fd = fopen("/etc/pcnfsd.conf", "r")) == NULL)
return;
while (fgets(buff, 1024, fd)) {
cp = strchr(buff, '\n');
*cp = '\0';
cp = strchr(buff, '#');
if (cp)
*cp = '\0';
kw = strtok(buff, " \t");
if (kw == NULL)
continue;
val = strtok(NULL, " \t");
if (val == NULL)
continue;
if (!strcasecmp(kw, "spooldir")) {
strlcpy(sp_name, val, sizeof(sp_name));
continue;
}
#ifdef WTMP
if (!strcasecmp(kw, "wtmp")) {
/* assume default is YES, just look for negatives */
if (!strcasecmp(val, "no") ||
!strcasecmp(val, "off") ||
!strcasecmp(val, "disable") ||
!strcmp(val, "0"))
wtmp_enabled = 0;
continue;
}
#endif
if (!strcasecmp(kw, "printer")) {
arg1 = strtok(NULL, " \t");
arg2 = strtok(NULL, "");
(void) add_printer_alias(val, arg1, arg2);
continue;
}
/*
** Add new cases here
*/
}
fclose(fd);
}
/*
** hack for main() - call config_from_file() then the real main
** in the rpcgen output, which is hacked by CPPFLAGS to be "mymain"
*/
#undef main