2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <koshy@india.hp.com> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Joseph Koshy
7 * ----------------------------------------------------------------------------
9 * $FreeBSD: src/usr.sbin/ctm/ctm/ctm_passb.c,v 1.5.2.1 2001/07/05 07:46:57 kris Exp $
10 * $DragonFly: src/usr.sbin/ctm/ctm/Attic/ctm_passb.c,v 1.2 2003/06/17 04:29:53 dillon Exp $
17 /*---------------------------------------------------------------------------*/
18 /* PassB -- Backup modified files.
27 u_char *md5=0,*md5before=0,*trash=0,*name=0,*uid=0,*gid=0,*mode=0;
28 struct CTM_Syntax *sp;
29 FILE *b = 0; /* backup command */
34 struct CTM_Filter *filter = NULL;
37 printf("PassB -- Backing up files which would be changed.\n");
40 snprintf(buf, sizeof(buf), fmtcheck(TarCmd, TARCMD), BackupFile);
42 if(!b) { warn("%s", buf); return Exit_Garbage; }
44 GETFIELD(p,' '); if(strcmp("CTM_BEGIN",p)) WRONG
45 GETFIELD(p,' '); if(strcmp(Version,p)) WRONG
46 GETFIELD(p,' '); if(strcmp(Name,p)) WRONG
47 GETFIELD(p,' '); if(strcmp(Nbr,p)) WRONG
48 GETFIELD(p,' '); if(strcmp(TimeStamp,p)) WRONG
49 GETFIELD(p,'\n'); if(strcmp(Prefix,p)) WRONG
63 if (p[0] != 'C' || p[1] != 'T' || p[2] != 'M') WRONG
65 if(!strcmp(p+3,"_END"))
68 for(sp=Syntax;sp->Key;sp++)
69 if(!strcmp(p+3,sp->Key))
73 for(i=0;(j = sp->List[i]);i++) {
74 if (sp->List[i+1] && (sp->List[i+1] & CTM_F_MASK) != CTM_F_Bytes)
79 switch (j & CTM_F_MASK) {
80 case CTM_F_Name: GETNAMECOPY(name,sep,j, Verbose); break;
81 case CTM_F_Uid: GETFIELDCOPY(uid,sep); break;
82 case CTM_F_Gid: GETFIELDCOPY(gid,sep); break;
83 case CTM_F_Mode: GETFIELDCOPY(mode,sep); break;
85 if(j & CTM_Q_MD5_Before)
86 GETFIELDCOPY(md5before,sep);
88 GETFIELDCOPY(md5,sep);
90 case CTM_F_Count: GETBYTECNT(cnt,sep); break;
91 case CTM_F_Bytes: GETDATA(trash,cnt); break;
95 /* XXX This should go away. Disallow trailing '/' */
97 if(name[j] == '/') name[j] = '\0';
100 (!strcmp(sp->Key,"DR") || !strcmp(sp->Key,"FR")))
103 /* match the name against the elements of the filter list. The
104 action associated with the last matched filter determines whether
105 this file should be ignored or backed up. */
106 match = (FilterList ? !(FilterList->Action) : CTM_FILTER_ENABLE);
107 for (filter = FilterList; filter; filter = filter->Next) {
108 if (0 == regexec(&filter->CompiledRegex, name, 0, 0, 0))
109 match = filter->Action;
112 if (CTM_FILTER_DISABLE == match)
115 if (!strcmp(sp->Key,"FS") || !strcmp(sp->Key,"FN") ||
116 !strcmp(sp->Key,"AS") || !strcmp(sp->Key,"DR") ||
117 !strcmp(sp->Key,"FR")) {
118 /* send name to the archiver for a backup */
120 if (cnt != fwrite(name,1,cnt,b) || EOF == fputc('\n',b)) {
138 q = MD5End (&ctx,md5_1);
139 GETFIELD(p,'\n'); /* <MD5> */
140 if(strcmp(q,p)) WRONG
141 if (-1 != getc(fd)) WRONG