2 * Bacula File Daemon verify.c Verify files.
4 * Kern Sibbald, October MM
8 Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2 of
13 the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public
21 License along with this program; if not, write to the Free
22 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 static int verify_file(FF_PKT *ff_pkt, void *my_pkt);
33 * Find all the requested files and send attributes
37 void do_verify(JCR *jcr)
39 BSOCK *dir = jcr->dir_bsock;
41 jcr->buf_size = MAX_NETWORK_BUFFER_SIZE;
42 if ((jcr->big_buf = (char *) malloc(jcr->buf_size)) == NULL) {
43 Emsg1(M_ABORT, 0, _("Cannot malloc %d network read buffer\n"), MAX_NETWORK_BUFFER_SIZE);
45 set_find_options(jcr->ff, jcr->incremental, jcr->mtime);
46 Dmsg0(10, "Start find files\n");
47 /* Subroutine verify_file() is called for each file */
48 if (!find_files(jcr->ff, verify_file, (void *)jcr)) {
49 /****FIXME**** error termination */
50 Dmsg0(0, "========= Error return from find_files\n");
52 Dmsg0(10, "End find files\n");
55 bnet_send(dir); /* signal end attributes to director */
63 * Called here by find() for each file.
65 *****FIXME***** add FSMs File System Modules
68 * Find the file, compute the MD5 and send it back to the Director
70 static int verify_file(FF_PKT *ff_pkt, void *pkt)
72 char attribs[MAXSTRING];
75 struct MD5Context md5c;
76 unsigned char signature[16];
78 JCR *jcr = (JCR *)pkt;
80 sd = jcr->store_bsock;
83 switch (ff_pkt->type) {
84 case FT_LNKSAVED: /* Hard linked, file already saved */
87 Dmsg1(30, "FT_REGE saving: %s\n", ff_pkt->fname);
90 Dmsg1(30, "FT_REG saving: %s\n", ff_pkt->fname);
93 Dmsg2(30, "FT_LNK saving: %s -> %s\n", ff_pkt->fname, ff_pkt->link);
96 Dmsg1(30, "FT_DIR saving: %s\n", ff_pkt->fname);
99 Dmsg1(30, "FT_SPEC saving: %s\n", ff_pkt->fname);
102 Jmsg(jcr, M_ERROR, -1, _(" Could not access %s: ERR=%s\n"), ff_pkt->fname, strerror(ff_pkt->ff_errno));
105 Jmsg(jcr, M_ERROR, -1, _(" Could not follow link %s: ERR=%s\n"), ff_pkt->fname, strerror(ff_pkt->ff_errno));
108 Jmsg(jcr, M_ERROR, -1, _(" Could not stat %s: ERR=%s\n"), ff_pkt->fname, strerror(ff_pkt->ff_errno));
112 Jmsg(jcr, M_INFO, -1, _(" Unchanged file skipped: %s\n"), ff_pkt->fname);
115 Jmsg(jcr, M_SKIPPED, -1, _(" Archive file skipped: %s\n"), ff_pkt->fname);
118 Jmsg(jcr, M_SKIPPED, -1, _(" Recursion turned off. Directory skipped: %s\n"), ff_pkt->fname);
121 Jmsg(jcr, M_SKIPPED, -1, _(" File system change prohibited. Directory skipped: %s\n"), ff_pkt->fname);
124 Jmsg(jcr, M_ERROR, -1, _(" Could not open directory %s: ERR=%s\n"), ff_pkt->fname, strerror(ff_pkt->ff_errno));
127 Jmsg(jcr, M_ERROR, 0, _("Unknown file type %d: %s\n"), ff_pkt->type, ff_pkt->fname);
131 if ((fid = open(ff_pkt->fname, O_RDONLY | O_BINARY)) < 0) {
132 ff_pkt->ff_errno = errno;
133 Jmsg(jcr, M_ERROR, -1, _(" Cannot open %s: ERR=%s.\n"), ff_pkt->fname, strerror(ff_pkt->ff_errno));
137 Dmsg2(50, "opened %s fid=%d\n", ff_pkt->fname, fid);
138 Dmsg1(10, "bfiled: sending %s to Director\n", ff_pkt->fname);
139 encode_stat(attribs, &ff_pkt->statp);
141 jcr->JobFiles++; /* increment number of files sent */
143 if (ff_pkt->VerifyOpts[0] == 0) {
144 ff_pkt->VerifyOpts[0] = 'V';
145 ff_pkt->VerifyOpts[1] = 0;
147 /* Send file attributes to Director (note different format than for Storage) */
148 if (ff_pkt->type == FT_LNK) {
149 dir->msglen = sprintf(dir->msg,"%d %d %s %s%c%s%c%s%c", jcr->JobFiles,
150 STREAM_UNIX_ATTRIBUTES, ff_pkt->VerifyOpts, ff_pkt->fname,
151 0, attribs, 0, ff_pkt->link, 0);
153 dir->msglen = sprintf(dir->msg,"%d %d %s %s%c%s%c%c", jcr->JobFiles,
154 STREAM_UNIX_ATTRIBUTES, ff_pkt->VerifyOpts, ff_pkt->fname,
157 Dmsg2(20, "bfiled>bdird: attribs len=%d: msg=%s\n", dir->msglen, dir->msg);
158 bnet_send(dir); /* send to Director */
162 * If MD5 is requested, read the file and compute the MD5
165 if (ff_pkt->flags & FO_MD5) {
166 char MD5buf[50]; /* 24 should do */
170 if (ff_pkt->type != FT_LNKSAVED && S_ISREG(ff_pkt->statp.st_mode) &&
171 ff_pkt->statp.st_size > 0) {
172 while ((n=read(fid, jcr->big_buf, jcr->buf_size)) > 0) {
173 MD5Update(&md5c, ((unsigned char *) jcr->big_buf), n);
177 Jmsg(jcr, M_ERROR, -1, _(" Error reading %s: ERR=%s\n"), ff_pkt->fname, strerror(ff_pkt->ff_errno));
181 MD5Final(signature, &md5c);
183 bin_to_base64(MD5buf, (char *)signature, 16); /* encode 16 bytes */
184 dir->msglen = sprintf(dir->msg, "%d %d %s X", jcr->JobFiles,
185 STREAM_MD5_SIGNATURE, MD5buf);
186 Dmsg2(20, "bfiled>bdird: MD5 len=%d: msg=%s\n", dir->msglen, dir->msg);
187 bnet_send(dir); /* send MD5 signature to Director */