Example #1
0
/*
 * Generic setup for performing a backup.
 */
static bRC setup_backup(bpContext *ctx, void *value)
{
   plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext;

   if (!p_ctx || !value) {
      return bRC_Error;
   }

   if (connect_to_cephfs(ctx) != bRC_OK) {
      return bRC_Error;
   }

   /*
    * Setup the directory we need to start scanning by setting the filetype
    * to FT_DIRBEGIN e.g. same as recursing into directory and let the recurse
    * logic do the rest of the work.
    */
   p_ctx->type = FT_DIRBEGIN;
   if (p_ctx->basedir && strlen(p_ctx->basedir) > 0) {
      pm_strcpy(p_ctx->next_filename, p_ctx->basedir);
   } else {
      pm_strcpy(p_ctx->next_filename, "/");
   }

   return bRC_OK;
}
Example #2
0
/*
 * Walk the tree of selected files for restore and lookup the
 * correct fileid. Return the actual full pathname of the file
 * corresponding to the given fileid.
 */
static inline char *lookup_fileindex(JCR *jcr, int32_t FileIndex)
{
   TREE_NODE *node, *parent;
   POOL_MEM restore_pathname, tmp;

   node = first_tree_node(jcr->restore_tree_root);
   while (node) {
      /*
       * See if this is the wanted FileIndex.
       */
      if (node->FileIndex == FileIndex) {
         pm_strcpy(restore_pathname, node->fname);

         /*
          * Walk up the parent until we hit the head of the list.
          */
         for (parent = node->parent; parent; parent = parent->parent) {
            pm_strcpy(tmp, restore_pathname.c_str());
            Mmsg(restore_pathname, "%s/%s", parent->fname, tmp.c_str());
         }

         if (bstrncmp(restore_pathname.c_str(), "/@NDMP/", 7)) {
            return bstrdup(restore_pathname.c_str());
         }
      }

      node = next_tree_node(node);
   }

   return NULL;
}
Example #3
0
static int result_handler(void *ctx, int fields, char **row)
{
   Bvfs *vfs = (Bvfs *)ctx;
   ATTR *attr = vfs->get_attr();
   char empty[] = "A A A A A A A A A A A A A A";

   memset(&attr->statp, 0, sizeof(struct stat));
   decode_stat((row[BVFS_LStat] && row[BVFS_LStat][0])?row[BVFS_LStat]:empty,
               &attr->statp, sizeof(attr->statp),  &attr->LinkFI);

   if (bvfs_is_dir(row) || bvfs_is_file(row)) {
      /* display clean stuffs */

      if (bvfs_is_dir(row)) {
         pm_strcpy(attr->ofname, bvfs_basename_dir(row[BVFS_Name]));
      } else {
         /* if we see the requested file, note his filenameid */
         if (bstrcmp(row[BVFS_Name], file)) {
            fnid = str_to_int64(row[BVFS_FilenameId]);
         }
         pm_strcpy(attr->ofname, row[BVFS_Name]);
      }
      print_ls_output(vfs->get_jcr(), attr);

   } else {
      Pmsg5(0, "JobId=%s FileId=%s\tMd5=%s\tVolName=%s\tVolInChanger=%s\n",
            row[BVFS_JobId], row[BVFS_FileId], row[BVFS_Md5], row[BVFS_VolName],
            row[BVFS_VolInchanger]);

      pm_strcpy(attr->ofname, file);
      print_ls_output(vfs->get_jcr(), attr);
   }
   return 0;
}
Example #4
0
File: askdir.c Project: AlD/bareos
bool dir_update_changer(JCR *jcr, AUTOCHANGER *changer)
{
   BSOCK *dir = jcr->dir_bsock;
   POOL_MEM dev_name, MediaType;
   DEVRES *device;
   bool ok;

   pm_strcpy(dev_name, changer->hdr.name);
   bash_spaces(dev_name);
   device = (DEVRES *)changer->device->first();
   pm_strcpy(MediaType, device->media_type);
   bash_spaces(MediaType);
   /* This is mostly to indicate that we are here */
   ok = dir->fsend(Device_update,
      jcr->Job,
      dev_name.c_str(),         /* Changer name */
      0, 0, 0,                  /* append, read, num_writers */
      0, 0, 0,                  /* is_open, is_labeled, offline */
      0, 0,                     /* reserved, max_writers */
      0,                        /* Autoselect */
      changer->device->size(),  /* Number of devices */
      "0",                      /* PoolId */
      "*",                      /* ChangerName */
      MediaType.c_str(),        /* MediaType */
      "*");                     /* VolName */
   Dmsg1(dbglvl, ">dird: %s\n", dir->msg);
   return ok;
}
Example #5
0
/*
 * Get or create a Client record for this Job
 */
