예제 #1
0
static int
fsqueue_envelope_delete(enum queue_kind qkind, struct envelope *ep)
{
	char pathname[MAXPATHLEN];

	if (! bsnprintf(pathname, sizeof(pathname), "%s/%03x/%08x%s/%016llx",
		fsqueue_getpath(qkind),
		evpid_to_msgid(ep->id) & 0xfff,
		evpid_to_msgid(ep->id),
		PATH_ENVELOPES,
		ep->id))
		fatal("fsqueue_envelope_delete: snprintf");

	if (unlink(pathname) == -1) {
		log_debug("######: %s [errno: %d]", pathname, errno);
		fatal("fsqueue_envelope_delete: unlink");
	}

	if (! bsnprintf(pathname, sizeof(pathname), "%s/%03x/%08x%s", PATH_QUEUE,
		evpid_to_msgid(ep->id) & 0xfff,
		evpid_to_msgid(ep->id), PATH_ENVELOPES))
		fatal("fsqueue_envelope_delete: snprintf");

	if (rmdir(pathname) != -1)
		fsqueue_message_delete(qkind, evpid_to_msgid(ep->id));

	return 1;
}
예제 #2
0
static int
fsqueue_message_commit(enum queue_kind qkind, u_int32_t msgid)
{
	char rootdir[MAXPATHLEN];
	char queuedir[MAXPATHLEN];
	char msgdir[MAXPATHLEN];
	
	if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%08x",
		fsqueue_getpath(qkind), msgid))
		fatal("fsqueue_message_commit: snprintf");

	if (! bsnprintf(queuedir, sizeof(queuedir), "%s/%03x",
		fsqueue_getpath(Q_QUEUE), msgid & 0xfff))
		fatal("fsqueue_message_commit: snprintf");

	if (mkdir(queuedir, 0700) == -1) {
		if (errno == ENOSPC)
			return 0;
		if (errno != EEXIST)
			fatal("fsqueue_message_commit: mkdir");
	}

	if (! bsnprintf(msgdir, sizeof(msgdir),"%s/%08x",
		queuedir, msgid))
		fatal("fsqueue_message_commit: snprintf");

	if (rename(rootdir, msgdir) == -1) {
		if (errno == ENOSPC)
			return 0;
		fatal("fsqueue_message_commit: rename");
	}

	return 1;
}
예제 #3
0
파일: edit.c 프로젝트: AlD/bareos
/*
 * Edit a utime "duration" into ASCII
 */
char *edit_utime(utime_t val, char *buf, int buf_len)
{
   char mybuf[200];
   static const int32_t mult[] = {60*60*24*365, 60*60*24*30, 60*60*24, 60*60, 60};
   static const char *mod[]  = {"year",  "month",  "day", "hour", "min"};
   int i;
   uint32_t times;

   *buf = 0;
   for (i=0; i<5; i++) {
      times = (uint32_t)(val / mult[i]);
      if (times > 0) {
         val = val - (utime_t)times * mult[i];
         bsnprintf(mybuf, sizeof(mybuf), "%d %s%s ", times, mod[i], times>1?"s":"");
         bstrncat(buf, mybuf, buf_len);
      }
   }
   if (val == 0 && strlen(buf) == 0) {
      bstrncat(buf, "0 secs", buf_len);
   } else if (val != 0) {
      bsnprintf(mybuf, sizeof(mybuf), "%d sec%s", (uint32_t)val, val>1?"s":"");
      bstrncat(buf, mybuf, buf_len);
   }
   return buf;
}
예제 #4
0
static int
fsqueue_message_create(enum queue_kind qkind, u_int32_t *msgid)
{
	char rootdir[MAXPATHLEN];
	char evpdir[MAXPATHLEN];
	char *queuepath = fsqueue_getpath(qkind);
	char msgpath[MAXPATHLEN];
	char lnkpath[MAXPATHLEN];
	u_int32_t msgid_save;

	msgid_save = *msgid;

again:
	*msgid = (u_int32_t)arc4random();
	if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%08x",
		queuepath, *msgid))
		fatalx("fsqueue_message_create: snprintf");

	if (mkdir(rootdir, 0700) == -1) {
		if (errno == EEXIST)
			goto again;

		if (errno == ENOSPC) {
			*msgid = 0;
			return 0;
		}
		fatal("fsqueue_message_create: mkdir");
	}

	if (! bsnprintf(evpdir, sizeof(evpdir), "%s%s", rootdir,
		PATH_ENVELOPES))
		fatalx("fsqueue_message_create: snprintf");

	if (mkdir(evpdir, 0700) == -1) {
		if (errno == ENOSPC) {
			rmdir(rootdir);
			*msgid = 0;
			return 0;
		}
		fatal("fsqueue_message_create: mkdir");
	}

	if (qkind == Q_BOUNCE) {
		if (! bsnprintf(msgpath, sizeof(msgpath), "%s/%03x/%08x/message",
			fsqueue_getpath(Q_QUEUE),
			msgid_save & 0xfff,
			msgid_save))
			return 0;

		if (! bsnprintf(lnkpath, sizeof(lnkpath), "%s/%08x/message",
			fsqueue_getpath(Q_BOUNCE), *msgid))
			return 0;
		
		if (link(msgpath, lnkpath) == -1)
			fatal("link");
	}

	return 1;
}
예제 #5
0
파일: bsock.c 프로젝트: gearsforwork/bareos
/*
 * Authenticate Director
 */
