Skip to content

Commit

Permalink
updated installer.c, queue-fix.c
Browse files Browse the repository at this point in the history
1. installer.c: added 'z' option to create files with fized number of zeros.
2. queue-fix.c: added option -S to specify tcpto buffer size
2. queue-fix.c: added option -t to create trash directory for qmail-rm
  • Loading branch information
mbhangui committed Feb 11, 2024
1 parent 0b4c9f3 commit 07d95a3
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 163 deletions.
2 changes: 2 additions & 0 deletions daemontools-x/doc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Release 1.1.3-1.1 Start 27/04/2023 End 01/01/2024
- 10/02/2024
16. installer.c: removed unused options and fixed check option fixing
permissions
- 10/02/2024
11. installer.c: added 'z' option to create files with fized number of zeros.

* Sun Apr 23 2023 17:05:00 +0000 Manvendra Bhangui <[email protected]> 1.1.2-1.1%{?dist}
Release 1.1.2-1.1 Start 20/02/2023 End 23/04/2023
Expand Down
37 changes: 24 additions & 13 deletions daemontools-x/installer.9
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.TH installer 1

.SH NAME
installer \- create directories, copy files, create FIFO, create devices
installer \- create directories, create/copy files, named pipes and devices

instcheck \- check installed files for existence, owner, group, permissions

Expand All @@ -13,16 +13,16 @@ instcheck \- check installed files for existence, owner, group, permissions

.SH DESCRIPTION
\fBinstaller\fR program create directories, install files from source
directories and create files, symbolic links, named pipes and devices files
in directory \fIdest\fR of your choice. \fBinstaller\fR takes input from
descriptor 0. It expects the data on descriptor 0 to be of the following
form.
directories, create files with zeros, symbolic links, named pipes and
devices files in directory \fIdest\fR of your choice. \fBinstaller\fR takes
input from descriptor 0. It expects the data on descriptor 0 to be of the
following form.

.EX
\fItype\fR:\fIowner\fR:\fIgroup\fR:\fImode\fR:\fItarget\fR:\fIsource\fR:
.EE

Here \fItype\fR is either of d, l, f, p, c as following
Here \fItype\fR is either of d, l, f, z, p, c as following
.TP 2
d
= directory
Expand All @@ -33,6 +33,9 @@ l
f
= file
.TP
z
= file with fixed number of zeroes
.TP
p
= named pipe
.TP
Expand All @@ -45,29 +48,37 @@ c
group ID) of the \fItarget\fR, \fImode\fR is the file mode bits of the
\fItarget\fR. \fItarget\fR is a relative or absolute path of the filename
in \fIdest\fR. \fIsource\fR is a relative or absolute path of the source
filename. The lines expected by \fBinstaller\fr has to be any of the
following forms given below. Invalid data is silently ignored.
filename. \fItarget\fR can be a directory, file, symbolic link, fifo or a
device The lines expected by \fBinstaller\fr has to be any of the following
forms given below. Invalid data is silently ignored.

.EX
Directory
\fBd\fR:\fIowner\fR:\fIgroup\fR:\fImode\fR:\fIdir\fR::
\fBd\fR:\fIowner\fR:\fIgroup\fR:\fImode\fR:\fItarget_dir\fR::
Soft link
\fBl\fR:\fIowner\fR:\fIgroup\fR:\fImode\fR:\fIlink\fR::\fIsource\fR:
\fBl\fR:\fIowner\fR:\fIgroup\fR:\fImode\fR:\fItarget_link\fR::\fIsource\fR:
File
\fBf\fR:\fIowner\fR:\fIgroup\fR:\fImode\fR:\fIfilename\fR:\fIsource\fR:
\fBf\fR:\fIowner\fR:\fIgroup\fR:\fImode\fR:\fItarget_file\fR:\fIsource\fR:
File with zeros
\fBz\fR:\fIowner\fR:\fIgroup\fR:\fImode\fR:\fItarget_file\fR:\fIsize\fR:
Named Pipes
\fBp\fR:\fIowner\fR:\fIgroup\fR:\fImode\fR:\fIfifo\fR::
\fBp\fR:\fIowner\fR:\fIgroup\fR:\fImode\fR:\fItarget_fifo\fR::
Device files
\fBc\fR:\fIowner\fR:\fIgroup\fR:\fImode\fR:target:devnum:
\fBc\fR:\fIowner\fR:\fIgroup\fR:\fImode\fR:target_device:devnum:
.EE