bool get_or_create_client_record(JCR *jcr)
{
   CLIENT_DBR cr;

   memset(&cr, 0, sizeof(cr));
   bstrncpy(cr.Name, jcr->client->hdr.name, sizeof(cr.Name));
   cr.AutoPrune = jcr->client->AutoPrune;
   cr.FileRetention = jcr->client->FileRetention;
   cr.JobRetention = jcr->client->JobRetention;
   if (!jcr->client_name) {
      jcr->client_name = get_pool_memory(PM_NAME);
   }
   pm_strcpy(jcr->client_name, jcr->client->hdr.name);
   if (!db_create_client_record(jcr, jcr->db, &cr)) {
      Jmsg(jcr, M_FATAL, 0, _("Could not create Client record. ERR=%s\n"),
         db_strerror(jcr->db));
      return false;
   }
   jcr->jr.ClientId = cr.ClientId;
   if (cr.Uname[0]) {
      if (!jcr->client_uname) {
         jcr->client_uname = get_pool_memory(PM_NAME);
      }
      pm_strcpy(jcr->client_uname, cr.Uname);
   }
   Dmsg2(100, "Created Client %s record %d\n", jcr->client->hdr.name,
      jcr->jr.ClientId);
   return true;
}
Example #6
0
void make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &archive_name)
{
   /* Use the working directory if spool directory is not defined */
   if (dev->device->spool_directory) {
      pm_strcpy(archive_name, dev->device->spool_directory);
   } else {
      pm_strcpy(archive_name, working_directory);
   }
   add_file_and_part_name(dev, archive_name);
}      
Example #7
0
/* Convert ActionOnPurge to string (Truncate, Erase, Destroy)
 */
char *action_on_purge_to_string(int aop, POOL_MEM &ret)
{
   if (aop & ON_PURGE_TRUNCATE) {
      pm_strcpy(ret, _("Truncate"));
   }
   if (!aop) {
      pm_strcpy(ret, _("None"));
   }
   return ret.c_str();
}
Example #8
0
/*
 * See in the tree with selected files what files were selected to be restored.
 */
static inline int set_files_to_restore(JCR *jcr, struct ndm_job_param *job, int32_t FileIndex,
                                       const char *restore_prefix, const char *ndmp_filesystem)
{
   int len;
   int cnt = 0;
   TREE_NODE *node, *parent;
   POOL_MEM restore_pathname, tmp;

   node = first_tree_node(jcr->restore_tree_root);
   while (node) {
      /*
       * See if this is the wanted FileIndex and the user asked to extract it.
       */
      if (node->FileIndex == FileIndex && node->extract) {
         pm_strcpy(restore_pathname, node->fname);

         /*
          * Walk up the parent until we hit the head of the list.
          */
         for (parent = node->parent; parent; parent = parent->parent) {
            pm_strcpy(tmp, restore_pathname.c_str());
            Mmsg(restore_pathname, "%s/%s", parent->fname, tmp.c_str());
         }

         /*
          * We only want to restore the non pseudo NDMP names e.g. not the full backup stream name.
          */
         if (!bstrncmp(restore_pathname.c_str(), "/@NDMP/", 7)) {
            /*
             * See if we need to strip the prefix from the filename.
             */
            len = strlen(ndmp_filesystem);
            if (bstrncmp(restore_pathname.c_str(), ndmp_filesystem, len)) {
               add_to_namelist(job,  restore_pathname.c_str() + len, restore_prefix,
                               (char *)"", (char *)"", NDMP_INVALID_U_QUAD);
            } else {
               add_to_namelist(job,  restore_pathname.c_str(), restore_prefix,
                               (char *)"", (char *)"", NDMP_INVALID_U_QUAD);
            }
            cnt++;
         }
      }

      node = next_tree_node(node);
   }

   return cnt;
}
Example #9
0
/*
 * This is called during restore to create the file (if necessary)
 * We must return in rp->create_status:
 *   
 *  CF_ERROR    -- error
 *  CF_SKIP     -- skip processing this file
 *  CF_EXTRACT  -- extract the file (i.e.call i/o routines)
 *  CF_CREATED  -- created, but no content to extract (typically directories)
 *
 */