bool BSOCK::authenticate_with_director(JCR *jcr,
                                       const char *name, s_password &password, tls_t &tls,
                                       char *response, int response_len)
{
   char bashed_name[MAX_NAME_LENGTH];
   BSOCK *dir = this;        /* for readability */

   response[0] = 0;

   /*
    * Send my name to the Director then do authentication
    */
   bstrncpy(bashed_name, name, sizeof(bashed_name));
   bash_spaces(bashed_name);

   /*
    * Timeout Hello after 5 mins
    */
   dir->start_timer(60 * 5);
   dir->fsend(hello, bashed_name);

   if (!authenticate_outbound_connection(jcr, "Director", name, password, tls)) {
      goto bail_out;
   }

   Dmsg1(6, ">dird: %s", dir->msg);
   if (dir->recv() <= 0) {
      dir->stop_timer();
      bsnprintf(response, response_len, _("Bad response to Hello command: ERR=%s\n"
                                          "The Director at \"%s:%d\" is probably not running.\n"),
                dir->bstrerror(), dir->host(), dir->port());
      return false;
   }

   dir->stop_timer();
   Dmsg1(10, "<dird: %s", dir->msg);
   if (!bstrncmp(dir->msg, OKhello, sizeof(OKhello) - 1)) {
      bsnprintf(response, response_len, _("Director at \"%s:%d\" rejected Hello command\n"),
                dir->host(), dir->port());
      return false;
   } else {
      bsnprintf(response, response_len, "%s", dir->msg);
   }

   return true;

bail_out:
   dir->stop_timer();
   bsnprintf(response, response_len, _("Authorization problem with Director at \"%s:%d\"\n"
                                       "Most likely the passwords do not agree.\n"
                                       "If you are using TLS, there may have been a certificate "
                                       "validation error during the TLS handshake.\n"
                                       "Please see %s for help.\n"),
             dir->host(), dir->port(), MANUAL_AUTH_URL);

   return false;
}
예제 #6
0
파일: bfile.c 프로젝트: AlD/bareos
void pause_msg(const char *file, const char *func, int line, const char *msg)
{
   char buf[1000];
   if (msg) {
      bsnprintf(buf, sizeof(buf), "%s:%s:%d %s", file, func, line, msg);
   } else {
      bsnprintf(buf, sizeof(buf), "%s:%s:%d", file, func, line);
   }
   MessageBox(NULL, buf, "Pause", MB_OK);
}
예제 #7
0
static int
fsqueue_envelope_update(enum queue_kind qkind, struct envelope *ep)
{
	char temp[MAXPATHLEN];
	char dest[MAXPATHLEN];
	FILE *fp;
	u_int64_t batch_id;

	batch_id = ep->batch_id;
	ep->batch_id = 0;

	if (! bsnprintf(temp, sizeof(temp), "%s/envelope.tmp", PATH_QUEUE))
		fatalx("fsqueue_envelope_update");

	if (! bsnprintf(dest, sizeof(dest), "%s/%03x/%08x%s/%016llx",
		fsqueue_getpath(qkind),
		evpid_to_msgid(ep->id) & 0xfff,
		evpid_to_msgid(ep->id),
		PATH_ENVELOPES, ep->id))
		fatal("fsqueue_envelope_update: snprintf");

	fp = fopen(temp, "w");
	if (fp == NULL) {
		if (errno == ENOSPC || errno == ENFILE)
			goto tempfail;
		fatal("fsqueue_envelope_update: open");
	}
	if (! fsqueue_dump_envelope_ascii(fp, ep)) {
		if (errno == ENOSPC)
			goto tempfail;
		fatal("fsqueue_dump_envelope_ascii: fwrite");
	}
	if (! safe_fclose(fp))
		goto tempfail;

	if (rename(temp, dest) == -1) {
		if (errno == ENOSPC)
			goto tempfail;
		fatal("fsqueue_envelope_update: rename");
	}

	ep->batch_id = batch_id;
	return 1;

tempfail:
	if (unlink(temp) == -1)
		fatal("fsqueue_envelope_update: unlink");
	if (fp)
		fclose(fp);

	ep->batch_id = batch_id;
	return 0;
}
예제 #8
0
파일: pythonsd.c 프로젝트: halgandd/bacula
int job_setattr(PyObject *self, char *attrname, PyObject *value)
{
  JCR *jcr;
   bool found = false;
   char *strval = NULL;
   char buf[200];
   char *errmsg;
   int i;

   Dmsg2(100, "In job_setattr=%s val=%p.\n", attrname, value);
   if (value == NULL) {                /* Cannot delete variables */
      bsnprintf(buf, sizeof(buf), _("Cannot delete attribute %s"), attrname);
      errmsg = buf;
      goto bail_out;
   }
   jcr = get_jcr_from_PyObject(self);
   if (!jcr) {
      errmsg = _("Job pointer not found.");
      goto bail_out;
   }

   /* Find attribute name in list */
   for (i=0; setvars[i].name; i++) {
      if (strcmp(setvars[i].name, attrname) == 0) {
         found = true;
         break;
      }
   }
   if (!found) {
      goto not_found;
   }
   /* Get argument value ***FIXME*** handle other formats */
   if (setvars[i].fmt != NULL) {
      if (!PyArg_Parse(value, (char *)setvars[i].fmt, &strval)) {
         PyErr_SetString(PyExc_TypeError, _("Read-only attribute"));
         return -1;
      }
   }   
   switch (i) {
   case 0:                            /* JobReport */
      Jmsg(jcr, M_INFO, 0, "%s", strval);
      return 0;
   }
not_found:
   bsnprintf(buf, sizeof(buf), _("Cannot find attribute %s"), attrname);
   errmsg = buf;
bail_out:
   PyErr_SetString(PyExc_AttributeError, errmsg);
   return -1;
}
예제 #9
0
int
queue_message_incoming_path(uint32_t msgid, char *buf, size_t len)
{
	return bsnprintf(buf, len, "%s/%08x",
	    PATH_INCOMING,
	    msgid);
}
예제 #10
0
void ItemFormatterBase::setPercent(int index, float value)
{
   char buf[100];
   bsnprintf(buf, sizeof(buf), "%.2f%%", value);
   QString val = buf;
   QString pix;
   if (value < 8) {
      pix = ":images/0p.png";
   } else if (value < 24) {
      pix = ":images/16p.png";
   } else if (value < 40) {
      pix = ":images/32p.png";
   } else if (value < 56) {
      pix = ":images/48p.png";
   } else if (value < 72) {
      pix = ":images/64p.png";
   } else if (value < 88) {
      pix = ":images/80p.png";
   } else {
      pix = ":images/96p.png";
   }
   setPixmap(index, QPixmap(pix), val);
   //setSortValue(index, (int) value);
   //setBackground(index, Qt::green);
}
예제 #11
0
파일: askdir.c 프로젝트: AlD/bareos
/**
 * Update File Attribute data
 * We do the following:
 *  1. expand the bsock buffer to be large enough
 *  2. Write a "header" into the buffer with serialized data
 *    VolSessionId
 *    VolSeesionTime
 *    FileIndex
 *    Stream
 *    data length that follows
 *    start of raw byte data from the Device record.
 * Note, this is primarily for Attribute data, but can
 *   also handle any device record. The Director must know
 *   the raw byte data format that is defined for each Stream.
 * Now Restore Objects pass through here STREAM_RESTORE_OBJECT
 */
bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec)
{
   JCR *jcr = dcr->jcr;
   BSOCK *dir = jcr->dir_bsock;
   ser_declare;

#ifdef NO_ATTRIBUTES_TEST
   return true;
#endif

   dir->msg = check_pool_memory_size(dir->msg, sizeof(FileAttributes) +
                MAX_NAME_LENGTH + sizeof(DEV_RECORD) + rec->data_len + 1);
   dir->msglen = bsnprintf(dir->msg, sizeof(FileAttributes) +
                MAX_NAME_LENGTH + 1, FileAttributes, jcr->Job);
   ser_begin(dir->msg + dir->msglen, 0);
   ser_uint32(rec->VolSessionId);
   ser_uint32(rec->VolSessionTime);
   ser_int32(rec->FileIndex);
   ser_int32(rec->Stream);
   ser_uint32(rec->data_len);
   ser_bytes(rec->data, rec->data_len);
   dir->msglen = ser_length(dir->msg);
   Dmsg1(1800, ">dird %s\n", dir->msg);    /* Attributes */
   return dir->send();
}
예제 #12
0
파일: edit.c 프로젝트: AlD/bareos
/*
 * Edit an integer into "human-readable" format with four or fewer
 * significant digits followed by a suffix that indicates the scale
 * factor.  The buf array inherits a 27 byte minimim length
 * requirement from edit_unit64_with_commas(), although the output
 * string is limited to eight characters.
 */
