*/
/*
- Copyright (C) 2000-2003 Kern Sibbald and John Walker
+ Copyright (C) 2000-2004 Kern Sibbald and John Walker
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
static int release_cmd(UAContext *ua, char *cmd);
static int update_cmd(UAContext *ua, char *cmd);
static int wait_cmd(UAContext *ua, char *cmd);
+static int setip_cmd(UAContext *ua, char *cmd);
int quit_cmd(UAContext *ua, char *cmd);
{ N_("run"), run_cmd, _("run <job-name>")},
{ N_("status"), status_cmd, _("status [storage | client]=<name>")},
{ N_("setdebug"), setdebug_cmd, _("sets debug level")},
+ { N_("setip"), setip_cmd, _("sets new client address -- if authorized")},
{ N_("show"), show_cmd, _("show (resource records) [jobs | pools | ... | all]")},
{ N_("sqlquery"), sqlquerycmd, _("use SQL to query catalog")},
{ N_("time"), time_cmd, _("print current time")},
{
unsigned int i;
int len, stat;
- int found;
+ bool found = false;
- found = 0;
stat = 1;
- Dmsg1(120, "Command: %s\n", ua->UA_sock->msg);
+ Dmsg1(200, "Command: %s\n", ua->UA_sock->msg);
if (ua->argc == 0) {
return 1;
}
len = strlen(ua->argk[0]);
for (i=0; i<comsize; i++) { /* search for command */
if (strncasecmp(ua->argk[0], _(commands[i].key), len) == 0) {
+ if (!acl_access_ok(ua, Command_ACL, ua->argk[0], len)) {
+ break;
+ }
stat = (*commands[i].func)(ua, cmd); /* go execute command */
- found = 1;
+ found = true;
break;
}
}
if (!found) {
- pm_strcat(&ua->UA_sock->msg, _(": is an illegal command\n"));
- ua->UA_sock->msglen = strlen(ua->UA_sock->msg);
- bnet_send(ua->UA_sock);
+ bnet_fsend(ua->UA_sock, _("%s: is an illegal command.\n"), ua->argk[0]);
}
return stat;
}
*/
static int cancel_cmd(UAContext *ua, char *cmd)
{
- int i;
+ int i, ret;
int njobs = 0;
- BSOCK *sd, *fd;
JCR *jcr = NULL;
char JobName[MAX_NAME_LENGTH];
for (i=1; i<ua->argc; i++) {
if (strcasecmp(ua->argk[i], _("jobid")) == 0) {
+ uint32_t JobId;
if (!ua->argv[i]) {
break;
}
- if (!(jcr=get_jcr_by_id(atoi(ua->argv[i])))) {
- bsendmsg(ua, _("JobId %d is not running.\n"), atoi(ua->argv[i]));
+ JobId = str_to_int64(ua->argv[i]);
+ if (!(jcr=get_jcr_by_id(JobId))) {
+ bsendmsg(ua, _("JobId %d is not running.\n"), JobId);
return 1;
}
break;
return 1;
}
}
+ /* NOTE! This increments the ref_count */
jcr = get_jcr_by_full_name(JobName);
if (!jcr) {
bsendmsg(ua, _("Job %s not found.\n"), JobName);
return 1;
}
}
-
- switch (jcr->JobStatus) {
- case JS_Created:
- case JS_WaitJobRes:
- case JS_WaitClientRes:
- case JS_WaitStoreRes:
- case JS_WaitPriority:
- case JS_WaitMaxJobs:
- case JS_WaitStartTime:
- set_jcr_job_status(jcr, JS_Canceled);
- bsendmsg(ua, _("JobId %d, Job %s marked to be canceled.\n"),
- jcr->JobId, jcr->Job);
- jobq_remove(&job_queue, jcr); /* attempt to remove it from queue */
- free_jcr(jcr); /* this decrements the use count only */
- return 1;
-
- default:
- set_jcr_job_status(jcr, JS_Canceled);
-
- /* Cancel File daemon */
- if (jcr->file_bsock) {
- ua->jcr->client = jcr->client;
- if (!connect_to_file_daemon(ua->jcr, 10, FDConnectTimeout, 1)) {
- bsendmsg(ua, _("Failed to connect to File daemon.\n"));
- free_jcr(jcr);
- return 1;
- }
- Dmsg0(200, "Connected to file daemon\n");
- fd = ua->jcr->file_bsock;
- bnet_fsend(fd, "cancel Job=%s\n", jcr->Job);
- while (bnet_recv(fd) >= 0) {
- bsendmsg(ua, "%s", fd->msg);
- }
- bnet_sig(fd, BNET_TERMINATE);
- bnet_close(fd);
- ua->jcr->file_bsock = NULL;
- }
- /* Cancel Storage daemon */
- if (jcr->store_bsock) {
- ua->jcr->store = jcr->store;
- if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
- bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
- free_jcr(jcr);
- return 1;
- }
- Dmsg0(200, "Connected to storage daemon\n");
- sd = ua->jcr->store_bsock;
- bnet_fsend(sd, "cancel Job=%s\n", jcr->Job);
- while (bnet_recv(sd) >= 0) {
- bsendmsg(ua, "%s", sd->msg);
- }
- bnet_sig(sd, BNET_TERMINATE);
- bnet_close(sd);
- ua->jcr->store_bsock = NULL;
- }
- }
+ ret = cancel_job(ua, jcr);
free_jcr(jcr);
- return 1;
+ return ret;
}
/*
switch (create_pool(ua->jcr, ua->db, pool, POOL_OP_CREATE)) {
case 0:
- bsendmsg(ua, _("Error: Pool %s already exists.\n\
-Use update to change it.\n"), pool->hdr.name);
+ bsendmsg(ua, _("Error: Pool %s already exists.\n"
+ "Use update to change it.\n"), pool->hdr.name);
break;
case -1:
}
+/*
+ * Set a new address in a Client resource. We do this only
+ * if the Console name is the same as the Client name
+ * and the Console can access the client.
+ */
+static int setip_cmd(UAContext *ua, char *cmd)
+{
+ CLIENT *client;
+ if (!ua->cons || !acl_access_ok(ua, Client_ACL, ua->cons->hdr.name)) {
+ bsendmsg(ua, _("Illegal command from this console.\n"));
+ return 1;
+ }
+ client = (CLIENT *)GetResWithName(R_CLIENT, ua->cons->hdr.name);
+
+ if (!client) {
+ bsendmsg(ua, _("Client \"%s\" not found.\n"), ua->cons->hdr.name);
+ return 1;
+ }
+ LockRes();
+ if (client->address) {
+ free(client->address);
+ }
+ client->address = bstrdup(inet_ntoa(ua->UA_sock->client_addr.sin_addr));
+ bsendmsg(ua, _("Client \"%s\" address set to %s\n"),
+ client->hdr.name, client->address);
+ UnlockRes();
+ return 1;
+}
/*