static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
{
   delta_test *self = get_self(ctx);
   pm_strcpy(self->fname, rp->ofname);
   rp->create_status = CF_EXTRACT;
   return bRC_OK;
}
Example #10
0
/*
 * resolve a host on a storage daemon
 */
bool do_storage_resolve(UAContext *ua, STORERES *store)
{
   BSOCK *sd;
   USTORERES lstore;

   lstore.store = store;
   pm_strcpy(lstore.store_source, _("unknown source"));
   set_wstorage(ua->jcr, &lstore);

   if (!(sd = open_sd_bsock(ua))) {
      return false;
   }

   for (int i = 1; i < ua->argc; i++) {
       if (!*ua->argk[i]) {
          continue;
       }

       sd->fsend("resolve %s", ua->argk[i]);
       while (sd->recv() >= 0) {
          ua->send_msg("%s", sd->msg);
       }
   }

   sd->signal(BNET_TERMINATE);
   sd->close();
   ua->jcr->store_bsock = NULL;

   return true;
}
Example #11
0
/*
 * User selected a row
 */
static void select_row_cb(GtkCList *item, gint row, gint column,
             GdkEventButton *event, Window *restore)
{
   char *file;
   char *marked = NULL;
   /* Column non-negative => double click */
   if (column >= 0) {
      gtk_clist_unselect_row(item, row, column);
      /* Double click on column 0 means to mark or unmark */
      if (column == 0) {
         gtk_clist_get_text(restore->list, row, CHECK_COLUMN, &marked);
         Dmsg1(200, "Marked=%s\n", marked);
         if (!marked || strcmp(marked, "x") != 0) {
            mark_row(row, true);
         } else {
            mark_row(row, false);
         }
      } else {
      /* Double clicking on directory means to move to it */
         int len;
         gtk_clist_get_text(item, row, FILE_COLUMN, &file);
         len = strlen(file);
         if (len > 0 && file[len-1] == '/') {
            /* Change to new directory */
            pm_strcpy(restore->path, restore->fname);
            if (*file == '*') {
               Mmsg(restore->fname, "%s%s", restore->path, file+1);
            } else {
               Mmsg(restore->fname, "%s%s", restore->path, file);
            }
            FillDirectory(restore->fname, restore);
         }
      }
   }
}
Example #12
0
/* 
 * Start the backup of a specific file
 */
static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp)
{
   delta_test *self = get_self(ctx);
   if (!self) {
      return bRC_Error;
   }
   time_t now = time(NULL);
   sp->fname = (char *)"/delta.txt";
   sp->type = FT_REG;
   sp->statp.st_mode = 0700 | S_IFREG;
   sp->statp.st_ctime = now;
   sp->statp.st_mtime = now;
   sp->statp.st_atime = now;
   sp->statp.st_size = -1;
   sp->statp.st_blksize = 4096;
   sp->statp.st_blocks = 1;
   if (self->level == 'I' || self->level == 'D') {
      bRC state = bfuncs->checkChanges(ctx, sp);
      /* Should always be bRC_OK */
      sp->type = (state == bRC_Seen)? FT_NOCHG : FT_REG;
      sp->flags |= (FO_DELTA|FO_OFFSETS);
      self->delta = sp->delta_seq + 1;
   }
   pm_strcpy(self->fname, files[self->delta % nb_files]);
   Dmsg(ctx, dbglvl, "delta-test-fd: delta_seq=%i delta=%i fname=%s\n", 
        sp->delta_seq, self->delta, self->fname);
// Dmsg(ctx, dbglvl, "delta-test-fd: startBackupFile\n");
   return bRC_OK;
}
Example #13
0
void writecmd(monitoritem* item, const char* command) {
   if (item->D_sock) {
      item->D_sock->msglen = strlen(command);
      pm_strcpy(&item->D_sock->msg, command);
      item->D_sock->send();
   }
}
Example #14
0
File: tree.c Project: AlD/bareos
static void tree_getpath_item(TREE_NODE *node, POOLMEM **path)
{
   if (!node) {
      return;
   }

   tree_getpath_item(node->parent, path);

   /*
    * Fixup for Win32. If we have a Win32 directory and
    * there is only a / in the buffer, remove it since
    * win32 names don't generally start with /
    */
   if (node->type == TN_DIR_NLS && IsPathSeparator((*path[0])) && (*path)[1] == '\0') {
      pm_strcpy(path, "");
   }
   pm_strcat(path, node->fname);

   /*
    * Add a slash for all directories unless we are at the root,
    * also add a slash to a soft linked file if it has children
    * i.e. it is linked to a directory.
    */
   if ((node->type != TN_FILE && !(IsPathSeparator((*path)[0]) && (*path)[1] == '\0')) ||
       (node->soft_link && tree_node_has_child(node))) {
      pm_strcat(path, "/");
   }
}
Example #15
0
/*
 * Format a scanner warning message
 */
