xref: /csrg-svn/old/berknet/header.c (revision 8186)
1*8186Smckusick static char sccsid[] = "@(#)header.c	4.1	(Berkeley)	09/12/82";
2*8186Smckusick 
3*8186Smckusick /* sccs id variable */
4*8186Smckusick static char *header_sid = "@(#)header.c	1.3";
5*8186Smckusick /*
6*8186Smckusick 	header.c
7*8186Smckusick 
8*8186Smckusick 	these routines provide a way of transferring the information
9*8186Smckusick 	in the "header" structure between machines.
10*8186Smckusick 	Programs calling these routines either read or write
11*8186Smckusick 	their information into the header structure.
12*8186Smckusick 	These procedures format the info in a way that is acceptable.
13*8186Smckusick 	Called by net.c, netdaemon.c, and netq.c.
14*8186Smckusick */
15*8186Smckusick /*
16*8186Smckusick 	protocol that is sent (in ASCII):
17*8186Smckusick 	code, remote mach, local mach, version stamp (2), remote login name,
18*8186Smckusick 	password, -i, -o, -r files,
19*8186Smckusick 	local login name, terminal, flag, utmp tty login time,
20*8186Smckusick 	cc jobno(variable parameter list), current time,
21*8186Smckusick 	command '\n' real command '\n'
22*8186Smckusick 	any data
23*8186Smckusick 
24*8186Smckusick 	changes:
25*8186Smckusick 	1) remove header
26*8186Smckusick 	3) use ascii length instead of 4 bytes
27*8186Smckusick 	4) encrypt the login name, command, and part of data as well
28*8186Smckusick */
29*8186Smckusick # include "defs.h"
30*8186Smckusick 
31*8186Smckusick 
writehdfd(phd,fd)32*8186Smckusick writehdfd(phd,fd)
33*8186Smckusick register struct header *phd;
34*8186Smckusick FILE *fd;
35*8186Smckusick {
36*8186Smckusick 	char *genparmlist();
37*8186Smckusick 	char cflag = 'a';
38*8186Smckusick 
39*8186Smckusick 	/* cflag is initially 'a'. Add the flags as needed. */
40*8186Smckusick 	if(phd->hd_fnonotify)cflag += F_NONOTIFY;
41*8186Smckusick 	if(phd->hd_fquiet)cflag += F_QUIET;
42*8186Smckusick 
43*8186Smckusick 	fprintf(fd,
44*8186Smckusick 	"%c :%c :%c :%c :%c :%s :%s :%s :%s :%s :%s :%s :%c :%lo :%s%s :%ld :",
45*8186Smckusick 		phd->hd_code,phd->hd_mchto,phd->hd_mchfrom,
46*8186Smckusick 		phd->hd_vmajor+'a',phd->hd_vminor+'a',phd->hd_snto,
47*8186Smckusick 		phd->hd_spasswd,phd->hd_sinfile,phd->hd_soutfile,
48*8186Smckusick 		phd->hd_srespfile,
49*8186Smckusick 		phd->hd_snfrom,phd->hd_sttyname,cflag,phd->hd_lttytime,
50*8186Smckusick 		phd->hd_ijobno,genparmlist(phd),phd->hd_ltimesent-TIMEBASE);
51*8186Smckusick 	fputs(phd->hd_scmdact,fd);
52*8186Smckusick 	putc('\n',fd);
53*8186Smckusick 	fputs(phd->hd_scmdvirt,fd);
54*8186Smckusick 	putc('\n',fd);
55*8186Smckusick 	/* not used, but a good idea */
56*8186Smckusick 	sprintf(phd->hd_addrfrom,"%c:%s",phd->hd_mchfrom,phd->hd_snfrom);
57*8186Smckusick 	sprintf(phd->hd_addrto,  "%c:%s",phd->hd_mchto,  phd->hd_snto);
58*8186Smckusick }
59*8186Smckusick /*
60*8186Smckusick 	print out debugging values of a header structure
61*8186Smckusick */
printhd(phd)62*8186Smckusick printhd(phd)
63*8186Smckusick register struct header *phd;
64*8186Smckusick {
65*8186Smckusick 	if(debugflg){
66*8186Smckusick 		printf("To %s From %s quiet=%c nonotify=%c\n",
67*8186Smckusick 			phd->hd_addrto, phd->hd_addrfrom,
68*8186Smckusick 			chfromf(phd->hd_fquiet), chfromf(phd->hd_fnonotify));
69*8186Smckusick 		/* don't print out for security reasons
70*8186Smckusick 		printf("Password %s\n",phd->hd_spasswd);
71*8186Smckusick 		*/
72*8186Smckusick 		printf("Code '%c' Version (%d,%d) Infile '%s'\n",
73*8186Smckusick 			phd->hd_code, phd->hd_vmajor,phd->hd_vminor,
74*8186Smckusick 			phd->hd_sinfile);
75*8186Smckusick 		printf("Outfile '%s' Respfile '%s' TTYName '%s'\n",
76*8186Smckusick 			phd->hd_soutfile,phd->hd_srespfile, phd->hd_sttyname);
77*8186Smckusick 		printf("Jobno %s TimeSent %s", phd->hd_ijobno,
78*8186Smckusick 			ctime(&phd->hd_ltimesent));
79*8186Smckusick 		if(phd->hd_lttytime != 0)
80*8186Smckusick 			printf("TTYTime %s", ctime(&phd->hd_lttytime));
81*8186Smckusick 		printf("Virtual Command \"%s\"\n", phd->hd_scmdvirt);
82*8186Smckusick 		printf("Actual Command \"%s\"\n", phd->hd_scmdact);
83*8186Smckusick 	}
84*8186Smckusick }
85*8186Smckusick /*
86*8186Smckusick 	generate a variable parameter list
87*8186Smckusick 	the format is:
88*8186Smckusick 		(name value, name value, ..., name value)
89*8186Smckusick 	where names are unquoted single words and values
90*8186Smckusick 	are unquoted if a single alphanumeric word, and are
91*8186Smckusick 	surrounded by {} otherwise. \ quotes { and }.
92*8186Smckusick 	the values are escape-processed, e.g. \n becomes 012.
93*8186Smckusick 	this function returns such a list.
94*8186Smckusick 	Returns the null parm list if nothing to give, i.e. "()"
95*8186Smckusick 
96*8186Smckusick 	Should also default so single keywords can have on/off
97*8186Smckusick 	states, and so do not require a value.
98*8186Smckusick 
99*8186Smckusick 	Things this variable protocol should specify:
100*8186Smckusick 		EPASSWD 	encrypted passwd
101*8186Smckusick 		FILEMODE 	file mode
102*8186Smckusick 		FROMUID  	from users' uid
103*8186Smckusick 		FROMGID  	from users' gid
104*8186Smckusick 		COMPRESS 	use colin's compression
105*8186Smckusick 		ACCTPAIR	handle acct pairs
106*8186Smckusick 		MESSAGEID	unique number identifying this request.
107*8186Smckusick 		FILENAME	when omitted by netcp, will use FILENAME ext.
108*8186Smckusick 		REPLYTO		the person the response should be sent to
109*8186Smckusick 
110*8186Smckusick 		 --- possibly ---
111*8186Smckusick 		MACHINE2	a second machine (e.g. 3way netcp)
112*8186Smckusick 		LOGIN2		a second login name
113*8186Smckusick 		PASSWD2		a second passwd
114*8186Smckusick 
115*8186Smckusick */
genparmlist(phd)116*8186Smckusick static char *genparmlist(phd)
117*8186Smckusick register struct header *phd;
118*8186Smckusick {
119*8186Smckusick 	static char returnstr[PARMLIST];
120*8186Smckusick 	strcpy(returnstr,"()");
121*8186Smckusick 	return(returnstr);
122*8186Smckusick }
123