* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement: ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * Neither the name of the University nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
*/
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)lpd.c 5.9 (Berkeley) 6/29/90";
+static char sccsid[] = "@(#)lpd.c 5.12 (Berkeley) 3/7/91";
#endif /* not lint */
/*
#include "pathnames.h"
int lflag; /* log requests flag */
+int from_remote; /* from remote socket */
-int reapchild();
-int mcleanup();
+void mcleanup(), reapchild();
main(argc, argv)
int argc;
char **argv;
{
- int f, funix, finet, options, defreadfds, fromlen;
+ int f, funix, finet, options = 0, defreadfds, fromlen;
struct sockaddr_un sun, fromunix;
struct sockaddr_in sin, frominet;
int omask, lfd;
signal(SIGTERM, mcleanup);
sun.sun_family = AF_UNIX;
strcpy(sun.sun_path, _PATH_SOCKETNAME);
- if (bind(funix, &sun, strlen(sun.sun_path) + 2) < 0) {
+ if (bind(funix,
+ (struct sockaddr *)&sun, strlen(sun.sun_path) + 2) < 0) {
syslog(LOG_ERR, "ubind: %m");
exit(1);
}
}
sin.sin_family = AF_INET;
sin.sin_port = sp->s_port;
- if (bind(finet, &sin, sizeof(sin), 0) < 0) {
+ if (bind(finet, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
syslog(LOG_ERR, "bind: %m");
mcleanup();
}
}
if (readfds & (1 << funix)) {
domain = AF_UNIX, fromlen = sizeof(fromunix);
- s = accept(funix, &fromunix, &fromlen);
+ s = accept(funix,
+ (struct sockaddr *)&fromunix, &fromlen);
} else if (readfds & (1 << finet)) {
domain = AF_INET, fromlen = sizeof(frominet);
- s = accept(finet, &frominet, &fromlen);
+ s = accept(finet,
+ (struct sockaddr *)&frominet, &fromlen);
}
if (s < 0) {
if (errno != EINTR)
(void) close(finet);
dup2(s, 1);
(void) close(s);
- if (domain == AF_INET)
+ if (domain == AF_INET) {
+ from_remote = 1;
chkhost(&frominet);
+ } else
+ from_remote = 0;
doit();
exit(0);
}
}
}
+void
reapchild()
{
union wait status;
- while (wait3(&status, WNOHANG, 0) > 0)
+ while (wait3((int *)&status, WNOHANG, 0) > 0)
;
}
+void
mcleanup()
{
if (lflag)
printjob();
break;
case '\2': /* receive files to be queued */
+ if (!from_remote) {
+ syslog(LOG_INFO, "illegal request (%d)", *cp);
+ exit(1);
+ }
printer = cp;
recvjob();
break;
displayq(cbuf[0] - '\3');
exit(0);
case '\5': /* remove a job from the queue */
+ if (!from_remote) {
+ syslog(LOG_INFO, "illegal request (%d)", *cp);
+ exit(1);
+ }
printer = cp;
while (*cp && *cp != ' ')
cp++;
f->sin_port = ntohs(f->sin_port);
if (f->sin_family != AF_INET || f->sin_port >= IPPORT_RESERVED)
fatal("Malformed from address");
- hp = gethostbyaddr(&f->sin_addr, sizeof(struct in_addr), f->sin_family);
+ hp = gethostbyaddr((char *)&f->sin_addr,
+ sizeof(struct in_addr), f->sin_family);
if (hp == 0)
fatal("Host name for your address (%s) unknown",
inet_ntoa(f->sin_addr));