static void s_warn(const char *file, int line, LEX *lc, const char *msg, ...)
{
   va_list ap;
   int len, maxlen;
   POOL_MEM buf(PM_NAME),
            more(PM_NAME);

   while (1) {
      maxlen = buf.size() - 1;
      va_start(ap, msg);
      len = bvsnprintf(buf.c_str(), maxlen, msg, ap);
      va_end(ap);

      if (len < 0 || len >= (maxlen - 5)) {
         buf.realloc_pm(maxlen + maxlen / 2);
         continue;
      }

      break;
   }

   if (lc->line_no > lc->begin_line_no) {
      Mmsg(more, _("Problem probably begins at line %d.\n"), lc->begin_line_no);
   } else {
      pm_strcpy(more, "");
   }

   if (lc->line_no > 0) {
      p_msg(file, line, 0, _("Config warning: %s\n"
                             "            : line %d, col %d of file %s\n%s\n%s"),
            buf.c_str(), lc->line_no, lc->col_no, lc->fname, lc->line, more.c_str());
   } else {
      p_msg(file, line, 0, _("Config warning: %s\n"), buf.c_str());
   }
}
Example #16
0
/*
 * Update File Attributes in the catalog with data sent by the Storage daemon.
 */
void catalog_update(JCR *jcr, BSOCK *bs)
{
   if (!jcr->res.pool->catalog_files) {
      return;                         /* user disabled cataloging */
   }

   if (jcr->is_job_canceled()) {
      goto bail_out;
   }

   if (!jcr->db) {
      POOLMEM *omsg = get_memory(bs->msglen+1);
      pm_strcpy(omsg, bs->msg);
      bs->fsend(_("1994 Invalid Catalog Update: %s"), omsg);
      Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog Update; DB not open: %s"), omsg);
      free_memory(omsg);
      goto bail_out;
   }

   update_attribute(jcr, bs->msg, bs->msglen);

bail_out:
   if (jcr->is_job_canceled()) {
      cancel_storage_daemon_job(jcr);
   }
}
Example #17
0
void bmsg(UAContext *ua, const char *fmt, va_list arg_ptr)
{
   BSOCK *bs = ua->UA_sock;
   int maxlen, len;
   POOLMEM *msg = NULL;

   if (bs) {
      msg = bs->msg;
   }
   if (!msg) {
      msg = get_memory(5000);
   }

   maxlen = sizeof_pool_memory(msg) - 1;
   if (maxlen < 4999) {
      msg = realloc_pool_memory(msg, 5000);
      maxlen = 4999;
   }
   len = bvsnprintf(msg, maxlen, fmt, arg_ptr);
   if (len < 0 || len >= maxlen) {
      pm_strcpy(msg, _("Message too long to display.\n"));
      len = strlen(msg);
   }

   if (bs) {
      bs->msg = msg;
      bs->msglen = len;
      bs->send();
   } else {                           /* No UA, send to Job */
      Jmsg(ua->jcr, M_INFO, 0, "%s", msg);
      free_pool_memory(msg);
   }

}
Example #18
0
void MonitorItem::writecmd(const char* command)
{
   if (d->DSock) {
      d->DSock->msglen = pm_strcpy(&d->DSock->msg, command);
      bnet_send(d->DSock);
   }
}
Example #19
0
int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr)
{
   char *p;
   /*
    * An Attributes record consists of:
    *    File_index
    *    Type   (FT_types)
    *    Filename
    *    Attributes
    *    Link name (if file linked i.e. FT_LNK)
    *    Extended attributes (Win32)
    *  plus optional values determined by AR_ flags in upper bits of Type
    *    Data_stream
    *
    */
   attr->stream = stream;
   Dmsg1(400, "Attr: %s\n", rec);
   if (sscanf(rec, "%d %d", &attr->file_index, &attr->type) != 2) {
      Jmsg(jcr, M_FATAL, 0, _("Error scanning attributes: %s\n"), rec);
      Dmsg1(100, "\nError scanning attributes. %s\n", rec);
      return 0;
   }
   Dmsg2(400, "Got Attr: FilInx=%d type=%d\n", attr->file_index, attr->type);
   if (attr->type & AR_DATA_STREAM) {
      attr->data_stream = 1;
   } else {
      attr->data_stream = 0;
   }
   attr->type &= FT_MASK;             /* keep only type bits */
   p = rec;
   while (*p++ != ' ')               /* skip record file index */
      { }
   while (*p++ != ' ')               /* skip type */
      { }

   attr->fname = p;                   /* set filname position */
   while (*p++ != 0)                  /* skip filename */
      { }
   attr->attr = p;                    /* set attributes position */
   while (*p++ != 0)                  /* skip attributes */
      { }
   attr->lname = p;                   /* set link position */
   while (*p++ != 0)                  /* skip link */
      { }
   pm_strcpy(attr->attrEx, p);        /* copy extended attributes, if any */

   if (attr->data_stream) {
      int64_t val;
      while (*p++ != 0)               /* skip extended attributes */
         { }
      from_base64(&val, p);
      attr->data_stream = (int32_t)val;
   }
   Dmsg7(400, "unpack_attr FI=%d Type=%d fname=%s attr=%s lname=%s attrEx=%s ds=%d\n",
      attr->file_index, attr->type, attr->fname, attr->attr, attr->lname,
      attr->attrEx, attr->data_stream);
   *attr->ofname = 0;
   *attr->olname = 0;
   return 1;
}
Example #20
0
static inline bool script_dir_allowed(JCR *jcr, RUNSCRIPT *script, alist *allowed_script_dirs)
{
   char *bp, *allowed_script_dir;
   bool allowed = false;
   POOL_MEM script_dir(PM_FNAME);

   /*
    * If there is no explicit list of allowed dirs allow any dir.
    */
   if (!allowed_script_dirs) {
      return true;
   }

   /*
    * Determine the dir the script is in.
    */
   pm_strcpy(script_dir, script->command);
   if ((bp = strrchr(script_dir.c_str(), '/'))) {
      *bp = '\0';
   }

   /*
    * Match the path the script is in against the list of allowed script directories.
    */
   foreach_alist(allowed_script_dir, allowed_script_dirs) {
      if (bstrcasecmp(script_dir.c_str(), allowed_script_dir)) {
         allowed = true;
         break;
      }
   }

   return allowed;
}
Example #21
0
/*
 * Create a connection string for connecting to the master database.
 */