char *edit_uint64_with_suffix(uint64_t val, char *buf)
{
  int commas = 0;
  char *c, mbuf[50];
  const char *suffix[] =
    { "", "K", "M", "G", "T", "P", "E", "Z", "Y", "FIX ME" };
  int suffixes = sizeof(suffix) / sizeof(*suffix);

  edit_uint64_with_commas(val, mbuf);

  if ((c = strchr(mbuf, ',')) != NULL) {
    commas++;
    *c++ = '.';
    while  ((c = strchr(c, ',')) != NULL) {
      commas++;
      *c++ = '\0';
    }
    mbuf[5] = '\0'; // drop this to get '123.456 TB' rather than '123.4 TB'
  }

  if (commas >= suffixes)
    commas = suffixes - 1;
  bsnprintf(buf, 27, "%s %s", mbuf, suffix[commas]);
  return buf;
}
예제 #13
0
static int
fsqueue_envelope_load(enum queue_kind qkind, struct envelope *ep)
{
	char pathname[MAXPATHLEN];
	FILE *fp;
	int  ret;

	if (! bsnprintf(pathname, sizeof(pathname), "%s/%03x/%08x%s/%016llx",
		fsqueue_getpath(qkind),
		evpid_to_msgid(ep->id) & 0xfff,
		evpid_to_msgid(ep->id),
		PATH_ENVELOPES, ep->id))
		fatalx("fsqueue_envelope_load: snprintf");

	fp = fopen(pathname, "r");
	if (fp == NULL) {
		if (errno == ENOENT || errno == ENFILE)
			return 0;
		fatal("fsqueue_envelope_load: fopen");
	}
	ret = fsqueue_load_envelope_ascii(fp, ep);

	fclose(fp);

	return ret;
}
예제 #14
0
파일: pythonsd.c 프로젝트: halgandd/bacula
/* Return Job variables */
PyObject *job_getattr(PyObject *self, char *attrname)
{
   JCR *jcr;
   bool found = false;
   int i;
   char buf[10];
   char errmsg[200];
   
   Dmsg1(100, "In job_getattr=%s\n", attrname);
   jcr = get_jcr_from_PyObject(self);
   if (!jcr) {
      bstrncpy(errmsg, _("Job pointer not found."), sizeof(errmsg));
      goto bail_out;
   }

   for (i=0; getvars[i].name; i++) {
      if (strcmp(getvars[i].name, attrname) == 0) {
         found = true;
         break;
      }
   }
   if (!found) {
      /* Try our methods */
      return Py_FindMethod(JobMethods, self, attrname);
   }  
   switch (i) {
   case 0:                            /* Job */
      return Py_BuildValue((char *)getvars[i].fmt, jcr->job_name);    /* Non-unique name */
   case 1:                            /* SD's name */
      return Py_BuildValue((char *)getvars[i].fmt, my_name);
   case 2:                            /* level */
      return Py_BuildValue((char *)getvars[i].fmt, job_level_to_str(jcr->get_JobLevel()));
   case 3:                            /* type */
      return Py_BuildValue((char *)getvars[i].fmt, job_type_to_str(jcr->get_JobType()));
   case 4:                            /* JobId */
      return Py_BuildValue((char *)getvars[i].fmt, jcr->JobId);
   case 5:                            /* Client */
      return Py_BuildValue((char *)getvars[i].fmt, jcr->client_name);
   case 6:                            /* Pool */
      return Py_BuildValue((char *)getvars[i].fmt, jcr->dcr->pool_name);
   case 7:                            /* MediaType */
      return Py_BuildValue((char *)getvars[i].fmt, jcr->dcr->media_type);
   case 8:                            /* JobName */
      return Py_BuildValue((char *)getvars[i].fmt, jcr->Job);
   case 9:                            /* JobStatus */
      buf[1] = 0;
      buf[0] = jcr->JobStatus;
      return Py_BuildValue((char *)getvars[i].fmt, buf);
   case 10:
      return Py_BuildValue((char *)getvars[i].fmt, jcr->dcr->VolumeName);
   case 11:
      return Py_BuildValue((char *)getvars[i].fmt, jcr->dcr->dev_name);
   }
   bsnprintf(errmsg, sizeof(errmsg), _("Attribute %s not found."), attrname);
bail_out:
   PyErr_SetString(PyExc_AttributeError, errmsg);
   return NULL;
}
예제 #15
0
파일: dev.c 프로젝트: prelegalwonder/bacula
const char *mode_to_str(int mode)
{
   static char buf[100];
   if (mode < 1 || mode > 4) {
      bsnprintf(buf, sizeof(buf), "BAD mode=%d", mode);
      return buf;
    }
   return modes[mode-1];
}
예제 #16
0
파일: enqueue.c 프로젝트: lucasad/OpenSMTPD
static int
enqueue_offline(int argc, char *argv[], FILE *ifile)
{
	char	 path[SMTPD_MAXPATHLEN];
	FILE	*fp;
	int	 i, fd, ch;
	mode_t	 omode;

	if (ckdir(PATH_SPOOL PATH_OFFLINE, 01777, 0, 0, 0) == 0)
		errx(EX_UNAVAILABLE, "error in offline directory setup");

	if (! bsnprintf(path, sizeof(path), "%s%s/%lld.XXXXXXXXXX", PATH_SPOOL,
		PATH_OFFLINE, (long long int) time(NULL)))
		err(EX_UNAVAILABLE, "snprintf");

	omode = umask(7077);
	if ((fd = mkstemp(path)) == -1 || (fp = fdopen(fd, "w+")) == NULL) {
		warn("cannot create temporary file %s", path);
		if (fd != -1)
			unlink(path);
		exit(EX_UNAVAILABLE);
	}
	umask(omode);

	if (fchmod(fd, 0600) == -1) {
		unlink(path);
		exit(EX_SOFTWARE);
	}

	for (i = 1; i < argc; i++) {
		if (strchr(argv[i], '|') != NULL) {
			warnx("%s contains illegal character", argv[i]);
			unlink(path);
			exit(EX_SOFTWARE);
		}
		fprintf(fp, "%s%s", i == 1 ? "" : "|", argv[i]);
	}

	fprintf(fp, "\n");

	while ((ch = fgetc(ifile)) != EOF)
		if (fputc(ch, fp) == EOF) {
			warn("write error");
			unlink(path);
			exit(EX_UNAVAILABLE);
		}

	if (ferror(ifile)) {
		warn("read error");
		unlink(path);
		exit(EX_UNAVAILABLE);
	}

	fclose(fp);

	return (EX_TEMPFAIL);
}
예제 #17
0
int
queue_envelope_incoming_path(uint64_t evpid, char *buf, size_t len)
{
	return bsnprintf(buf, len, "%s/%08x%s/%016" PRIx64,
	    PATH_INCOMING,
	    evpid_to_msgid(evpid),
	    PATH_ENVELOPES,
	    evpid);
}
예제 #18
0
void restorePage::fileDoubleClicked(QTreeWidgetItem *item, int column)
{
   char cmd[1000];
   statusLine->setText("");
   if (column == 0) {                 /* mark/unmark */
      mainWin->waitEnter();
      if (item->data(0, Qt::UserRole).toBool()) {
         bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data());
         item->setIcon(0, QIcon(QString::fromUtf8(":images/unchecked.png")));
         item->setData(0, Qt::UserRole, false);
      } else {
         bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data());
         item->setIcon(0, QIcon(QString::fromUtf8(":images/check.png")));
         item->setData(0, Qt::UserRole, true);
      }
      m_console->write_dir(m_conn, cmd, false);
      if (m_console->read(m_conn) > 0) {
         strip_trailing_newline(m_console->msg(m_conn));
         statusLine->setText(m_console->msg(m_conn));
      }
      m_console->displayToPrompt(m_conn);
      mainWin->waitExit();
      return;
   }
   /*
    * Double clicking other than column 0 means to decend into
    *  the directory -- or nothing if it is not a directory.
    */
   if (item->text(1).endsWith("/")) {
      QString fullpath = m_cwd + item->text(1);
      QTreeWidgetItem *item = m_dirPaths.value(fullpath);
      if (mainWin->m_miscDebug) {
         Pmsg1(dbglvl, "%s\n", fullpath.toUtf8().data());
      }
      if (item) {
         directoryWidget->setCurrentItem(item);
      } else {
         QString msg = QString("DoubleClick else of item column %1 fullpath %2\n")
              .arg(column,10)
              .arg(fullpath);
         if (mainWin->m_miscDebug) Pmsg1(dbglvl, "%s\n", msg.toUtf8().data());
      }
   }
}
예제 #19
0
static int
fsqueue_message_corrupt(enum queue_kind qkind, u_int32_t msgid)
{
	char rootdir[MAXPATHLEN];
	char corruptdir[MAXPATHLEN];

	if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%03x/%08x",
		fsqueue_getpath(qkind), msgid & 0xfff, msgid))
		fatalx("fsqueue_message_corrupt: snprintf");

	if (! bsnprintf(corruptdir, sizeof(corruptdir), "%s/%08x",
		fsqueue_getpath(Q_CORRUPT), msgid))
		fatalx("fsqueue_message_corrupt: snprintf");

	if (rename(rootdir, corruptdir) == -1)
		fatalx("fsqueue_message_corrupt: rename");

	return 1;
}
예제 #20
0
static int
fsqueue_message_purge(enum queue_kind qkind, u_int32_t msgid)
{
	char rootdir[MAXPATHLEN];
	char purgedir[MAXPATHLEN];

	if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%08x",
		fsqueue_getpath(qkind), msgid))
		fatalx("fsqueue_message_purge: snprintf");

	if (! bsnprintf(purgedir, sizeof(purgedir), "%s/%08x",
		fsqueue_getpath(Q_PURGE), msgid))
		fatalx("fsqueue_message_purge: snprintf");

	if (rename(rootdir, purgedir) == -1)
		fatal("fsqueue_message_purge: rename");

	return 1;
}
예제 #21
0
int
main (int argc, char *const *argv)
{
   int verbose = 0;
   int status = 0;
   int ch, i;
   bool display_local = false;
   bool display_all = false;
   char drive='A';
   char buf[16];

   setlocale(LC_ALL, "");
   bindtextdomain("bacula", LOCALEDIR);
   textdomain("bacula");

   while ((ch = getopt(argc, argv, "alv?")) != -1) {
      switch (ch) {
         case 'v':
            verbose = 1;
            break;
         case 'l':
            display_local = true;
            break;
         case 'a':
            display_all = true;
            break;
         case '?':
         default:
            usage();

      }
   }
   argc -= optind;
   argv += optind;

   OSDependentInit();

   if (argc < 1 && display_all) {
      /* Try all letters */
      for (drive = 'A'; drive <= 'Z'; drive++) {
         bsnprintf(buf, sizeof(buf), "%c:/", drive);
         display_drive(buf, display_local, verbose);
      }
      exit(status);
   }

   if (argc < 1) {
      usage();
   }

   for (i = 0; i < argc; --argc, ++argv) {
      status += display_drive(*argv, display_local, verbose);
   }
   exit(status);
}
예제 #22
0
파일: record.c 프로젝트: wisre/bareos
static const char *findex_to_str(int32_t index, char *buf, size_t bufsz)
{
   if (index >= 0) {
      bsnprintf(buf, bufsz, "<User> %d", index);
      return buf;
   }

   FI_to_ascii(buf, index);

   return buf;
}
예제 #23
0
파일: dev.c 프로젝트: prelegalwonder/bacula
/*
 * Edit codes into (Un)MountCommand, Write(First)PartCommand
 *  %% = %
 *  %a = archive device name
 *  %e = erase (set if cannot mount and first part)
 *  %n = part number
 *  %m = mount point
 *  %v = last part name
 *
 *  omsg = edited output message
 *  imsg = input string containing edit codes (%x)
 *
 */
