コード例 #1
0
ファイル: exchange-fd.c プロジェクト: halgandd/bacula
static bRC
startBackupFile(bpContext *ctx, struct save_pkt *sp)
{
   bRC retval;
   exchange_fd_context_t *context = (exchange_fd_context_t *)ctx->pContext;
   node_t *current_node;

   _DebugMessage(100, "startBackupFile, cmd = %s\n", sp->cmd);
   if (sp->pkt_size != sizeof(struct save_pkt) || sp->pkt_end != sizeof(struct save_pkt))
   {
      _JobMessage(M_FATAL, "save_pkt size mismatch - sizeof(struct save_pkt) = %d, pkt_size = %d, pkt_end = %d\n", sizeof(struct save_pkt), sp->pkt_size, sp->pkt_end);
      return bRC_Error;
   }

   //context->root_node = new root_node_t(PLUGIN_PATH_PREFIX_BASE);
   //context->current_node = context->root_node;
   do {
      current_node  = context->current_node;
      retval = current_node->startBackupFile(context, sp);
      if (retval == bRC_Seen)
         endBackupFile(ctx);
   } while (current_node != context->current_node);
   _DebugMessage(100, "startBackupFile done - type = %d, fname = %s, retval = %d\n", sp->type, sp->fname, retval);
   return retval;
}
コード例 #2
0
ファイル: exchange-fd.c プロジェクト: halgandd/bacula
/*
 * Do actual I/O
 */