static void set_ado_connect_string(bpContext *ctx)
{
   POOL_MEM ado_connect_string(PM_NAME);
   plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext;

   if (bstrcasecmp(p_ctx->instance, DEFAULT_INSTANCE)) {
      pm_strcpy(ado_connect_string,
                "Provider=SQLOLEDB.1;Data Source=localhost;Initial Catalog=master");
   } else {
      Mmsg(ado_connect_string,
           "Provider=SQLOLEDB.1;Data Source=localhost\\%s;Initial Catalog=master",
           p_ctx->instance);
   }

   /*
    * See if we need to use a username/password or a trusted connection.
    */
   if (p_ctx->username && p_ctx->password) {
      POOL_MEM temp(PM_NAME);

      Mmsg(temp, ";User Id=%s;Password=%s;",
            p_ctx->username, p_ctx->password);
      pm_strcat(ado_connect_string, temp.c_str());
   } else {
      pm_strcat(ado_connect_string, ";Integrated Security=SSPI;");
   }

   Dmsg(ctx, dbglvl, "set_ado_connect_string: ADO Connect String '%s'\n", ado_connect_string.c_str());

   if (p_ctx->ado_connect_string) {
      free(p_ctx->ado_connect_string);
   }
   p_ctx->ado_connect_string = bstrdup(ado_connect_string.c_str());
}
Example #22
0
static void do_storage_cmd(UAContext *ua, STORERES *store, const char *cmd)
{
   BSOCK *sd;
   JCR *jcr = ua->jcr;
   USTORERES lstore;

   lstore.store = store;
   pm_strcpy(lstore.store_source, _("unknown source"));
   set_wstorage(jcr, &lstore);

   if (!(sd = open_sd_bsock(ua))) {
      ua->error_msg(_("Could not open SD socket.\n"));
      return;
   }

   Dmsg0(120, _("Connected to storage daemon\n"));
   sd = jcr->store_bsock;
   sd->fsend("%s", cmd);
   if (sd->recv() >= 0) {
      ua->send_msg("%s", sd->msg);
   }

   close_sd_bsock(ua);
   return;
}
Example #23
0
/*
 * Add a filename to the files we want to restore.
 *
 * The RFC says this:
 *
 * original_path - The original path name of the data to be recovered,
 *                 relative to the backup root. If original_path is the null
 *                 string, the server shall recover all data contained in the
 *                 backup image.
 *
 * destination_path, name, other_name
 *               - Together, these identify the absolute path name to which
 *                 data are to be recovered.
 *
 *               If name is the null string:
 *                 - destination_path identifies the name to which the data
 *                   identified by original_path are to be recovered.
 *                 - other_name must be the null string.
 *
 *               If name is not the null string:
 *                 - destination_path, when concatenated with the server-
 *                   specific path name delimiter and name, identifies the
 *                   name to which the data identified by original_path are
 *                   to be recovered.
 *
 *               If other_name is not the null string:
 *                 - destination_path, when concatenated with the server-
 *                   specific path name delimiter and other_name,
 *                   identifies the alternate name-space name of the data
 *                   to be recovered. The definition of such alternate
 *                   name-space is server-specific.
 *
 * Neither name nor other_name may contain a path name delimiter.
 *
 * Under no circumstance may destination_path be the null string.
 *
 * If intermediate directories that lead to the path name to
 * recover do not exist, the server should create them.
 */