void DEVICE::edit_mount_codes(POOL_MEM &omsg, const char *imsg)
{
   const char *p;
   const char *str;
   char add[20];

   POOL_MEM archive_name(PM_FNAME);

   omsg.c_str()[0] = 0;
   Dmsg1(800, "edit_mount_codes: %s\n", imsg);
   for (p=imsg; *p; p++) {
      if (*p == '%') {
         switch (*++p) {
         case '%':
            str = "%";
            break;
         case 'a':
            str = dev_name;
            break;
         case 'e':
            if (num_dvd_parts == 0) {
               if (truncating || blank_dvd) {
                  str = "2";
               } else {
                  str = "1";
               }
            } else {
               str = "0";
            }
            break;
         case 'n':
            bsnprintf(add, sizeof(add), "%d", part);
            str = add;
            break;
         case 'm':
            str = device->mount_point;
            break;
         default:
            add[0] = '%';
            add[1] = *p;
            add[2] = 0;
            str = add;
            break;
         }
      } else {
         add[0] = *p;
         add[1] = 0;
         str = add;
      }
      Dmsg1(1900, "add_str %s\n", str);
      pm_strcat(omsg, (char *)str);
      Dmsg1(1800, "omsg=%s\n", omsg.c_str());
   }
}
예제 #24
0
/*
 * ANSI date
 *  ' 'YYDDD
 */
