From 0f35059da342f2795078ac92ba5bc14fddc53a29 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 5 Jan 2008 22:12:20 +0000 Subject: [PATCH] kes Fix reserve_volume() so it doesn't release a volume in use (i.e. a volume entry not marked released). This should be the last part needed to fix bug #1018. + remove old code + update some copyrights git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6240 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/LICENSE | 9 +- bacula/projects | 31 +++++++ bacula/src/dird/ua_update.c | 4 +- bacula/src/jcr.h | 2 + bacula/src/lib/bnet_server.c | 162 ----------------------------------- bacula/src/lib/daemon.c | 8 +- bacula/src/stored/label.c | 2 +- bacula/src/stored/reserve.c | 27 ++++-- bacula/technotes-2.3 | 12 ++- 9 files changed, 76 insertions(+), 181 deletions(-) diff --git a/bacula/LICENSE b/bacula/LICENSE index 12d4c662a9..6f3eee71a1 100644 --- a/bacula/LICENSE +++ b/bacula/LICENSE @@ -75,7 +75,7 @@ Code falling under the above conditions will be marked as follows: Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -122,9 +122,10 @@ copyrighted code. GPLv2 or later license: src/tools/bsmtp.c Copyright (C) 1997 Ralf S. Engelschall, All Rights Reserved. - (note, bsmtp.c does not use OpenSSL) + (note, bsmtp.c does not use OpenSSL, nor is it used with the code + of any other part of Bacula) -BSD License notice for inclusion with the binary: +3 clause BSD License notice for inclusion with the binary: src/lib/fnmatch.c * Copyright (c) 1989, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -163,7 +164,7 @@ that contains cryptographic software written by Eric Young (tjh@cryptsoft.com). There are parts of Bacula that are licensed under the LGPL so -that they may be used in proprietary code to interface with +that those files may be used in proprietary code to interface with Bacula. Finally there are parts of Bacula that are in the public domain. diff --git a/bacula/projects b/bacula/projects index 55820d6946..40b9040862 100644 --- a/bacula/projects +++ b/bacula/projects @@ -1157,6 +1157,37 @@ Item h10: Clustered file-daemons implement it. A lot more design detail should be presented before voting on this project. +========= Added since the last vote ================= + +Item: Store and restore extended attributes, especially selinux file contexts + Date: 28 December 2007 + Origin: Frank Sweetser + What: The ability to store and restore extended attributes on + filesystems that support them, such as ext3. + + Why: Security Enhanced Linux (SELinux) enabled systems make extensive + use of extended attributes. In addition to the standard user, + group, and permission, each file has an associated SELinux context + stored as an extended attribute. This context is used to define + which operations a given program is permitted to perform on that + file. Storing contexts on an SELinux system is as critical as + storing ownership and permissions. In the case of a full system + restore, the system will not even be able to boot until all + critical system files have been properly relabeled. + + Notes: Fedora ships with a version of tar that has been patched to handle + extended attributes. The patch has not been integrated upstream + yet, so could serve as a good starting point. + + http://linux.die.net/man/2/getxattr + http://linux.die.net/man/2/setxattr + http://linux.die.net/man/2/listxattr + === + http://linux.die.net/man/3/getfilecon + http://linux.die.net/man/3/setfilecon + + + ========== Already implemented ================================ diff --git a/bacula/src/dird/ua_update.c b/bacula/src/dird/ua_update.c index 2526bcd2ed..f7e38bd5e6 100644 --- a/bacula/src/dird/ua_update.c +++ b/bacula/src/dird/ua_update.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -579,7 +579,7 @@ static int update_volume(UAContext *ua) i = do_prompt(ua, "", _("Select parameter to modify"), NULL, 0); /* For All Volumes, All Volumes from Pool, and Done, we don't need - * a Volume record */ + * a Volume record */ if ( i != 12 && i != 13 && i != 16) { if (!select_media_dbr(ua, &mr)) { /* Get Volume record */ return 0; diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 51e7704a5f..ccef2c32b2 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -192,6 +192,8 @@ public: ATTR_DBR *ar; /* DB attribute record */ guid_list *id_list; /* User/group id to name list */ + void *plugin_ctx; + /* Daemon specific part of JCR */ /* This should be empty in the library */ diff --git a/bacula/src/lib/bnet_server.c b/bacula/src/lib/bnet_server.c index d6bac6de05..0602ebb507 100644 --- a/bacula/src/lib/bnet_server.c +++ b/bacula/src/lib/bnet_server.c @@ -240,165 +240,3 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, } -#ifdef REALLY_USED -/* - * Bind an address so that we may accept connections - * one at a time. - */ -BSOCK *bnet_bind(int port) -{ - int sockfd; - struct sockaddr_in serv_addr; /* our address */ - int tlog; - int turnon = 1; - - /* - * Open a TCP socket - */ - for (tlog = 0; (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0; tlog -= 10) { - berrno be; - if (errno == EINTR || errno == EAGAIN) { - continue; - } - if (tlog <= 0) { - tlog = 2 * 60; - Emsg1(M_ERROR, 0, _("Cannot open stream socket: %s\n"), be.bstrerror()); - } - bmicrosleep(60, 0); - } - - /* - * Reuse old sockets - */ - if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) { - berrno be; - Emsg1(M_WARNING, 0, _("Cannot set SO_REUSEADDR on socket: %s\n"), - be.bstrerror()); - } - - /* - * Bind our local address so that the client can send to us. - */ - bzero((char *)&serv_addr, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); - serv_addr.sin_port = htons(port); - - for (tlog = 0; bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0; - tlog -= 5) { - berrno be; - if (errno == EINTR || errno == EAGAIN) { - continue; - } - if (tlog <= 0) { - tlog = 2 * 60; - Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s: retrying ...\n"), port, - be.bstrerror()); - } - bmicrosleep(5, 0); - } - listen(sockfd, 1); /* tell system we are ready */ - return init_bsock(NULL, sockfd, _("Server socket"), _("client"), port, - &serv_addr); -} - -/* - * Accept a single connection - */ -BSOCK *bnet_accept(BSOCK * bsock, char *who) -{ - fd_set ready, sockset; - int newsockfd, stat, len; - socklen_t clilen; - struct sockaddr_in cli_addr; /* client's address */ - char *caller, *buf; - BSOCK *bs; - int turnon = 1; -#ifdef HAVE_LIBWRAP - struct request_info request; -#endif - - /* - * Wait for a connection from the client process. - */ - FD_ZERO(&sockset); - FD_SET((unsigned)bsock->fd, &sockset); - - for (;;) { - /* - * Wait for a connection from a client process. - */ - ready = sockset; - if ((stat = select(bsock->fd + 1, &ready, NULL, NULL, NULL)) < 0) { - berrno be; - if (errno == EINTR || errno = EAGAIN) { - errno = 0; - continue; - } - Emsg1(M_FATAL, 0, _("Error in select: %s\n"), be.bstrerror()); - newsockfd = -1; - break; - } - do { - clilen = sizeof(cli_addr); - newsockfd = accept(bsock->fd, (struct sockaddr *)&cli_addr, &clilen); - } while (newsockfd < 0 && (errno == EINTR || errno = EAGAIN)); - if (newsockfd >= 0) { - break; - } - } - -#ifdef HAVE_LIBWRAP - P(mutex); - request_init(&request, RQ_DAEMON, my_name, RQ_FILE, newsockfd, 0); - fromhost(&request); - if (!hosts_access(&request)) { - V(mutex); - Emsg2(M_SECURITY, 0, _("Connection from %s:%d refused by hosts.access\n"), - inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port)); - close(newsockfd); - return NULL; - } - V(mutex); -#endif - - /* - * Receive notification when connection dies. - */ - if (setsockopt(newsockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) { - berrno be; - Emsg1(M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"), - be.bstrerror()); - } - - /* see who client is. I.e. who connected to us. - * return it in the input message buffer. - */ - if ((caller = inet_ntoa(cli_addr.sin_addr)) != NULL) { - pm_strcpy(&bsock->msg, caller); - } else { - bsock->msg[0] = 0; - } - bsock->msglen = strlen(bsock->msg); - - if (newsockfd < 0) { - berrno be; - Emsg2(M_FATAL, 0, _("Socket accept error for %s. ERR=%s\n"), who, - be.bstrerror()); - return NULL; - } else { - if (caller == NULL) { - caller = _("unknown"); - } - len = strlen(caller) + strlen(who) + 3; - buf = (char *)malloc(len); - bstrncpy(buf, len, who); - bstrncat(buf, len, ": "); - bstrncat(buf, len, caller); - bs = init_bsock(NULL, newsockfd, _("client"), buf, bsock->port, &cli_addr); - free(buf); - return bs; /* return new BSOCK */ - } -} - -#endif diff --git a/bacula/src/lib/daemon.c b/bacula/src/lib/daemon.c index 16196e0309..5bfd7f84d7 100644 --- a/bacula/src/lib/daemon.c +++ b/bacula/src/lib/daemon.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -26,11 +26,11 @@ Switzerland, email:ftf@fsfeurope.org. */ /* - * daemon.c by Kern Sibbald + * daemon.c by Kern Sibbald 2000 * * Version $Id$ * - * this code is inspired by the Prentice Hall book + * This code is inspired by the Prentice Hall book * "Unix Network Programming" by W. Richard Stevens * and later updated from his book "Advanced Programming * in the UNIX Environment" @@ -63,7 +63,7 @@ daemon_start() Dmsg0(900, "Enter daemon_start\n"); if ( (cpid = fork() ) < 0) { berrno be; - Emsg1(M_ABORT, 0, _("Cannot fork to become daemon: %s\n"), be.bstrerror()); + Emsg1(M_ABORT, 0, _("Cannot fork to become daemon: ERR=%s\n"), be.bstrerror()); } else if (cpid > 0) { exit(0); /* parent exits */ } diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index e3db2c7c7e..5e6c75bfca 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/src/stored/reserve.c b/bacula/src/stored/reserve.c index 6911c9ad89..59084d4bc3 100644 --- a/bacula/src/stored/reserve.c +++ b/bacula/src/stored/reserve.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -82,7 +82,10 @@ static int my_compare(void *item1, void *item2) return strcmp(((VOLRES *)item1)->vol_name, ((VOLRES *)item2)->vol_name); } - +/* + * This allows a given thread to recursively call lock_reservations. + * It must, of course, call unlock_... the same number of times. + */ void init_reservations_lock() { int errstat; @@ -132,6 +135,9 @@ void _unlock_reservations() int vol_list_lock_count = 0; +/* + * This allows a given thread to recursively call to lock_volumes() + */ void _lock_volumes() { int errstat; @@ -330,6 +336,11 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName) Dmsg1(dbglvl, "OK, vol=%s on device.\n", VolumeName); goto get_out; /* Volume already on this device */ } else { + /* Don't release a volume if it is in use */ + if (!vol->released) { + vol = NULL; /* vol in use */ + goto get_out; + } Dmsg2(dbglvl, "reserve_vol free vol=%s at %p\n", vol->vol_name, vol->vol_name); unload_autochanger(dcr, -1); /* unload the volume */ free_volume(dev); @@ -393,6 +404,7 @@ get_out: /* * Switch from current device to given device + * (not yet used) */ void switch_device(DCR *dcr, DEVICE *dev) { @@ -467,8 +479,12 @@ void unreserve_device(DCR *dcr) /* * Free a Volume from the Volume list if it is no longer used + * Note, for tape drives we want to remember where the Volume + * was when last used, so rather than free the volume entry, + * we simply mark it "released" so when the drive is really + * needed for another volume, we can reuse it. * - * Returns: true if the Volume found and removed from the list + * Returns: true if the Volume found and "removed" from the list * false if the Volume is not in the list or is in use */ bool volume_unused(DCR *dcr) @@ -502,7 +518,7 @@ bool volume_unused(DCR *dcr) } /* - * Unconditionally release the volume + * Unconditionally release the volume entry */ bool free_volume(DEVICE *dev) { @@ -953,8 +969,9 @@ bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx) free_volume_list(); /* release temp_vol_list */ vol_list = save_vol_list; Dmsg0(dbglvl, "deleted temp vol list\n"); - Dmsg0(dbglvl, "lock volumes\n"); + Dmsg0(dbglvl, "unlock volumes\n"); unlock_volumes(); + debug_list_volumes("=== After free temp table\n"); } if (ok) { Dmsg1(dbglvl, "got vol %s from in-use vols list\n", rctx.VolumeName); diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 274ec0a653..1d35512bfb 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -1,18 +1,24 @@ Technical notes on version 2.3 General: +05Jan08 +kes Fix reserve_volume() so it doesn't release a volume in use + (i.e. a volume entry not marked released). This should be + the last part needed to fix bug #1018. 02Jan08 -kes Fix exist switch drive SD code to call autochanger to release +kes Fix existing switch drive SD code to call autochanger to release any old volume. This must be done to keep the autochanger from releasing subsequently newly reserved volumes in doing a close(). + This should fix bug #1018. kes Fail if attempting to get console input in batch mode. This should help fail RunScript console commands that are incomplete. kes First cut implementing switch_drive() in SD (not actually called). 31Dec07 kes Implement first cut running console commands in a RunScript. 29Dec07 -ebl Fixes #1028 where "Selection Type" option was not usable with JobDefs. -ebl Fixes #897 and #1005 where bacula doesn't display runscript +ebl Fixes bug #1028 where "Selection Type" option was not usable + with JobDefs. +ebl Fixes bug #897 and bug #1005 where bacula doesn't display runscript output in error. 24Dec07 kes Add new free_tls() entry point so that Win32 builds. -- 2.39.2