static inline void add_to_namelist(struct ndm_job_param *job,
                                   char *filename,
                                   const char *restore_prefix,
                                   char *name,
                                   char *other_name,
                                   int64_t node)
{
   ndmp9_name nl;
   POOL_MEM destination_path;

   memset(&nl, 0, sizeof(ndmp9_name));

   /*
    * See if the filename is an absolute pathname.
    */
   if (*filename == '\0') {
      pm_strcpy(destination_path, restore_prefix);
   } else if (*filename == '/') {
      Mmsg(destination_path, "%s%s", restore_prefix, filename);
   } else {
      Mmsg(destination_path, "%s/%s", restore_prefix, filename);
   }

   nl.original_path = filename;
   nl.destination_path = destination_path.c_str();
   nl.name = name;
   nl.other_name = other_name;
   nl.node = node;

   ndma_store_nlist(&job->nlist_tab, &nl);
}
Example #24
0
static int send_volume_info_to_storage_daemon(JCR *jcr, BSOCK *sd, MEDIA_DBR *mr)
{
   int status;
   char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50], ed6[50];

   jcr->MediaId = mr->MediaId;
   pm_strcpy(jcr->VolumeName, mr->VolumeName);
   bash_spaces(mr->VolumeName);
   status = sd->fsend(OK_media, mr->VolumeName, mr->VolJobs,
      mr->VolFiles, mr->VolBlocks, edit_uint64(mr->VolBytes, ed1),
      mr->VolMounts, mr->VolErrors, mr->VolWrites,
      edit_uint64(mr->MaxVolBytes, ed2),
      edit_uint64(mr->VolCapacityBytes, ed3),
      mr->VolStatus, mr->Slot, mr->MaxVolJobs, mr->MaxVolFiles,
      mr->InChanger,
      edit_int64(mr->VolReadTime, ed4),
      edit_int64(mr->VolWriteTime, ed5),
      mr->EndFile, mr->EndBlock,
      mr->LabelType,
      edit_uint64(mr->MediaId, ed6),
      mr->EncrKey, mr->MinBlocksize, mr->MaxBlocksize);
   unbash_spaces(mr->VolumeName);
   Dmsg2(100, "Vol Info for %s: %s", jcr->Job, sd->msg);
   return status;
}
Example #25
0
/*
 * Return 1 if OK
 *        0 if no input
 *       -1 error (must stop)
 */