\fBinstaller\fR silently ignores comments, blank lines or any line starting
with any white space character.

\fBinstaller\fR is not meant to be executed by end users. It is meant to be
used to be used in Makefile and build scripts to install binaries, links,
named pipes, devices and files with zeros to a destination directory.

\fBinstcheck\fR checks the existence of files and ower, group, mode of
installed files. It needs the same input as \fBinstcheck\fR on descriptor
0. \fBinstcheck\fR is just a frontend to \fBinstaller\fR, except that it
Expand Down
144 changes: 98 additions & 46 deletions daemontools-x/installer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: installer.c,v 1.24 2024-02-11 19:52:08+05:30 Cprogrammer Exp mbhangui $
* $Id: installer.c,v 1.25 2024-02-11 23:20:17+05:30 Cprogrammer Exp mbhangui $
* taken from ezmlm-0.54
*/
#include <sys/types.h>
Expand All @@ -21,6 +21,7 @@
#include <scan.h>
#include <fmt.h>
#include <noreturn.h>
#include <alloc.h>
#ifndef NETQMAIL
#include <qprintf.h>
#endif
Expand Down Expand Up @@ -63,7 +64,7 @@ get_octal(mode_t mode)
}

void
print_info(const char *str, char *source, char *dest, mode_t mode, uid_t uid, gid_t gid)
print_info(const char *str, char *source, char *dest, mode_t mode, uid_t uid, gid_t gid, unsigned long size)
{
struct passwd *pw;
struct group *gr;
Expand Down Expand Up @@ -115,6 +116,16 @@ print_info(const char *str, char *source, char *dest, mode_t mode, uid_t uid, gi
subprintf(subfdout, " -mode %s", get_octal(mode));
if (source)
subprintf(subfdout, " -source %s", source);
#endif
#ifdef NETQMAIL
if (size != -1) {
substdio_puts(subfdout, " -size ");
strnum[fmt_ulong(strnum, size)] = 0;
substdio_puts(subfdout, strnum);
}
#else
if (size != -1)
subprintf(subfdout, " -size %lu", size);
#endif
substdio_puts(subfdout, "\n");
substdio_flush(subfdout);
Expand Down Expand Up @@ -272,14 +283,15 @@ set_perms(char *dest, char *uidstr, char *gidstr, char *modestr,
* f:owner:group:mode:target_file:name:
* p:owner:group:mode:target_fifo::
* c:owner:group:mode:target_device:devnum:
* z:owner:group:mode:target_file:size:
*/
void
doit(stralloc *line, int uninstall, int check)
{
char *x;
char *type, *uidstr, *gidstr, *modestr, *mid, *name;
char *type, *uidstr, *gidstr, *modestr, *mid, *name, *zerobuf;
int fdin, fdout, opt;
unsigned long m;
unsigned long m, size;
unsigned int xlen, i;
uid_t uid;
gid_t gid;
Expand Down Expand Up @@ -340,18 +352,27 @@ doit(stralloc *line, int uninstall, int check)
x += i;
xlen -= i;

mid = x;
if (*type == 'z') {
name = x;
mid = NULL;
} else {
name = NULL;
mid = x;
}
i = byte_chr(x, xlen, ':');
if (i == xlen)
return;
x[i++] = 0;
x += i;
xlen -= i;

name = x;
if (*type == 'f')
name = x;
i = byte_chr(x, xlen, ':');
if (i == xlen)
return;
if (*type == 'z')
scan_ulong(x, &size);
x[i++] = 0;
x += i;
xlen -= i;
Expand All @@ -364,9 +385,13 @@ doit(stralloc *line, int uninstall, int check)
nomem();
if (!stralloc_cats(&target, mid))
nomem();
if (*type != 'l' && name && !stralloc_cats(&target, name))
nomem();
} else
if (*type == 'z') {
if (!stralloc_cats(&target, name))
nomem();
}
if (*type != 'l' && name && !stralloc_cats(&target, name))
nomem();
if (!stralloc_0(&target))
nomem();
target.len--;
Expand All @@ -379,7 +404,7 @@ doit(stralloc *line, int uninstall, int check)
switch (*type)
{
case 'l':
print_info("unlink", 0, target.s, -1, -1, -1);
print_info("unlink", 0, target.s, -1, -1, -1, -1);
if (lstat(target.s, &st) == -1) {
if (errno == error_noent)
return;
Expand All @@ -391,15 +416,16 @@ doit(stralloc *line, int uninstall, int check)
strerr_die4sys(111, FATAL, "unable to unlink ", target.s, ": ");
break;
case 'd':
print_info("rmdir", 0, target.s, -1, -1, -1);
print_info("rmdir", 0, target.s, -1, -1, -1, -1);
if (rmdir(target.s) == -1) {
if (errno == error_noent)
return;
strerr_warn4(WARN, "rmdir ", target.s, ": ", &strerr_sys);
}
break;
case 'z':
case 'f':
print_info("delete", 0, target.s, -1, -1, -1);
print_info("delete", 0, target.s, -1, -1, -1, -1);
if (lstat(target.s, &st) == -1) {
if (errno == error_noent)
return;
Expand Down Expand Up @@ -441,7 +467,7 @@ doit(stralloc *line, int uninstall, int check)
{
case 'c':
if (!check || access(target.s, F_OK)) {
print_info("mknod", 0, target.s, mode == -1 ? 0644 : mode, uid, gid);
print_info("mknod", 0, target.s, mode == -1 ? 0644 : mode, uid, gid, -1);
scan_ulong(name, (unsigned long *) &dev);
if (mknod(target.s, mode == -1 ? 0644 : mode, dev) == -1) {
if (errno != error_exist)
Expand All @@ -453,7 +479,7 @@ doit(stralloc *line, int uninstall, int check)
break;
case 'p':
if (!check || access(target.s, F_OK)) {
print_info("mkfifo", 0, target.s, mode == -1 ? 0644 : mode, uid, gid);
print_info("mkfifo", 0, target.s, mode == -1 ? 0644 : mode, uid, gid, -1);
if (fifo_make(target.s, mode == -1 ? 0644 : mode) == -1) {
if (errno != error_exist)
strerr_die4sys(111, FATAL, "fifo_make: ", target.s, ": ");
Expand All @@ -464,14 +490,14 @@ doit(stralloc *line, int uninstall, int check)
break;
case 'l':/*- here name is target */
if (!check || access(name, F_OK)) {
print_info("make link", name, target.s, -1, -1, -1);
print_info("make link", name, target.s, -1, -1, -1, -1);
if (symlink(name, target.s) == -1 && errno != error_exist)
strerr_die6sys(111, FATAL, "unable to symlink ", target.s, " to ", name, ": ");
}
break;
case 'd':
if (!check || access(target.s, F_OK)) {
print_info("mkdir", 0, target.s, (my_uid || mode == -1) ? 0755 : mode, uid, gid);
print_info("mkdir", 0, target.s, (my_uid || mode == -1) ? 0755 : mode, uid, gid, -1);
if (myr_mkdir(target.s, (my_uid || mode == -1) ? 0755 : mode) == -1) {
if (errno != error_exist)
strerr_die4sys(111, FATAL, "unable to mkdir ", target.s, ": ");
Expand All @@ -481,47 +507,61 @@ doit(stralloc *line, int uninstall, int check)
set_perms(target.s, uidstr, gidstr, modestr, uid, gid, mode, check);
break;

case 'z':
case 'f':
if (!check) {
if (access(name, F_OK)) {
if (errno == error_noent) {
if (!missing_ok)
strerr_die3sys(111, FATAL, target.s, ": ");
print_info("skipping file", name, target.s, mode == -1 ? 0644 : mode, uid, gid);
return;
} else
strerr_die3sys(111, FATAL, name, ": ");
}
if (mode == -1) {
if (lstat(name, &st) == -1)
strerr_die4sys(111, FATAL, "lstat: ", name, ": ");
mode = st.st_mode;
if (*type == 'f') {
if (access(name, F_OK)) {
if (errno == error_noent) {
if (!missing_ok)
strerr_die3sys(111, FATAL, target.s, ": ");
print_info("skipping file", name, target.s, mode == -1 ? 0644 : mode, uid, gid, -1);
return;
} else
strerr_die3sys(111, FATAL, name, ": ");
}
if (mode == -1) {
if (lstat(name, &st) == -1)
strerr_die4sys(111, FATAL, "lstat: ", name, ": ");
mode = st.st_mode;
}
}
print_info("install file", name, target.s, mode == -1 ? 0644 : mode, uid, gid);
if ((fdin = open_read(name)) == -1) {
print_info("install file", *type == 'f' ? name : "/dev/zero", target.s, mode == -1 ? 0644 : mode, uid, gid, size);
if ((fdin = open_read(*type == 'z' ? "/dev/zero" : name)) == -1) {
if (opt)
return;
else
strerr_die4sys(111, FATAL, "unable to read ", name, ": ");
}
if (!(zerobuf = (char *) alloc(sizeof(char) * size)))
nomem();
substdio_fdbuf(&ssin, read, fdin, inbuf, sizeof (inbuf));
if ((fdout = open_trunc(target.s)) == -1)
strerr_die4sys(111, FATAL, "unable to write ", target.s, ": ");
substdio_fdbuf(&ssout, write, fdout, outbuf, sizeof (outbuf));

switch (substdio_copy(&ssout, &ssin))
{
case -2:
strerr_die4sys(111, FATAL, "unable to read ", name, ": ");
case -3:
strerr_die4sys(111, FATAL, "unable to write ", target.s, ": ");
if (*type == 'f') {
switch (substdio_copy(&ssout, &ssin))
{
case -2:
strerr_die4sys(111, FATAL, "unable to read ", name, ": ");
case -3:
strerr_die4sys(111, FATAL, "unable to write ", target.s, ": ");
}
} else
if (*type == 'z') {
if (substdio_get(&ssin, zerobuf, size) == -1)
strerr_die2sys(111, FATAL, "unable to read /dev/zero: ");
if (substdio_put(&ssout, zerobuf, size) == -1)
strerr_die4sys(111, FATAL, "unable to write ", target.s, ": ");
}
close(fdin);
if (substdio_flush(&ssout) == -1)
strerr_die4sys(111, FATAL, "unable to write ", target.s, ": ");
if (fsync(fdout) == -1)
strerr_die4sys(111, FATAL, "unable to write ", target.s, ": ");
close(fdout);
alloc_free(zerobuf);
if (my_uid) {
#ifdef NETQMAIL
substdio_puts(subfdout, "\tchmod ");
Expand All @@ -535,16 +575,25 @@ doit(stralloc *line, int uninstall, int check)
if (qchmod(target.s, mode == -1 ? 0644 : mode) == -1)
strerr_die4sys(111, FATAL, "unable to chmod ", target.s, ": ");
}
} else
if (access(target.s, F_OK)) {
if (errno == error_noent) {
if (missing_ok)
strerr_warn3(WARN, target.s, " is missing", 0);
else
} else {
if (access(target.s, F_OK)) {
if (errno == error_noent) {
if (missing_ok)
strerr_warn3(WARN, target.s, " is missing", 0);
else
strerr_die3sys(111, FATAL, target.s, ": ");
return;
} else
strerr_die3sys(111, FATAL, target.s, ": ");
return;
} else
strerr_die3sys(111, FATAL, target.s, ": ");
}
if (*type == 'z') {
if (lstat(target.s, &st) == -1)
strerr_die4sys(111, FATAL, "lstat: ", target.s, ": ");
if (size != st.st_size) {
strnum[fmt_ulong(strnum, size)] = 0;
strerr_warn5(WARN, target.s, " is not the right size (", strnum, ").", 0);
}
}
}
if (uid != -1 || gid != -1 || mode != -1)
set_perms(target.s, uidstr, gidstr, modestr, uid, gid, mode, check);
Expand Down Expand Up @@ -620,14 +669,17 @@ main(int argc, char **argv)
void
getversion_installer_c()
{
static const char *x = "$Id: installer.c,v 1.24 2024-02-11 19:52:08+05:30 Cprogrammer Exp mbhangui $";
static const char *x = "$Id: installer.c,v 1.25 2024-02-11 23:20:17+05:30 Cprogrammer Exp mbhangui $";

if (x)
x++;
}

/*
* $Log: installer.c,v $
* Revision 1.25 2024-02-11 23:20:17+05:30 Cprogrammer
* added 'z' option to create files with fixed number of zeros
*
* Revision 1.24 2024-02-11 19:52:08+05:30 Cprogrammer
* updated for netqmail, notqmail
*
Expand Down
Loading

0 comments on commit 07d95a3

Please sign in to comment.