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 * ----------------------------------------------------------------------------
16 /*---------------------------------------------------------------------------*/
17 /* PassB -- Backup modified files.
26 u_char *md5=0,*md5before=0,*trash=0,*name=0,*uid=0,*gid=0,*mode=0;
27 struct CTM_Syntax *sp;
28 FILE *b = 0; /* backup command */
33 struct CTM_Filter *filter = NULL;
36 printf("PassB -- Backing up files which would be changed.\n");
39 snprintf(buf, sizeof(buf), fmtcheck(TarCmd, TARCMD), BackupFile);
41 if(!b) { warn("%s", buf); return Exit_Garbage; }
43 GETFIELD(p,' '); if(strcmp("CTM_BEGIN",p)) WRONG
44 GETFIELD(p,' '); if(strcmp(Version,p)) WRONG
45 GETFIELD(p,' '); if(strcmp(Name,p)) WRONG
46 GETFIELD(p,' '); if(strcmp(Nbr,p)) WRONG
47 GETFIELD(p,' '); if(strcmp(TimeStamp,p)) WRONG
48 GETFIELD(p,'\n'); if(strcmp(Prefix,p)) WRONG
62 if (p[0] != 'C' || p[1] != 'T' || p[2] != 'M') WRONG
64 if(!strcmp(p+3,"_END"))
67 for(sp=Syntax;sp->Key;sp++)
68 if(!strcmp(p+3,sp->Key))
72 for(i=0;(j = sp->List[i]);i++) {
73 if (sp->List[i+1] && (sp->List[i+1] & CTM_F_MASK) != CTM_F_Bytes)
78 switch (j & CTM_F_MASK) {
79 case CTM_F_Name: GETNAMECOPY(name,sep,j, Verbose); break;
80 case CTM_F_Uid: GETFIELDCOPY(uid,sep); break;
81 case CTM_F_Gid: GETFIELDCOPY(gid,sep); break;
82 case CTM_F_Mode: GETFIELDCOPY(mode,sep); break;
84 if(j & CTM_Q_MD5_Before)
85 GETFIELDCOPY(md5before,sep);
87 GETFIELDCOPY(md5,sep);
89 case CTM_F_Count: GETBYTECNT(cnt,sep); break;
90 case CTM_F_Bytes: GETDATA(trash,cnt); break;
94 /* XXX This should go away. Disallow trailing '/' */
96 if(name[j] == '/') name[j] = '\0';
99 (!strcmp(sp->Key,"DR") || !strcmp(sp->Key,"FR")))
102 /* match the name against the elements of the filter list. The
103 action associated with the last matched filter determines whether
104 this file should be ignored or backed up. */
105 match = (FilterList ? !(FilterList->Action) : CTM_FILTER_ENABLE);
106 for (filter = FilterList; filter; filter = filter->Next) {
107 if (0 == regexec(&filter->CompiledRegex, name, 0, 0, 0))
108 match = filter->Action;
111 if (CTM_FILTER_DISABLE == match)
114 if (!strcmp(sp->Key,"FS") || !strcmp(sp->Key,"FN") ||
115 !strcmp(sp->Key,"AS") || !strcmp(sp->Key,"DR") ||
116 !strcmp(sp->Key,"FR")) {
117 /* send name to the archiver for a backup */
119 if (cnt != fwrite(name,1,cnt,b) || EOF == fputc('\n',b)) {
137 q = MD5End (&ctx,md5_1);
138 GETFIELD(p,'\n'); /* <MD5> */
139 if(strcmp(q,p)) WRONG
140 if (-1 != getc(fd)) WRONG