int get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
{
   static char *line = NULL;
   static char *next = NULL;
   static int do_history = 0;
   char *command;

   if (line == NULL) {
      do_history = 0;
      rl_catch_signals = 0;              /* do it ourselves */
      /* Here, readline does ***real*** malloc
       * so, be we have to use the real free
       */
      line = readline((char *)prompt);   /* cast needed for old readlines */
      if (!line) {
         return -1;                      /* error return and exit */
      }
      strip_trailing_junk(line);
      command = line;
   } else if (next) {
      command = next + 1;
   } else {
     sendit(_("Command logic problem\n"));
     sock->msglen = 0;
     sock->msg[0] = 0;
     return 0;                  /* No input */
   }

   /*
    * Split "line" into multiple commands separated by the eol character.
    *   Each part is pointed to by "next" until finally it becomes null.
    */
   if (eol == '\0') {
      next = NULL;
   } else {
      next = strchr(command, eol);
      if (next) {
         *next = '\0';
      }
   }
   if (command != line && isatty(fileno(input))) {
      senditf("%s%s\n", prompt, command);
   }

   sock->msglen = pm_strcpy(&sock->msg, command);
   if (sock->msglen) {
      do_history++;
   }

   if (!next) {
      if (do_history) {
        add_history(line);
      }
      actuallyfree(line);       /* allocated by readline() malloc */
      line = NULL;
   }
   return 1;                    /* OK */
}
Example #26
0
/*
 * Get or create a Client record for this Job
 */
bool get_or_create_client_record(JCR *jcr)
{
   CLIENT_DBR cr;

   memset(&cr, 0, sizeof(cr));
   bstrncpy(cr.Name, jcr->res.client->hdr.name, sizeof(cr.Name));
   cr.AutoPrune = jcr->res.client->AutoPrune;
   cr.FileRetention = jcr->res.client->FileRetention;
   cr.JobRetention = jcr->res.client->JobRetention;
   if (!jcr->client_name) {
      jcr->client_name = get_pool_memory(PM_NAME);
   }
   pm_strcpy(jcr->client_name, jcr->res.client->hdr.name);
   if (!db_create_client_record(jcr, jcr->db, &cr)) {
      Jmsg(jcr, M_FATAL, 0, _("Could not create Client record. ERR=%s\n"),
         db_strerror(jcr->db));
      return false;
   }
   /*
    * Only initialize quota when a Soft or Hard Limit is set.
    */
   if (jcr->res.client->HardQuota != 0 ||
       jcr->res.client->SoftQuota != 0) {
      if (!db_get_quota_record(jcr, jcr->db, &cr)) {
         if (!db_create_quota_record(jcr, jcr->db, &cr)) {
            Jmsg(jcr, M_FATAL, 0, _("Could not create Quota record. ERR=%s\n"),
               db_strerror(jcr->db));
         }
         jcr->res.client->QuotaLimit = 0;
         jcr->res.client->GraceTime = 0;
      }
   }
   jcr->jr.ClientId = cr.ClientId;
   jcr->res.client->QuotaLimit = cr.QuotaLimit;
   jcr->res.client->GraceTime = cr.GraceTime;
   if (cr.Uname[0]) {
      if (!jcr->client_uname) {
         jcr->client_uname = get_pool_memory(PM_NAME);
      }
      pm_strcpy(jcr->client_uname, cr.Uname);
   }
   Dmsg2(100, "Created Client %s record %d\n", jcr->res.client->hdr.name,
      jcr->jr.ClientId);
   return true;
}
Example #27
0
/*
 * Return the string for the error that occurred
 * on the socket. Only the first error is retained.
 */
const char *BSOCK::bstrerror()
{
   berrno be;
   if (errmsg == NULL) {
      errmsg = get_pool_memory(PM_MESSAGE);
   }
   pm_strcpy(errmsg, be.bstrerror(b_errno));
   return errmsg;
}
Example #28
0
/*
 * Create a parent directory using the gfapi.
 */
static inline bool gfapi_makedir(glfs_t *glfs, const char *directory)
{
   char *bp;
   struct stat st;
   bool retval = false;
   POOL_MEM new_directory(PM_FNAME);

   pm_strcpy(new_directory, directory);

   /*
    * See if the parent exists.
    */
   bp = strrchr(new_directory.c_str(), '/');
   if (bp) {
      /*
       * See if we reached the root.
       */
      if (bp == new_directory.c_str()) {
         /*
          * Create the directory.
          */
         if (glfs_mkdir(glfs, directory, 0750) == 0) {
            retval = true;
         }
      } else {
         *bp = '\0';

         if (glfs_stat(glfs, new_directory.c_str(), &st) != 0) {
            switch (errno) {
            case ENOENT:
               /*
                * Make sure our parent exists.
                */
               retval = gfapi_makedir(glfs, new_directory.c_str());
               if (!retval) {
                  return false;
               }

               /*
                * Create the directory.
                */
               if (glfs_mkdir(glfs, directory, 0750) == 0) {
                  retval = true;
               }
               break;
            default:
               break;
            }
         } else {
            retval = true;
         }
      }
   }

   return retval;
}
Example #29
0
File: dev.c Project: dl5rcw/bareos
/*
 * Open a device.
 */
