* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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
* Auxillary functions to aid portability to other systems.
* These are 4.4BSD routines that are often not found on other systems.
* !!!USE THIS FILE ONLY IF YOU ARE NOT RUNNING 4.4BSD!!!
snprintf(char *str
, size_t n
, const char *fmt
, ...)
snprintf(str
, n
, fmt
, va_alist
)
ret
= vsprintf(str
, fmt
, ap
);
fatal("memory corrupted");
vsnprintf(str
, n
, fmt
, ap
)
ret
= vsprintf(str
, fmt
, ap
);
fatal("memory corrupted");
extern char *sys_errlist
[];
#define UPREFIX "Unknown error: "
static char ebuf
[40] = UPREFIX
; /* 64-bit number + slop */
register unsigned int errnum
;
errnum
= num
; /* convert to unsigned */
return(sys_errlist
[errnum
]);
/* Do this by hand, so we don't include stdio(3). */
*t
++ = "0123456789"[errnum
% 10];
for (p
= ebuf
+ sizeof(UPREFIX
) - 1;;) {
if (sp
= (char *) malloc(n
))
if (!noclose
&& (fd
= open(_PATH_DEVNULL
, O_RDWR
, 0)) != -1) {
(void)dup2(fd
, STDIN_FILENO
);
(void)dup2(fd
, STDOUT_FILENO
);
(void)dup2(fd
, STDERR_FILENO
);
f
= open("/dev/tty", O_RDWR
);
char buf
[2048], fmt_cpy
[1024];
/* substitute error message for %m */
register char ch
, *t1
, *t2
;
for (t1
= fmt_cpy
; ch
= *fmt
; ++fmt
)
if (ch
== '%' && fmt
[1] == 'm') {
for (t2
= strerror(errno
);
vsprintf(buf
, fmt_cpy
, ap
);
* Returns 0 if ok, -1 if not ok.
__ivaliduser(hostf
, raddr
, luser
, ruser
)
const char *luser
, *ruser
;
char buf
[MAXHOSTNAMELEN
+ 128]; /* host + login */
while (fgets(buf
, sizeof(buf
), hostf
)) {
/* Skip lines that are too long. */
if (strchr(p
, '\n') == NULL
) {
while ((ch
= getc(hostf
)) != '\n' && ch
!= EOF
);
while (*p
!= '\n' && *p
!= ' ' && *p
!= '\t' && *p
!= '\0') {
*p
= isupper(*p
) ? tolower(*p
) : *p
;
if (*p
== ' ' || *p
== '\t') {
while (*p
== ' ' || *p
== '\t')
while (*p
!= '\n' && *p
!= ' ' &&
*p
!= '\t' && *p
!= '\0')
if (__icheckhost(raddr
, buf
) &&
strcmp(ruser
, *user
? user
: luser
) == 0) {
* Returns "true" if match, 0 if no match.
__icheckhost(raddr
, lhost
)
register struct hostent
*hp
;
/* Try for raw ip address first. */
if (isdigit(*lhost
) && (laddr
.s_addr
= inet_addr(lhost
)) != INADDR_NONE
)
return (raddr
.s_addr
== laddr
.s_addr
);
/* Better be a hostname. */
if ((hp
= gethostbyname(lhost
)) == NULL
)
/* Spin through ip addresses. */
for (pp
= hp
->h_addr_list
; *pp
; ++pp
)
if (!bcmp(&raddr
, *pp
, sizeof(struct in_addr
)))
#endif /* NO_IVALIDUSER */
* Check to see if there is enough space on the disk for size bytes.
#define SBOFF ((off_t)(BBSIZE))
if (stat(".", &stb
) < 0) {
syslog(LOG_ERR
, "%s: %m", "statfs(\".\")");
ddev
= find_dev(stb
.st_dev
, S_IFBLK
);
if ((dfd
= open(ddev
, O_RDONLY
)) < 0) {
syslog(LOG_WARNING
, "%s: %s: %m", printer
, ddev
);
if (lseek(dfd
, (off_t
)(SBOFF
), 0) < 0)
if (read(dfd
, (char *)&fs
, sizeof fs
) != sizeof fs
|| fs
.fs_magic
!= FS_MAGIC
) {
syslog(LOG_ERR
, "Can't calculate free space on spool device");
spacefree
= freespace(&fs
, fs
.fs_minfree
) * fs
.fs_fsize
/ 512;
size
= (size
+ 511) / 512;
if (minfree
+ size
> spacefree
)
char devname
[MAXNAMLEN
+6];
strcpy(devname
, "/dev/dsk");
if ((dfd
= opendir(devname
)) == NULL
) {
while ((dir
= readdir(dfd
))) {
strcpy(devname
+ n
, dir
->d_name
);
if ((stb
.st_mode
& S_IFMT
) != type
)
if (dev
== stb
.st_rdev
) {
dp
= (char *)malloc(strlen(devname
)+1);
frecverr("cannot find device %d, %d", major(dev
), minor(dev
));