]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_dotcmds.c
kes Move the checking of the database in initializion of the Director
[bacula/bacula] / bacula / src / dird / ua_dotcmds.c
index a236ff3c2e17253b36468a333df4590b428472e5..48f9edf27b1977972053ac24ef550417ef9922cb 100644 (file)
@@ -102,22 +102,29 @@ int do_a_dot_command(UAContext *ua, const char *cmd)
    int len;
    bool ok = false;
    bool found = false;
-   BSOCK *sock = ua->UA_sock;
+   BSOCK *user = ua->UA_sock;
 
-   Dmsg1(1400, "Dot command: %s\n", ua->UA_sock->msg);
+   Dmsg1(1400, "Dot command: %s\n", user->msg);
    if (ua->argc == 0) {
       return 1;
    }
 
    len = strlen(ua->argk[0]);
    if (len == 1) {
+      if (ua->api) user->signal(BNET_CMD_BEGIN);
+      if (ua->api) user->signal(BNET_CMD_OK);
       return 1;                       /* no op */
    }
    for (i=0; i<comsize; i++) {     /* search for command */
       if (strncasecmp(ua->argk[0],  _(commands[i].key), len) == 0) {
          bool gui = ua->gui;
+         /* Check if command permitted, but "quit" is always OK */
+         if (strcmp(ua->argk[0], NT_(".quit")) != 0 &&
+             !acl_access_ok(ua, Command_ACL, ua->argk[0], len)) {
+            break;
+         }
          ua->gui = true;
-         if (ua->api) sock->signal(BNET_CMD_BEGIN);
+         if (ua->api) user->signal(BNET_CMD_BEGIN);
          ok = (*commands[i].func)(ua, cmd);   /* go execute command */
          ua->gui = gui;
          found = true;
@@ -125,12 +132,11 @@ int do_a_dot_command(UAContext *ua, const char *cmd)
       }
    }
    if (!found) {
-      pm_strcat(sock->msg, _(": is an invalid command\n"));
-      sock->msglen = strlen(sock->msg);
-      sock->send();
-      if (ua->api) sock->signal(BNET_INVALID_CMD);
+      pm_strcat(user->msg, _(": is an invalid command.\n"));
+      user->msglen = strlen(user->msg);
+      user->send();
    }
-   if (ua->api) sock->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED);
+   if (ua->api) user->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED);
    return 1;
 }
 
@@ -170,9 +176,9 @@ static bool diecmd(UAContext *ua, const char *cmd)
 
 static bool jobscmd(UAContext *ua, const char *cmd)
 {
-   JOB *job = NULL;
+   JOB *job;
    LockRes();
-   while ( (job = (JOB *)GetNextRes(R_JOB, (RES *)job)) ) {
+   foreach_res(job, R_JOB) {
       if (acl_access_ok(ua, Job_ACL, job->name())) {
          bsendmsg(ua, "%s\n", job->name());
       }
@@ -183,9 +189,9 @@ static bool jobscmd(UAContext *ua, const char *cmd)
 
 static bool filesetscmd(UAContext *ua, const char *cmd)
 {
-   FILESET *fs = NULL;
+   FILESET *fs;
    LockRes();
-   while ( (fs = (FILESET *)GetNextRes(R_FILESET, (RES *)fs)) ) {
+   foreach_res(fs, R_FILESET) {
       if (acl_access_ok(ua, FileSet_ACL, fs->name())) {
          bsendmsg(ua, "%s\n", fs->name());
       }
@@ -196,9 +202,9 @@ static bool filesetscmd(UAContext *ua, const char *cmd)
 
 static bool clientscmd(UAContext *ua, const char *cmd)
 {
-   CLIENT *client = NULL;
+   CLIENT *client;       
    LockRes();
-   while ( (client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client)) ) {
+   foreach_res(client, R_CLIENT) {
       if (acl_access_ok(ua, Client_ACL, client->name())) {
          bsendmsg(ua, "%s\n", client->name());
       }
@@ -211,7 +217,7 @@ static bool msgscmd(UAContext *ua, const char *cmd)
 {
    MSGS *msgs = NULL;
    LockRes();
-   while ( (msgs = (MSGS *)GetNextRes(R_MSGS, (RES *)msgs)) ) {
+   foreach_res(msgs, R_MSGS) {
       bsendmsg(ua, "%s\n", msgs->name());
    }
    UnlockRes();
@@ -220,9 +226,9 @@ static bool msgscmd(UAContext *ua, const char *cmd)
 
 static bool poolscmd(UAContext *ua, const char *cmd)
 {
-   POOL *pool = NULL;
+   POOL *pool;       
    LockRes();
-   while ( (pool = (POOL *)GetNextRes(R_POOL, (RES *)pool)) ) {
+   foreach_res(pool, R_POOL) {
       if (acl_access_ok(ua, Pool_ACL, pool->name())) {
          bsendmsg(ua, "%s\n", pool->name());
       }
@@ -233,9 +239,9 @@ static bool poolscmd(UAContext *ua, const char *cmd)
 
 static bool storagecmd(UAContext *ua, const char *cmd)
 {
-   STORE *store = NULL;
+   STORE *store;
    LockRes();
-   while ( (store = (STORE *)GetNextRes(R_STORAGE, (RES *)store)) ) {
+   foreach_res(store, R_STORAGE) {
       if (acl_access_ok(ua, Storage_ACL, store->name())) {
          bsendmsg(ua, "%s\n", store->name());
       }
@@ -273,22 +279,27 @@ static int client_backups_handler(void *ctx, int num_field, char **row)
  */
 static bool api_cmd(UAContext *ua, const char *cmd)
 {
-   /* Eventually we will probably have several levels or
-    *  capabilities enabled by this.
-    */
-   ua->api = 1;
+   if (ua->argc == 2) {
+      ua->api = atoi(ua->argk[1]);
+   } else {
+      ua->api = 1;
+   }
    return true;
 }
 
 /*
  * Return the backups for this client 
+ *
+ *  .backups client=xxx fileset=yyy
+ *
  */
 static bool backupscmd(UAContext *ua, const char *cmd)
 {
    if (!open_client_db(ua)) {
       return true;
    }
-   if (ua->argc != 3 || strcmp(ua->argk[1], "client") != 0 || strcmp(ua->argk[2], "fileset") != 0) {
+   if (ua->argc != 3 || strcmp(ua->argk[1], "client") != 0 || 
+       strcmp(ua->argk[2], "fileset") != 0) {
       return true;
    }
    if (!acl_access_ok(ua, Client_ACL, ua->argv[1]) ||