void DEVICE::open_device(DCR *dcr, int omode)
{
   POOL_MEM archive_name(PM_FNAME);

   get_autochanger_loaded_slot(dcr);

   /*
    * Handle opening of File Archive (not a tape)
    */
   pm_strcpy(archive_name, dev_name);

   /*
    * If this is a virtual autochanger (i.e. changer_res != NULL) we simply use
    * the device name, assuming it has been appropriately setup by the "autochanger".
    */
   if (!device->changer_res || device->changer_command[0] == 0) {
      if (VolCatInfo.VolCatName[0] == 0) {
         Mmsg(errmsg, _("Could not open file device %s. No Volume name given.\n"),
            print_name());
         clear_opened();
         return;
      }

      if (!IsPathSeparator(archive_name.c_str()[strlen(archive_name.c_str())-1])) {
         pm_strcat(archive_name, "/");
      }
      pm_strcat(archive_name, getVolCatName());
   }

   mount(dcr, 1);                     /* do mount if required */

   open_mode = omode;
   set_mode(omode);

   /*
    * If creating file, give 0640 permissions
    */
   Dmsg3(100, "open disk: mode=%s open(%s, 0x%x, 0640)\n", mode_to_str(omode),
         archive_name.c_str(), oflags);

   if ((m_fd = d_open(archive_name.c_str(), oflags, 0640)) < 0) {
      berrno be;
      dev_errno = errno;
      Mmsg2(errmsg, _("Could not open: %s, ERR=%s\n"), archive_name.c_str(),
            be.bstrerror());
      Dmsg1(100, "open failed: %s", errmsg);
   }

   if (m_fd >= 0) {
      dev_errno = 0;
      file = 0;
      file_addr = 0;
   }

   Dmsg1(100, "open dev: disk fd=%d opened\n", m_fd);
}
Example #30
0
/**
 * If requested strip leading components of the path so that we can
 * save file as if it came from a subdirectory.  This is most useful
 * for dealing with snapshots, by removing the snapshot directory, or
 * in handling vendor migrations where files have been restored with
 * a vendor product into a subdirectory.
 */
void strip_path(FF_PKT *ff_pkt)
{
   if (!bit_is_set(FO_STRIPPATH, ff_pkt->flags) || ff_pkt->strip_path <= 0) {
      Dmsg1(200, "No strip for %s\n", ff_pkt->fname);
      return;
   }

   if (!ff_pkt->fname_save) {
     ff_pkt->fname_save = get_pool_memory(PM_FNAME);
     ff_pkt->link_save = get_pool_memory(PM_FNAME);
   }

   pm_strcpy(ff_pkt->fname_save, ff_pkt->fname);
   if (ff_pkt->type != FT_LNK && ff_pkt->fname != ff_pkt->link) {
      pm_strcpy(ff_pkt->link_save, ff_pkt->link);
      Dmsg2(500, "strcpy link_save=%d link=%d\n", strlen(ff_pkt->link_save),
         strlen(ff_pkt->link));
      Dsm_check(200);
   }

   /**
    * Strip path. If it doesn't succeed put it back. If it does, and there
    * is a different link string, attempt to strip the link. If it fails,
    * back them both back. Do not strip symlinks. I.e. if either stripping
    * fails don't strip anything.
    */
   if (!do_strip(ff_pkt->strip_path, ff_pkt->fname)) {
      unstrip_path(ff_pkt);
      goto rtn;
   }

   /**
    * Strip links but not symlinks
    */
   if (ff_pkt->type != FT_LNK && ff_pkt->fname != ff_pkt->link) {
      if (!do_strip(ff_pkt->strip_path, ff_pkt->link)) {
         unstrip_path(ff_pkt);
      }
   }

rtn:
   Dmsg3(100, "fname=%s stripped=%s link=%s\n", ff_pkt->fname_save, ff_pkt->fname, ff_pkt->link);
}