1 /* $NetBSD: supmsg.c,v 1.16 2009/10/16 12:41:37 christos Exp $ */
4 * Copyright (c) 1992 Carnegie Mellon University
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation is hereby granted, provided that both the copyright
9 * notice and this permission notice appear in all copies of the
10 * software, derivative works or modified versions, and any portions
11 * thereof, and that both notices appear in supporting documentation.
13 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 * Carnegie Mellon requests users of this software to return to
19 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
20 * School of Computer Science
21 * Carnegie Mellon University
22 * Pittsburgh PA 15213-3890
24 * any improvements or extensions that they make and grant Carnegie Mellon
25 * the rights to redistribute these changes.
28 **********************************************************************
31 * 7-July-93 Nate Williams at Montana State University
32 * Modified SUP to use gzip based compression when sending files
33 * across the network to save BandWidth
35 * Revision 2.4 92/09/09 22:05:17 mrt
36 * Moved PFI definition under __STDC__ conditional since it
37 * is already defined in libc.h in this case.
40 * Revision 2.3 92/08/11 12:08:12 mrt
43 * Brad's changes: Delinted, Incorporated updated variable
44 * argument list usage from old msgxfer.c
47 * Revision 2.2 89/08/23 15:02:56 gm0w
48 * Created from separate message modules.
51 **********************************************************************
54 #include <sys/types.h>
59 #include "supextern.h"
67 extern int pgmver
; /* program version of partner */
68 extern int pgmversion
; /* my program version */
69 extern char *scmver
; /* scm version of partner */
70 extern int fspid
; /* process id of fileserver */
72 static int refuseone(TREE
*, void *);
73 static int listone(TREE
*, void *);
74 static int needone(TREE
*, void *);
75 static int denyone(TREE
*, void *);
76 static int writeone(TREE
*, void *);
84 x
= readmsg(MSGSIGNON
);
86 x
= readint(&protver
);
90 x
= readstring(&scmver
);
94 x
= writemsg(MSGSIGNON
);
96 x
= writeint(PROTOVERSION
);
98 x
= writeint(pgmversion
);
100 x
= writestring(scmversion
);
113 x
= writemsg(MSGSIGNONACK
);
115 x
= writeint(PROTOVERSION
);
117 x
= writeint(pgmversion
);
119 x
= writestring(scmversion
);
125 x
= readmsg(MSGSIGNONACK
);
127 x
= readint(&protver
);
129 x
= readint(&pgmver
);
131 x
= readstring(&scmver
);
142 extern int xpatch
; /* setup crosspatch to a new client */
143 extern char *xuser
; /* user,group,acct for crosspatch */
144 extern char *collname
; /* base directory */
145 extern char *basedir
; /* base directory */
146 extern int basedev
; /* base directory device */
147 extern int baseino
; /* base directory inode */
148 extern time_t lasttime
; /* time of last upgrade */
149 extern int listonly
; /* only listing files, no data xfer */
150 extern int newonly
; /* only send new files */
151 extern char *release
; /* release name */
152 extern int setupack
; /* ack return value for setup */
160 x
= readmsg(MSGSETUP
);
164 x
= readint(&xpatch
);
170 x
= readstring(&xuser
);
175 x
= readstring(&collname
);
177 x
= readint((void *) &lasttime
);
179 x
= readstring(&basedir
);
181 x
= readint(&basedev
);
183 x
= readint(&baseino
);
185 x
= readint(&listonly
);
187 x
= readint(&newonly
);
190 release
= (char *) NULL
;
192 x
= readstring(&release
);
197 x
= writemsg(MSGSETUP
);
201 x
= writeint(xpatch
);
206 x
= writestring(xuser
);
209 return (writemend());
212 x
= writestring(collname
);
214 x
= writeint((int) lasttime
);
216 x
= writestring(basedir
);
218 x
= writeint(basedev
);
220 x
= writeint(baseino
);
222 x
= writeint(listonly
);
224 x
= writeint(newonly
);
225 if (x
== SCMOK
&& protver
>= 6)
226 x
= writestring(release
);
237 return (writemint(MSGSETUPACK
, setupack
));
238 return (readmint(MSGSETUPACK
, &setupack
));
243 extern char *crypttest
; /* encryption test string */
249 return (readmstr(MSGCRYPT
, &crypttest
));
250 return (writemstr(MSGCRYPT
, crypttest
));
257 return (writemnull(MSGCRYPTOK
));
258 return (readmnull(MSGCRYPTOK
));
263 extern char *logcrypt
; /* login encryption test */
264 extern char *loguser
; /* login username */
265 extern char *logpswd
; /* password for login */
266 extern int logack
; /* login ack status */
267 extern char *logerror
; /* error from login */
274 x
= readmsg(MSGLOGIN
);
276 x
= readstring(&logcrypt
);
278 x
= readstring(&loguser
);
280 x
= readstring(&logpswd
);
284 x
= writemsg(MSGLOGIN
);
286 x
= writestring(logcrypt
);
288 x
= writestring(loguser
);
290 x
= writestring(logpswd
);
302 x
= writemsg(MSGLOGACK
);
304 x
= writeint(logack
);
306 x
= writestring(logerror
);
310 x
= readmsg(MSGLOGACK
);
312 x
= readint(&logack
);
314 x
= readstring(&logerror
);
321 * refuse list message
323 extern TREE
*refuseT
; /* tree of files to refuse */
327 refuseone(TREE
* t
, void *v __unused
)
329 return (writestring(t
->Tname
));
338 x
= readmsg(MSGREFUSE
);
340 x
= readstring(&name
);
344 (void) Tinsert(&refuseT
, name
, FALSE
);
347 x
= readstring(&name
);
352 x
= writemsg(MSGREFUSE
);
354 x
= Tprocess(refuseT
, refuseone
, NULL
);
356 x
= writestring((char *) NULL
);
365 extern TREE
*listT
; /* tree of files to list */
366 extern time_t scantime
; /* time that collection was scanned */
370 listone(TREE
* t
, void *v __unused
)
374 x
= writestring(t
->Tname
);
376 x
= writeint((int) t
->Tmode
);
378 x
= writeint((int) t
->Tflags
);
380 x
= writeint(t
->Tmtime
);
389 x
= writemsg(MSGLIST
);
391 x
= Tprocess(listT
, listone
, NULL
);
393 x
= writestring((char *) NULL
);
395 x
= writeint((int) scantime
);
400 int mode
, flags
, mtime
;
402 x
= readmsg(MSGLIST
);
404 x
= readstring(&name
);
415 t
= Tinsert(&listT
, name
, TRUE
);
420 x
= readstring(&name
);
423 x
= readint((void *) &scantime
);
430 * files needed message
432 extern TREE
*needT
; /* tree of files to need */
436 needone(TREE
* t
, void *v __unused
)
439 x
= writestring(t
->Tname
);
441 x
= writeint((t
->Tflags
& FUPDATE
) != 0);
453 x
= readmsg(MSGNEED
);
455 x
= readstring(&name
);
459 x
= readint(&update
);
462 t
= Tinsert(&needT
, name
, TRUE
);
465 t
->Tflags
|= FUPDATE
;
466 x
= readstring(&name
);
471 x
= writemsg(MSGNEED
);
473 x
= Tprocess(needT
, needone
, NULL
);
475 x
= writestring((char *) NULL
);
482 * files denied message
484 extern TREE
*denyT
; /* tree of files to deny */
488 denyone(TREE
* t
, void *v __unused
)
490 return (writestring(t
->Tname
));
498 x
= writemsg(MSGDENY
);
500 x
= Tprocess(denyT
, denyone
, NULL
);
502 x
= writestring((char *) NULL
);
507 x
= readmsg(MSGDENY
);
509 x
= readstring(&name
);
513 (void) Tinsert(&denyT
, name
, FALSE
);
516 x
= readstring(&name
);
530 return (readmnull(MSGSEND
));
531 return (writemnull(MSGSEND
));
534 * receive file message
536 extern TREE
*upgradeT
; /* pointer to file being upgraded */
540 writeone(TREE
* t
, void *v __unused
)
542 return (writestring(t
->Tname
));
547 msgrecv(int (*xferfile
)(TREE
*, va_list), ...)
553 va_start(args
, xferfile
);
555 x
= writemsg(MSGRECV
);
558 x
= writestring((char *) NULL
);
565 x
= writestring(t
->Tname
);
567 x
= writeint(t
->Tmode
);
575 x
= writeint(t
->Tflags
);
577 x
= writestring(t
->Tuser
);
579 x
= writestring(t
->Tgroup
);
581 x
= writeint(t
->Tmtime
);
583 x
= Tprocess(t
->Tlink
, writeone
, NULL
);
585 x
= writestring((char *) NULL
);
587 x
= Tprocess(t
->Texec
, writeone
, NULL
);
589 x
= writestring((char *) NULL
);
591 x
= (*xferfile
) (t
, args
);
595 char *linkname
, *execcmd
;
600 x
= readmsg(MSGRECV
);
602 x
= readstring(&t
->Tname
);
603 if (x
== SCMOK
&& t
->Tname
== NULL
) {
606 x
= (*xferfile
) (NULL
, args
);
611 x
= readint(&t
->Tmode
);
615 x
= (*xferfile
) (t
, args
);
620 x
= readint(&t
->Tflags
);
622 x
= readstring(&t
->Tuser
);
624 x
= readstring(&t
->Tgroup
);
626 x
= readint(&t
->Tmtime
);
629 x
= readstring(&linkname
);
631 if (linkname
== NULL
)
633 (void) Tinsert(&t
->Tlink
, linkname
, FALSE
);
636 x
= readstring(&linkname
);
640 x
= readstring(&execcmd
);
644 (void) Tinsert(&t
->Texec
, execcmd
, FALSE
);
647 x
= readstring(&execcmd
);
650 x
= (*xferfile
) (t
, args
);
658 * protocol done message
661 extern char *donereason
;
669 printf("Error, msgdone should not have been called.");
673 x
= readmsg(MSGDONE
);
675 x
= readint(&doneack
);
677 x
= readstring(&donereason
);
681 x
= writemsg(MSGDONE
);
683 x
= writeint(doneack
);
685 x
= writestring(donereason
);
694 extern char *goawayreason
; /* reason for goaway */
699 return (writemstr(MSGGOAWAY
, goawayreason
));
702 * cross-patch protocol message
704 extern int xargc
; /* arg count for crosspatch */
705 extern char **xargv
; /* arg array for crosspatch */
714 x
= readmsg(MSGXPATCH
);
721 xargv
= (char **) calloc(sizeof(char *), (unsigned) xargc
+ 1);
724 for (i
= 2; i
< xargc
; i
++) {
725 x
= readstring(&xargv
[i
]);
731 x
= writemsg(MSGXPATCH
);
737 for (i
= 0; i
< xargc
; i
++) {
738 x
= writestring(xargv
[i
]);
747 * Compression check protocol message
749 extern int docompress
; /* Compress file before sending? */
755 return (readmint(MSGCOMPRESS
, &docompress
));
756 return (writemint(MSGCOMPRESS
, docompress
));