]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/match_bsr.c
b7e331d7f010bdd4568d9f5995daec6aa7c6d47d
[bacula/bacula] / bacula / src / stored / match_bsr.c
1 /*     
2  *   Match Bootstrap Records (used for restores) against
3  *     Volume Records
4  *  
5  *     Kern Sibbald, June MMII
6  *
7  *   Version $Id$
8  */
9
10 /*
11    Copyright (C) 2002 Kern Sibbald and John Walker
12
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License as
15    published by the Free Software Foundation; either version 2 of
16    the License, or (at your option) any later version.
17
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21    General Public License for more details.
22
23    You should have received a copy of the GNU General Public
24    License along with this program; if not, write to the Free
25    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26    MA 02111-1307, USA.
27
28  */
29
30
31 #include "bacula.h"
32 #include "stored.h"
33 #include <fnmatch.h>
34
35 /* Forward references */
36 static int match_sesstime(BSR_SESSTIME *sesstime, DEV_RECORD *rec);
37 static int match_sessid(BSR_SESSID *sessid, DEV_RECORD *rec);
38 static int match_client(BSR_CLIENT *client, SESSION_LABEL *sessrec);
39 static int match_job(BSR_JOB *job, SESSION_LABEL *sessrec);
40 static int match_job_type(BSR_JOBTYPE *job_type, SESSION_LABEL *sessrec);
41 static int match_job_level(BSR_JOBLEVEL *job_level, SESSION_LABEL *sessrec);
42 static int match_jobid(BSR_JOBID *jobid, SESSION_LABEL *sessrec);
43 static int match_findex(BSR_FINDEX *findex, DEV_RECORD *rec);
44 static int match_volfile(BSR_VOLFILE *volfile, DEV_RECORD *rec);
45 static int match_stream(BSR_STREAM *stream, DEV_RECORD *rec);
46 static int match_one_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec);
47
48 /*********************************************************************
49  *
50  *      Match Bootstrap records
51  *
52  */
53 int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec)
54 {
55    if (!bsr) {
56       return 0;
57    }
58    if (match_one_bsr(bsr, rec, volrec, sessrec)) {
59       return 1;
60    }
61    return match_bsr(bsr->next, rec, volrec, sessrec);
62 }
63
64 static int match_one_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec)
65 {
66    if (strcmp(bsr->VolumeName, volrec->VolName) != 0) {
67       return 0;
68    }
69    if (!match_volfile(bsr->volfile, rec)) {
70       return 0;
71    }
72    if (!match_sesstime(bsr->sesstime, rec)) {
73       return 0;
74    }
75    if (!match_sessid(bsr->sessid, rec)) {
76       return 0;
77    }
78    if (!match_jobid(bsr->JobId, sessrec)) {
79       return 0;
80    }
81    if (!match_job(bsr->job, sessrec)) {
82       return 0;
83    }
84    if (!match_client(bsr->client, sessrec)) {
85       return 0;
86    }
87    if (!match_findex(bsr->FileIndex, rec)) {
88       return 0;
89    }
90    if (!match_job_type(bsr->JobType, sessrec)) {
91       return 0;
92    }
93    if (!match_job_level(bsr->JobLevel, sessrec)) {
94       return 0;
95    }
96    if (!match_stream(bsr->stream, rec)) {
97       return 0;
98    }
99    return 1;
100 }
101
102 static int match_client(BSR_CLIENT *client, SESSION_LABEL *sessrec)
103 {
104    if (!client) {
105       return 1;                       /* no specification matches all */
106    }
107    if (fnmatch(client->ClientName, sessrec->ClientName, 0) == 0) {
108       return 1;
109    }
110    if (client->next) {
111       return match_client(client->next, sessrec);
112    }
113    return 0;
114 }
115
116 static int match_job(BSR_JOB *job, SESSION_LABEL *sessrec)
117 {
118    if (!job) {
119       return 1;                       /* no specification matches all */
120    }
121    if (fnmatch(job->Job, sessrec->Job, 0) == 0) {
122       job->found++;
123       return 1;
124    }
125    if (job->next) {
126       return match_job(job->next, sessrec);
127    }
128    return 0;
129 }
130
131
132 static int match_job_type(BSR_JOBTYPE *job_type, SESSION_LABEL *sessrec)
133 {
134    if (!job_type) {
135       return 1;                       /* no specification matches all */
136    }
137    if (job_type->JobType == sessrec->JobType) {
138       return 1;
139    }
140    if (job_type->next) {
141       return match_job_type(job_type->next, sessrec);
142    }
143    return 0;
144 }
145
146 static int match_job_level(BSR_JOBLEVEL *job_level, SESSION_LABEL *sessrec)
147 {
148    if (!job_level) {
149       return 1;                       /* no specification matches all */
150    }
151    if (job_level->JobLevel == sessrec->JobLevel) {
152       return 1;
153    }
154    if (job_level->next) {
155       return match_job_level(job_level->next, sessrec);
156    }
157    return 0;
158 }
159
160 static int match_jobid(BSR_JOBID *jobid, SESSION_LABEL *sessrec)
161 {
162    if (!jobid) {
163       return 1;                       /* no specification matches all */
164    }
165    if (jobid->JobId <= sessrec->JobId && jobid->JobId2 >= sessrec->JobId) {
166       jobid->found++;
167       return 1;
168    }
169    if (jobid->next) {
170       return match_jobid(jobid->next, sessrec);
171    }
172    return 0;
173 }
174
175
176 static int match_volfile(BSR_VOLFILE *volfile, DEV_RECORD *rec)
177 {
178    if (!volfile) {
179       return 1;                       /* no specification matches all */
180    }
181    if (volfile->sfile <= rec->File && volfile->efile >= rec->File) {
182       volfile->found++;
183       return 1;
184    }
185    if (volfile->next) {
186       return match_volfile(volfile->next, rec);
187    }
188    return 0;
189 }
190
191 static int match_stream(BSR_STREAM *stream, DEV_RECORD *rec)
192 {
193    if (!stream) {
194       return 1;                       /* no specification matches all */
195    }
196    if (stream->stream == rec->Stream) {
197       return 1;
198    }
199    if (stream->next) {
200       return match_stream(stream->next, rec);
201    }
202    return 0;
203 }
204
205 static int match_findex(BSR_FINDEX *findex, DEV_RECORD *rec)
206 {
207    if (!findex) {
208       return 1;                       /* no specification matches all */
209    }
210    if (findex->findex <= rec->FileIndex && findex->findex2 >= rec->FileIndex) {
211       findex->found++;
212       return 1;
213    }
214    if (findex->next) {
215       return match_findex(findex->next, rec);
216    }
217    return 0;
218 }
219
220
221 static int match_sessid(BSR_SESSID *sessid, DEV_RECORD *rec)
222 {
223    if (!sessid) {
224       return 1;                       /* no specification matches all */
225    }
226    if (sessid->sessid <= rec->VolSessionId && sessid->sessid2 >= rec->VolSessionId) {
227       sessid->found++;
228       return 1;
229    }
230    if (sessid->next) {
231       return match_sessid(sessid->next, rec);
232    }
233    return 0;
234 }
235
236 static int match_sesstime(BSR_SESSTIME *sesstime, DEV_RECORD *rec)
237 {
238    if (!sesstime) {
239       return 1;                       /* no specification matches all */
240    }
241    if (sesstime->sesstime == rec->VolSessionTime) {
242       sesstime->found++;
243       return 1;
244    }
245    if (sesstime->next) {
246       return match_sesstime(sesstime->next, rec);
247    }
248    return 0;
249 }