static bRC pluginIO(bpContext *ctx, struct io_pkt *io)
{
   bRC retval = bRC_OK;
   exchange_fd_context_t *context = (exchange_fd_context_t *)ctx->pContext;

   if (io->pkt_size != sizeof(struct io_pkt) || io->pkt_end != sizeof(struct io_pkt))
   {
      _JobMessage(M_ERROR, "io_pkt size mismatch - sizeof(struct io_pkt) = %d, pkt_size = %d, pkt_end = %d\n", sizeof(struct io_pkt), io->pkt_size, io->pkt_end);
   }

   switch(io->func) {
   case IO_OPEN:
      _DebugMessage(100, "IO_OPEN\n");
      retval = context->current_node->pluginIoOpen(context, io);
      break;
   case IO_READ:
      //_DebugMessage(100, "IO_READ buf=%p len=%d\n", io->buf, io->count);
      retval = context->current_node->pluginIoRead(context, io);
      break;
   case IO_WRITE:
      //_DebugMessage(100, "IO_WRITE buf=%p len=%d\n", io->buf, io->count);
      retval = context->current_node->pluginIoWrite(context, io);
      break;
   case IO_CLOSE:
      _DebugMessage(100, "IO_CLOSE\n");
      retval = context->current_node->pluginIoClose(context, io);
      break;
   }
   return retval;
}
コード例 #3
0
ファイル: file_node.c プロジェクト: halgandd/bacula
bRC
file_node_t::pluginIoOpen(exchange_fd_context_t *context, struct io_pkt *io)
{
   HRESULT result;
   HANDLE handle;
   char *tmp = new char[wcslen(filename) + 1];
   wcstombs(tmp, filename, wcslen(filename) + 1);

   _DebugMessage(0, "pluginIoOpen_FILE - filename = %s\n", tmp);
   io->status = 0;
   io->io_errno = 0;
   if (context->job_type == JOB_TYPE_BACKUP)
   {
      _DebugMessage(10, "Calling HrESEBackupOpenFile\n");
      result = HrESEBackupOpenFile(hccx, filename, 65535, 1, &backup_file_handle, &section_size);
      if (result)
      {
         _JobMessage(M_ERROR, "HrESEBackupOpenFile failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
         backup_file_handle = INVALID_HANDLE_VALUE;
         io->io_errno = 1;
         return bRC_Error;
      }
   }
   else
   {
      _DebugMessage(10, "Calling HrESERestoreOpenFile for '%s'\n", tmp);
      result = HrESERestoreOpenFile(hccx, filename, 1, &restore_file_handle);
      if (result == hrRestoreAtFileLevel)
      {
         restore_at_file_level = true;
         _DebugMessage(100, "Calling CreateFileW for '%s'\n", tmp);
         handle = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
         if (handle == INVALID_HANDLE_VALUE)
         {
            _JobMessage(M_ERROR, "CreateFile failed");
            return bRC_Error;
         }
         restore_file_handle = (void *)handle;
         return bRC_OK;
      }
      else if (result == 0)
      {
         _JobMessage(M_ERROR, "Exchange File IO API not yet supported for restore\n");
         restore_at_file_level = false;
         return bRC_Error;
      }
      else
      {
         _JobMessage(M_ERROR, "HrESERestoreOpenFile failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
         return bRC_Error;
      }
   }
   return bRC_OK;
}
コード例 #4
0
ファイル: exchange-fd.c プロジェクト: halgandd/bacula
static bRC endRestoreFile(bpContext *ctx)
{
   bRC retval;
   exchange_fd_context_t *context = (exchange_fd_context_t *)ctx->pContext;
   node_t *current_node;

   _DebugMessage(100, "endRestoreFile\n");

   do {
      current_node  = context->current_node;
      retval = current_node->endRestoreFile(context);
   } while (current_node != context->current_node);
   _DebugMessage(100, "endRestoreFile done - retval = %d\n", retval);
   return retval;
}
コード例 #5
0
ファイル: exchange-fd.c プロジェクト: halgandd/bacula
static bRC startRestoreFile(bpContext *ctx, const char *cmd)
{
   exchange_fd_context_t *context = (exchange_fd_context_t *)ctx->pContext;
   _DebugMessage(100, "startRestoreFile\n");

   return bRC_OK;
}
コード例 #6
0
ファイル: file_node.c プロジェクト: halgandd/bacula
bRC
file_node_t::endRestoreFile(exchange_fd_context_t *context)
{
   _DebugMessage(0, "endRestoreFile_FILE state = %d\n", state);
   context->current_node = parent;
   return bRC_OK;
}
コード例 #7
0
ファイル: exchange-fd.c プロジェクト: halgandd/bacula
static bRC newPlugin(bpContext *ctx)
{
   exchange_fd_context_t *context;
   bRC retval = bRC_OK;
   DWORD size;

   int JobId = 0;
   ctx->pContext = new exchange_fd_context_t;
   context = (exchange_fd_context_t *)ctx->pContext;
   context->bpContext = ctx;
   context->job_since = 0;
   context->notrunconfull_option = false;
   bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
   _DebugMessage(0, "newPlugin JobId=%d\n", JobId);
   bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
   size = MAX_COMPUTERNAME_LENGTH + 1;
   context->computer_name = new WCHAR[size];
   /*
   GetComputerNameW(context->computer_name, &size);
   */
   GetComputerNameExW(ComputerNameNetBIOS, context->computer_name, &size);
   context->current_node = NULL;
   context->root_node = NULL;
   return retval;
}
コード例 #8
0
ファイル: exchange-fd.c プロジェクト: halgandd/bacula
static bRC freePlugin(bpContext *ctx)
{
   exchange_fd_context_t *context = (exchange_fd_context_t *)ctx->pContext;
   int JobId = 0;
   bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
   _DebugMessage(100, "freePlugin JobId=%d\n", JobId);
   delete context;
   return bRC_OK;
}
コード例 #9
0
ファイル: file_node.c プロジェクト: halgandd/bacula
bRC
file_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
{
   //HrESERestoreOpenFile with name of log file

   _DebugMessage(0, "createFile_FILE state = %d\n", state);
   rp->create_status = CF_EXTRACT;
   return bRC_OK;
}
コード例 #10
0
ファイル: exchange-fd.c プロジェクト: halgandd/bacula
static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
{
   bRC retval;
   exchange_fd_context_t *context = (exchange_fd_context_t *)ctx->pContext;
   node_t *current_node;
   char **path_bits;
   int count;
   int i;


   _DebugMessage(100, "createFile - type = %d, ofname = %s\n", rp->type, rp->ofname);
   if (rp->pkt_size != sizeof(struct restore_pkt) || rp->pkt_end != sizeof(struct restore_pkt))
   {
      _JobMessage(M_ERROR, "restore_pkt size mismatch - sizeof(struct restore_pkt) = %d, pkt_size = %d, pkt_end = %d\n", sizeof(struct restore_pkt), rp->pkt_size, rp->pkt_end);
   }

   for (i = 0; i < 6; i++)
   {
      context->path_bits[i] = NULL;
   }

   path_bits = splitString((char *)rp->ofname, '/', 7, &count);

   _DebugMessage(100, "count = %d\n", count);

   for (i = 1; i < count; i++)
   {
      _DebugMessage(150, "%d = '%s'\n", i, path_bits[i]);
      context->path_bits[i - 1] = path_bits[i];
   }

   if (context->current_node == NULL)
   {
      context->root_node = new root_node_t(context->path_bits[0]);
      context->current_node = context->root_node;
   }

   do {
      current_node  = context->current_node;
      retval = current_node->createFile(context, rp);
   } while (current_node != context->current_node);
   _DebugMessage(100, "createFile done - retval = %d\n", retval);
   return retval;
}
コード例 #11
0
ファイル: file_node.c プロジェクト: halgandd/bacula
bRC
file_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
{
   time_t now = time(NULL);
   _DebugMessage(100, "startBackupNode_FILE state = %d\n", state);

   if (context->job_level == 'F' || parent->type == NODE_TYPE_STORAGE_GROUP) {
      sp->fname = full_path;
      sp->link = full_path;
      _DebugMessage(100, "fname = %s\n", sp->fname);
      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 = (uint64_t)-1;
      sp->type = FT_REG;
      return bRC_OK;
   } else {
      bfuncs->setBaculaValue(context->bpContext, bVarFileSeen, (void *)full_path);
      return bRC_Seen;
   }
}
コード例 #12
0
ファイル: file_node.c プロジェクト: halgandd/bacula
bRC
file_node_t::pluginIoRead(exchange_fd_context_t *context, struct io_pkt *io)
{
   HRESULT result;
   uint32_t readLength;

   io->status = 0;
   io->io_errno = 0;
   _DebugMessage(200, "Calling HrESEBackupReadFile\n");
   result = HrESEBackupReadFile(hccx, backup_file_handle, io->buf, io->count, &readLength);
   if (result)
   {
      io->io_errno = 1;
      return bRC_Error;
   }
   io->status = readLength;
   size += readLength;
   return bRC_OK;
}
コード例 #13
0
BOOL He4HookDriverHide::SendCommand(USER_COMMAND *lpUserCommand)
{
  if (IsBadReadPtr(lpUserCommand, sizeof(USER_COMMAND)))
    return FALSE;

  if (
      lpUserCommand->m_dwInBufferSize != 0 &&
      IsBadReadPtr(lpUserCommand->m_lpInBuffer, lpUserCommand->m_dwInBufferSize)
     )
    return FALSE;

  if (
      lpUserCommand->m_dwOutBufferSize != 0 &&
      IsBadWritePtr(lpUserCommand->m_lpOutBuffer, lpUserCommand->m_dwOutBufferSize)
     )
    return FALSE;

  __try
  {
    DWORD NtStatus = ZwDispatchFunction(0, 0,
                                        lpUserCommand->m_dwCommand,
                                        lpUserCommand->m_lpInBuffer, lpUserCommand->m_dwInBufferSize,
                                        lpUserCommand->m_lpOutBuffer, lpUserCommand->m_dwOutBufferSize,
                                        &lpUserCommand->m_dwBytesReturned);
    if (GetNtProcAddresses())
    {
      SetLastError(pRtlNtStatusToDosError(NtStatus));
    }
    if (NtStatus)
    {
      DriverErrorMessage();
      return FALSE;
    }
  }
  __except(EXCEPTION_EXECUTE_HANDLER)
  {
    _DebugMessage("BOOL He4HookDriverHide::SendCommand(USER_COMMAND *lpUserCommand)");
    return FALSE;
  }

  return TRUE;
}
コード例 #14
0
ファイル: file_node.c プロジェクト: halgandd/bacula
bRC
file_node_t::pluginIoClose(exchange_fd_context_t *context, struct io_pkt *io)
{
   if (context->job_type == JOB_TYPE_BACKUP)
   {
      _DebugMessage(100, "Calling HrESEBackupCloseFile\n");
      HrESEBackupCloseFile(hccx, backup_file_handle);
      backup_file_handle = INVALID_HANDLE_VALUE;
      return bRC_OK;
   }
   else
   {
      if (restore_at_file_level)
      {
         CloseHandle(restore_file_handle);
         restore_file_handle = INVALID_HANDLE_VALUE;
         return bRC_OK;
      }
      else
      {
         return bRC_OK;
      }
   }
}
コード例 #15
0
ファイル: exchange-fd.c プロジェクト: halgandd/bacula
static bRC setPluginValue(bpContext *ctx, pVariable var, void *value) 
{
   exchange_fd_context_t *context = (exchange_fd_context_t *)ctx->pContext;
   _DebugMessage(100, "setPluginValue var=%d\n", var);
   return bRC_OK;
}
コード例 #16
0
ファイル: exchange-fd.c プロジェクト: halgandd/bacula
static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value)
{
   exchange_fd_context_t *context = (exchange_fd_context_t *)ctx->pContext;
   char *name;
   int i, intval;
   int accurate;

   switch (event->eventType) {
   case bEventJobStart:
      _DebugMessage(0, "JobStart=%s\n", (char *)value);
      break;
   case bEventJobEnd:
      _DebugMessage(0, "JobEnd\n");
      break;
   case bEventStartBackupJob:
      _DebugMessage(0, "BackupStart\n");
      bfuncs->getBaculaValue(ctx, bVarAccurate, (void *)&accurate);
      context->accurate = accurate;
      context->job_type = JOB_TYPE_BACKUP;
      // level should have been specified by now - check it
      // if level is D or I, since should have been specified too
      switch (context->job_level)
      {
      case 'F':
         if (context->notrunconfull_option) {
            context->truncate_logs = false;
         } else {
            context->truncate_logs = true;
         }
         break;
      case 'D':
         context->truncate_logs = false;
         break;
      case 'I':
         context->truncate_logs = false;
         break;
      default:
         _DebugMessage(0, "Invalid job level %c\n", context->job_level);
         return bRC_Error;
      }
      break;
   case bEventEndBackupJob:
      _DebugMessage(0, "BackupEnd\n");
      break;
   case bEventLevel:
      intval = (intptr_t)value;
      _DebugMessage(0, "JobLevel=%c %d\n", intval, intval);
      context->job_level = intval;
      break;
   case bEventSince:
      intval = (intptr_t)value;
      _DebugMessage(0, "since=%d\n", intval);
      context->job_since = (time_t)value;
      break;
   case bEventStartRestoreJob:
      _DebugMessage(0, "StartRestoreJob\n");
      context->job_type = JOB_TYPE_RESTORE;
      break;
   case bEventEndRestoreJob:
      _DebugMessage(0, "EndRestoreJob\n");
      break;
   
   /* Plugin command e.g. plugin = <plugin-name>:<name-space>:command */
   case bEventRestoreCommand:
      _DebugMessage(0, "restore\n"); // command=%s\n", (char *)value);
      break;

   case bEventBackupCommand:
      {
      _DebugMessage(0, "backup command=%s\n", (char *)value);    
      char *command = new char[strlen((char *)value)];
      strcpy(command, (char *)value);
      char *plugin_name = strtok((char *)command, ":");
      char *path = strtok(NULL, ":");
      char *option;
      while ((option = strtok(NULL, ":")) != NULL)
      {
         _DebugMessage(100, "option %s\n", option);
         if (stricmp(option, "notrunconfull") == 0)
         {
            context->notrunconfull_option = true;
         }
         else
         {
            _JobMessage(M_WARNING, "Unknown plugin option '%s'\n", option);
         }
      }
      _DebugMessage(0, "name = %s\n", plugin_name);
      _DebugMessage(0, "path = %s\n", path);
      if (*path != '/')
      {
         _JobMessage(M_ERROR, "Path does not begin with a '/'\n");
         return bRC_Error;
      }

      for (i = 0; i < 6; i++)
         context->path_bits[i] = NULL;

      char *path_bit = strtok(path, "/");
      for (i = 0; path_bit != NULL && i < 6; i++)
      {
         context->path_bits[i] = new char[strlen(path_bit) + 1];
         strcpy(context->path_bits[i], path_bit);
         path_bit = strtok(NULL, "/");
      }

      if (i < 2 || i > 4)
      {
         _JobMessage(M_ERROR, "Invalid plugin backup path\n");
         return bRC_Error;
      }
      context->root_node = new root_node_t(context->path_bits[0]);
      context->current_node = context->root_node;

      }
      break;

   default:
      _JobMessage(M_ERROR, "unknown event=%d\n", event->eventType);
   }
   bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name);
   return bRC_OK;
}
コード例 #17
0
ファイル: exchange-fd.c プロジェクト: halgandd/bacula
static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp)
{
   exchange_fd_context_t *context = (exchange_fd_context_t *)ctx->pContext;
   _DebugMessage(100, "setFileAttributes\n");
   return bRC_OK;
}