jaakov%wisdom.bitnet@WISCVM.ARPA (07/03/85)
From: Jacob Levy <jaakov%wisdom.bitnet@WISCVM.ARPA> Did you ever want to get that file you forgot to take with you when you went to visit that other university? What a shame you forgot! Now you will not be able to get it fast. But with 'cmdbymail', you can just send yourself a command file to mail the missing file to you at the place you are currently at, and the mail system will take care of it. How is it done? Unpack this shell archive, by feeding everything below the dashed line to 'sh', and read the man page included. #--- cut here --- cut here --- cut here --- cut here --- cut here # # This is a shar archive. It contains the following files - # # makefile cmdbymail.c cmdbymail.1 # echo extracting makefile cat << 'FoO ThE BaR' > makefile CFILES = cmdbymail.c OFILES = cmdbymail.o CFLAGS = -O all: cmdbymail cmdbymail.nr cmdbymail: $(OFILES) cc -o $(OFILES) cmdbymail cmdbymail.nr: cmdbymail.1 nroff -Tla12 -man cmdbymail.1 > cmdbymail.nr FoO ThE BaR echo extracting cmdbymail.c cat << 'FoO ThE BaR' > cmdbymail.c #include <stdio.h> char msgbuffer[1024000]; main(ac, av) char **av; { char *trusted_user, *mail_file, *subject; if (ac == 1) { printf("doing settup\n"); setup(av[0]); exit(0); } trusted_user = av[1]; subject = av[2]; mail_file = av[3]; collect_message(); if (command_message(trusted_user,subject)) do_command(); save_message(mail_file); } setup(pname) { FILE *fd; register char *run; char ubuf[256], sbuf[256], mbuf[256]; char fbuf[256]; sprintf(fbuf, "%s/.forward", getenv("HOME")); if ((fd = fopen(fbuf, "w")) == NULL) { printf("cannot open .forward file for writing\n"); exit(0); } printf("enter full mail address of trusted user: "); run = ubuf; for (*run = getchar(); *run != '\n'; *run = getchar()) run++; *run = 0; printf("enter subject line to identify command files: "); run = sbuf; for (*run = getchar(); *run != '\n'; *run = getchar()) run++; *run = 0; printf("enter name of mail file to save messages: "); run = mbuf; for (*run = getchar(); *run != '\n'; *run = getchar()) run++; *run = 0; fprintf(fd, "| %s %s \"%s\" %s\n", pname, ubuf, sbuf, mbuf); fclose(fd); printf("setup done\n"); } collect_message() { register char *run = msgbuffer; for (*run = getchar(); *run != EOF; *run = getchar()) run++; *run = 0; } save_message(mail_file) char *mail_file; { FILE *fd = fopen(mail_file, "a"); if (fd == NULL) exit(0); /* Lose... */ fprintf(fd, "%s", msgbuffer); fclose(fd); } char * find_body() { register char *run = msgbuffer; for (; !(*run == '\n' && *(run + 1) == '\n'); run++); return run + 2; } do_command() { register char *run = find_body(); FILE *fd; char *tmp = "/tmp/cmdfXXXXXX"; char cmdbuf[256]; if ((fd = fopen(tmp = (char *)mktemp(tmp), "w")) == NULL) return; fprintf(fd, "%s", run); fclose(fd); sprintf(cmdbuf, "sh %s", tmp); system(cmdbuf); unlink(tmp); } char * getline(l, here) char *l, *here; { register char *run = l; for (; *here && *here != '\n'; *run++ = *here++); here++; *run = 0; if (run == l) return 0; return here; } command_message(user, subject) char *user, *subject; { char ubuf[256], sbuf[256]; char l[256]; char *run = msgbuffer; char *lrun = l; sprintf(ubuf, "From %s", user); sprintf(sbuf, "Subject: %s", subject); run = getline(lrun, msgbuffer); if (strncmp(l, ubuf, strlen(ubuf)) != 0) return 0; for (; (run = getline(lrun, run)) != 0; ) if (strcmp(l, sbuf) == 0) return 1; return 0; } FoO ThE BaR echo extracting cmdbymail.1 cat << 'FoO ThE BaR' > cmdbymail.1 ..TH CMDBYMAIL 1N "2 July 1985" ..UC 4 ..SH NAME cmdbymail \- execute commands by mail ..SH SYNOPSYS ..B cmdbymail ..br ..SH DESCRIPTION ..I Cmdbymail allows a user to execute commands by mail when the user is away. This is intended to be used as an inexpensive dummy server, or as a way for a user to execute commands on systems where he has accounts but cannot log in from his present location. For example, an ARPA user who has an account on a machine on the UUCP network can execute commands on the UUCP machine even though he cannot log in on it directly. ..PP ..I Cmdbymail must be run once by the user before he leaves the system on which the commands should be executed. When it is run by the user, it prompts for three parameters. It asks for a full path to the user that will be allowed to execute commands via mail. ..I Cmdbymail also asks for a subject line to identify messages containing commands to execute. Lastly, it asks for a file to save all mail in. ..PP ..I Cmdbymail creates a .forward file in the user's home directory which will execute ..I cmdbymail for each mail message received. If the message is sent by the trusted user who is allowed to execute remote commands, and the subject line identifies this as a command message, the body of the message will be executed as a shell procedure, with \"sh\". ..I All messages, whether they are command messages or not, are saved into the saved mail file, for later perusal. ..SH FILES ~/.forward - used to store the name of the trusted user and the subject line for command messages. ..br The mail save file is named by the user as the third parameter for ..I cmdbymail. ..SH BUGS If the commands in a command message fail, no output is returned to the sender. ..PP It is currently impossible to set up servers for a group of users or all users. ..PP It is ridiculously easy to cause security problems with this program. No more hints given here.. ..SH AUTHOR Jacob Levy, Weizmann Institute of Science, Rehovot 76100, Israel. FoO ThE BaR
twb@hoqam.UUCP (BEATTIE) (07/05/85)
> From: Jacob Levy <jaakov%wisdom.bitnet@WISCVM.ARPA> > > Did you ever want to get that file you forgot to take with you when you > went to visit that other university? What a shame you forgot! Now you > will not be able to get it fast. > > But with 'cmdbymail', you can just send yourself a command file to mail > the missing file to you at the place you are currently at, and the mail > system will take care of it. How is it done? Unpack this shell archive, > by feeding everything below the dashed line to 'sh', and read the man > page included. Err, Umm Is this a BSD only utility? As far as I know [:-) .forward (??) files are not used on system V. Has there been any attempt to identify items which are: 1. BSD only 2. System V only 3. Able to function anywhere after possibly a few mods. 4. Other ? Persons posting sources could at least indicate systems known to work and possibly support features required (like .forward files). (Maybe I should read the headers more closely - but just because something was developed under BSD doesn't mean it can't work under System V, et al. Tom. Genderplex - n. The predicament of a person in a restaurant who is unable to determine his or her designated restroom (e.g. turtles and tortoises). Uniplex - n. The predicament of a unix user who is unable to determine if a piece of posted software will or won't work on his or her machine.