static char *ansi_date(time_t td, char *buf)
{
   struct tm *tm;

   if (td == 0) {
      td = time(NULL);
   }
   tm = gmtime(&td);
   bsnprintf(buf, 10, " %05d ", 1000 * (tm->tm_year + 1900 - 2000) + tm->tm_yday);
   return buf;
}
예제 #25
0
static int
fsqueue_message_fd_rw(enum queue_kind qkind, u_int32_t msgid)
{
	char pathname[MAXPATHLEN];
	
	if (! bsnprintf(pathname, sizeof(pathname), "%s/%08x/message",
		fsqueue_getpath(qkind),
		msgid))
		fatal("fsqueue_message_fd_rw: snprintf");

	return open(pathname, O_CREAT|O_EXCL|O_RDWR, 0600);
}
예제 #26
0
/*  SM_DUMP  --  Print orphaned buffers (and dump them if BUFDUMP is
 *               True).
 */
void sm_dump(bool bufdump, bool in_use)
{
   struct abufhead *ap;

   P(mutex);

   ap = (struct abufhead *)abqueue.qnext;

   while (ap != (struct abufhead *) &abqueue) {

      if ((ap == NULL) ||
          (ap->abq.qnext->qprev != (struct b_queue *) ap) ||
          (ap->abq.qprev->qnext != (struct b_queue *) ap)) {
         Pmsg1(0, _(
            "\nOrphaned buffers exist.  Dump terminated following\n"
            "  discovery of bad links in chain of orphaned buffers.\n"
            "  Buffer address with bad links: %p\n"), ap);
         break;
      }

      if (ap->abfname != NULL) {
         char errmsg[500];
         uint32_t memsize = ap->ablen - (HEAD_SIZE + 1);
         char *cp = ((char *)ap) + HEAD_SIZE;

         Pmsg6(0, "%s buffer: %s %d bytes at %p from %s:%d\n",
            in_use?"In use":"Orphaned",
            my_name, memsize, cp, get_basename(ap->abfname), ap->ablineno);
         if (bufdump) {
            char buf[20];
            unsigned llen = 0;

            errmsg[0] = EOS;
            while (memsize) {
               if (llen >= 16) {
                  bstrncat(errmsg, "\n", sizeof(errmsg));
                  llen = 0;
                  Pmsg1(0, "%s", errmsg);
                  errmsg[0] = EOS;
               }
               bsnprintf(buf, sizeof(buf), " %02X",
                  (*cp++) & 0xFF);
               bstrncat(errmsg, buf, sizeof(errmsg));
               llen++;
               memsize--;
            }
            Pmsg1(0, "%s\n", errmsg);
         }
      }
      ap = (struct abufhead *) ap->abq.qnext;
   }
   V(mutex);
}
예제 #27
0
static int
fsqueue_message_delete(enum queue_kind qkind, u_int32_t msgid)
{
	char rootdir[MAXPATHLEN];
	char evpdir[MAXPATHLEN];
	char msgpath[MAXPATHLEN];

	if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%03x/%08x", PATH_QUEUE,
		msgid & 0xfff, msgid))
		fatal("queue_delete_message: snprintf");

	if (! bsnprintf(evpdir, sizeof(evpdir), "%s%s", rootdir,
		PATH_ENVELOPES))
		fatal("queue_delete_message: snprintf");
	
	if (! bsnprintf(msgpath, sizeof(msgpath), "%s/message", rootdir))
		fatal("queue_delete_message: snprintf");

	if (unlink(msgpath) == -1)
		fatal("queue_delete_message: unlink");

	if (rmdir(evpdir) == -1) {
		/* It is ok to fail rmdir with ENOENT here
		 * because upon successful delivery of the
		 * last envelope, we remove the directory.
		 */
		if (errno != ENOENT)
			fatal("queue_delete_message: rmdir");
	}

	if (rmdir(rootdir) == -1)
		fatal("#2 queue_delete_message: rmdir");

	if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%03x", PATH_QUEUE, msgid & 0xffff))
		fatal("queue_delete_message: snprintf");

	rmdir(rootdir);

	return 1;
}
예제 #28
0
static int
fsqueue_message_fd_r(enum queue_kind qkind, u_int32_t msgid)
{
	int fd;
	char pathname[MAXPATHLEN];

	if (qkind == Q_ENQUEUE || qkind == Q_INCOMING) {
		if (! bsnprintf(pathname, sizeof(pathname), "%s/%08x/message",
			fsqueue_getpath(qkind), msgid))
			fatal("fsqueue_message_fd_r: snprintf");
	}
	else {
		if (! bsnprintf(pathname, sizeof(pathname), "%s/%03x/%08x/message",
			fsqueue_getpath(qkind), msgid & 0xfff, msgid))
			fatal("fsqueue_message_fd_r: snprintf");
	}

	if ((fd = open(pathname, O_RDONLY)) == -1)
		fatal("fsqueue_message_fd_r: open");

	return fd;
}
예제 #29
0
void selectDialog::accept()
{
   char cmd[100];

   this->hide();
   bsnprintf(cmd, sizeof(cmd), "%d", m_index+1);
   m_console->write_dir(m_conn, cmd);
   m_console->displayToPrompt(m_conn);
   this->close();
   mainWin->resetFocus();
   m_console->displayToPrompt(m_conn);
   m_console->notify(m_conn, true);
}
예제 #30
0
파일: bsys.c 프로젝트: pstray/bareos
static int addrtosymstr(void *pc, char *buffer, int size)
{
   Dl_info info;
   Sym *sym;

   if (dladdr1(pc, &info, (void **)&sym, RTLD_DL_SYMENT) == 0) {
      return (bsnprintf(buffer, size, "[0x%p]", pc));
   }

   if ((info.dli_fname != NULL && info.dli_sname != NULL) &&
      ((uintptr_t)pc - (uintptr_t)info.dli_saddr < sym->st_size)) {
      return (bsnprintf(buffer, size, "%s'%s+0x%x [0x%p]",
                        info.dli_fname,
                        info.dli_sname,
                        (unsigned long)pc - (unsigned long)info.dli_saddr,
                        pc));
   } else {
      return (bsnprintf(buffer, size, "%s'0x%p [0x%p]",
                        info.dli_fname,
                        (unsigned long)pc - (unsigned long)info.dli_fbase,
                        pc));
   }
}