static char *sccsid
= "@(#)docmd.c 4.1 (Berkeley) 83/09/07";
FILE *lfp
; /* log file for recording files updated */
* Routines to process commands.
docmd(files
, hosts
, cmds
)
struct block
*files
, *hosts
, *cmds
;
register struct block
*h
, *f
, *c
;
register char *cp
, **cpp
;
fatal("no files to be updated\n");
fatal("empty list of hosts to be updated\n");
for (h
= hosts
; h
!= NULL
; h
= h
->b_next
) {
if ((lfp
= fopen(tmpfile
, "w")) == NULL
) {
fatal("cannot open %s\n", tmpfile
);
if (!makeconn(h
->b_name
))
for (f
= files
; f
!= NULL
; f
= f
->b_next
) {
for (cpp
= filev
; *cpp
; cpp
++)
if (!strcmp(f
->b_name
, *cpp
))
for (c
= cmds
; c
!= NULL
; c
= c
->b_next
)
if (c
->b_type
== INSTALL
) {
install(f
->b_name
, c
->b_name
, 0);
} else if (c
->b_type
== VERIFY
) {
install(f
->b_name
, c
->b_name
, 1);
install(f
->b_name
, f
->b_name
, 0);
for (c
= cmds
; c
!= NULL
; c
= c
->b_next
)
notify(h
->b_name
, c
->b_args
);
* Create a connection to the rdist server on the machine rhost.
(void) sprintf(buf
, "/usr/local/rdist -Server%s%s%s%s%s",
vflag
? " -v" : "", qflag
? " -q" : "", nflag
? " -n" : "",
yflag
? " -y" : "", debug
? " -d" : "");
ruser
= rindex(rhost
, '.');
printf("makeconn(%s)\n", rhost
);
printf("luser = %s, ruser = %s\n", user
, ruser
);
printf("buf = %s\n", buf
);
rem
= rcmd(&rhost
, IPPORT_CMDSERVER
, user
, ruser
, buf
, 0);
* Update the file(s) if they are different.
install(src
, dest
, verify
)
printf("%s %s %s\n", verify
? "verify" : "install", src
, dest
);
* Pass the destination file/directory name to remote.
(void) sprintf(buf
, "T%s\n", dest
);
(void) write(rem
, buf
, strlen(buf
));
* Notify the list of people the changes that were made.
register struct block
*to
;
printf("notify @%s ", host
);
if ((fd
= open(tmpfile
, 0)) < 0) {
error("%s: %s\n", tmpfile
, sys_errlist
[errno
]);
* Create a pipe to mailling program.
pf
= popen(MAILCMD
, "w");
fatal("notify: \"%s\" failed\n", MAILCMD
);
* Output the proper header information.
fprintf(pf
, "From: rdist (Remote distribution program)\n");
fprintf(pf
, " %s@%s", to
->b_name
, host
);
fprintf(pf
, "Subject: files updated by rdist\n");
while ((len
= read(fd
, buf
, BUFSIZ
)) > 0)
(void) fwrite(buf
, 1, len
, pf
);
struct block
*except
; /* list of files to exclude */
* Return true if name is in list.
register struct block
*b
, *c
;
for (c
= except
; c
!= NULL
; c
= c
->b_next
) {
for (b
= c
->b_args
; b
!= NULL
; b
= b
->b_next
)
if (!strcmp(file
, b
->b_name
))
register char *cp
= name
;
if (!isalpha(c
) && !isdigit(c
) && c
!= '_' && c
!= '-')
error("invalid user name %s\n", name
);