]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bdb_delete.c
Fix segfault from double free or RestoreBootstrap; add L_NONE for restore and admin...
[bacula/bacula] / bacula / src / cats / bdb_delete.c
1 /*
2  * Bacula Catalog Database Delete record interface routines
3  *
4  * Bacula Catalog Database routines written specifically
5  *  for Bacula.  Note, these routines are VERY dumb and
6  *  do not provide all the functionality of an SQL database.
7  *  The purpose of these routines is to ensure that Bacula
8  *  can limp along if no real database is loaded on the
9  *  system.
10  *   
11  *    Kern Sibbald, January MMI 
12  *
13  *    Version $Id$
14  */
15
16 /*
17    Copyright (C) 2001-2003 Kern Sibbald and John Walker
18
19    This program is free software; you can redistribute it and/or
20    modify it under the terms of the GNU General Public License as
21    published by the Free Software Foundation; either version 2 of
22    the License, or (at your option) any later version.
23
24    This program is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27    General Public License for more details.
28
29    You should have received a copy of the GNU General Public
30    License along with this program; if not, write to the Free
31    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32    MA 02111-1307, USA.
33
34  */
35
36
37 /* The following is necessary so that we do not include
38  * the dummy external definition of DB.
39  */
40 #define __SQL_C                       /* indicate that this is sql.c */
41
42 #include "bacula.h"
43 #include "cats.h"
44 #include "bdb.h"
45
46 #ifdef HAVE_BACULA_DB
47
48 /* Forward referenced functions */
49
50 /* -----------------------------------------------------------------------
51  *
52  *   Bacula specific defines and subroutines
53  *
54  * -----------------------------------------------------------------------
55  */
56
57
58 /*
59  * Delete a Pool record given the Name
60  *
61  * Returns: 0 on error
62  *          the number of records deleted on success 
63  */
64 int db_delete_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
65 {
66    int stat;
67    POOL_DBR opr;
68
69    db_lock(mdb);
70    pr->PoolId = 0;                    /* Search on Pool Name */
71    if (!db_get_pool_record(jcr, mdb, pr)) {
72       Mmsg1(&mdb->errmsg, "No pool record %s exists\n", pr->Name);
73       db_unlock(mdb);
74       return 0;
75    }
76    fseek(mdb->poolfd, pr->rec_addr, SEEK_SET);
77    memset(&opr, 0, sizeof(opr));
78    stat = fwrite(&opr, sizeof(opr), 1, mdb->poolfd);
79    db_unlock(mdb);
80    return stat; 
81 }
82
83 int db_delete_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) 
84
85    int stat;
86    MEDIA_DBR omr;
87
88    db_lock(mdb);
89    if (!db_get_media_record(jcr, mdb, mr)) {
90       Mmsg0(&mdb->errmsg, "Media record not found.\n");
91       db_unlock(mdb);
92       return 0;
93    }
94    fseek(mdb->mediafd, mr->rec_addr, SEEK_SET);
95    memset(&omr, 0, sizeof(omr));
96    stat = fwrite(&omr, sizeof(omr), 1, mdb->mediafd);
97    db_unlock(mdb);
98    return stat; 
99 }
100
101 #endif /* HAVE_BACULA_DB */