Skip to content

Commit

Permalink
Add command for doing a name resolution on client.
Browse files Browse the repository at this point in the history
Resolve command now can resolve given hostname(s) on director, client
and storage daemon if specified.

examples:

* resolution on director:
   resolve www.bareos.com
   > gonzo-dir resolves www.bareos.com to host[ipv4:84.44.166.242]

* resolution on client:
   resolve client=gonzo.bareos.com-fd www.bareos.com
   > gonzo-fd resolves www.bareos.com to host[ipv4:84.44.166.242]

* resolution on storage:
   resolve storage=File www.bareos.com
   > gonzo-sd  resolves www.bareos.com to host[ipv4:84.44.166.242]

Fixes #181: Add command for doing a name resolution on client.

Signed-off-by: Marco van Wieringen <marco.van.wieringen@bareos.com>
  • Loading branch information
pstorz authored and Marco van Wieringen committed Aug 9, 2013
1 parent bb3cd2e commit 6a4e8f7
Show file tree
Hide file tree
Showing 33 changed files with 361 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/cats/protos.h
Expand Up @@ -114,7 +114,7 @@ void db_list_files_for_job(JCR *jcr, B_DB *db, uint32_t jobid, DB_LIST_HANDLER s
void db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, JobId_t JobId, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
void db_list_joblog_records(JCR *jcr, B_DB *mdb, JobId_t JobId, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
bool db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit, void *ctx, int verbose, e_list_type type);
bool db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit, void *ctx, bool verbose, e_list_type type);
void db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
void db_list_copies_records(JCR *jcr, B_DB *mdb, uint32_t limit, char *jobids, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
void db_list_base_files_for_job(JCR *jcr, B_DB *mdb, JobId_t jobid, DB_LIST_HANDLER *sendit, void *ctx);
Expand Down
2 changes: 1 addition & 1 deletion src/cats/sql_list.c
Expand Up @@ -45,7 +45,7 @@
* Submit general SQL query
*/
bool db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit,
void *ctx, int verbose, e_list_type type)
void *ctx, bool verbose, e_list_type type)
{
bool retval = false;

Expand Down
2 changes: 1 addition & 1 deletion src/console/console.c
Expand Up @@ -1241,7 +1241,7 @@ int main(int argc, char *argv[])
heart_beat = 0;
}
UA_sock = bnet_connect(NULL, 5, 15, heart_beat, "Director daemon", dir->address,
NULL, dir->DIRport, 0);
NULL, dir->DIRport, false);
if (UA_sock == NULL) {
terminate_console(0);
return 1;
Expand Down
4 changes: 2 additions & 2 deletions src/dird/backup.c
Expand Up @@ -346,7 +346,7 @@ bool do_native_backup(JCR *jcr)
/*
* Start conversation with Storage daemon
*/
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, 1)) {
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, true)) {
return false;
}
sd = jcr->store_bsock;
Expand Down Expand Up @@ -387,7 +387,7 @@ bool do_native_backup(JCR *jcr)
}

jcr->setJobStatus(JS_WaitFD);
if (!connect_to_file_daemon(jcr, 10, me->FDConnectTimeout, 1)) {
if (!connect_to_file_daemon(jcr, 10, me->FDConnectTimeout, true, true)) {
goto bail_out;
}
fd = jcr->file_bsock;
Expand Down
150 changes: 99 additions & 51 deletions src/dird/fd_cmds.c
Expand Up @@ -90,7 +90,7 @@ extern DIRRES *director;
* give up after max_retry_time (default 30 mins).
*/

int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time, int verbose)
int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time, bool verbose, bool start_job)
{
BSOCK *fd = new_bsock();
char ed1[30];
Expand Down Expand Up @@ -132,44 +132,47 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time, int
return 0;
}

/*
* Now send JobId and authorization key
*/
if (jcr->sd_auth_key == NULL) {
jcr->sd_auth_key = bstrdup("dummy");
}
fd->fsend(jobcmd, edit_int64(jcr->JobId, ed1), jcr->Job, jcr->VolSessionId,
jcr->VolSessionTime, jcr->sd_auth_key);
if (!jcr->keep_sd_auth_key && !bstrcmp(jcr->sd_auth_key, "dummy")) {
memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
}
Dmsg1(100, ">filed: %s", fd->msg);
if (bget_dirmsg(fd) > 0) {
Dmsg1(110, "<filed: %s", fd->msg);
if (!bstrncmp(fd->msg, OKjob, strlen(OKjob))) {
Jmsg(jcr, M_FATAL, 0, _("File daemon \"%s\" rejected Job command: %s\n"),
jcr->res.client->hdr.name, fd->msg);
jcr->setJobStatus(JS_ErrorTerminated);
return 0;
} else if (jcr->db) {
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;
bstrncpy(cr.Uname, fd->msg+strlen(OKjob)+1, sizeof(cr.Uname));
if (!db_update_client_record(jcr, jcr->db, &cr)) {
Jmsg(jcr, M_WARNING, 0, _("Error updating Client record. ERR=%s\n"),
db_strerror(jcr->db));
if (start_job) {
/*
* Now send JobId and authorization key
*/
if (jcr->sd_auth_key == NULL) {
jcr->sd_auth_key = bstrdup("dummy");
}
fd->fsend(jobcmd, edit_int64(jcr->JobId, ed1), jcr->Job, jcr->VolSessionId,
jcr->VolSessionTime, jcr->sd_auth_key);
if (!jcr->keep_sd_auth_key && !bstrcmp(jcr->sd_auth_key, "dummy")) {
memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
}
Dmsg1(100, ">filed: %s", fd->msg);
if (bget_dirmsg(fd) > 0) {
Dmsg1(110, "<filed: %s", fd->msg);
if (!bstrncmp(fd->msg, OKjob, strlen(OKjob))) {
Jmsg(jcr, M_FATAL, 0, _("File daemon \"%s\" rejected Job command: %s\n"),
jcr->res.client->hdr.name, fd->msg);
jcr->setJobStatus(JS_ErrorTerminated);
return 0;
} else if (jcr->db) {
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;
bstrncpy(cr.Uname, fd->msg+strlen(OKjob)+1, sizeof(cr.Uname));
if (!db_update_client_record(jcr, jcr->db, &cr)) {
Jmsg(jcr, M_WARNING, 0, _("Error updating Client record. ERR=%s\n"),
db_strerror(jcr->db));
}
}
}
} else {
Jmsg(jcr, M_FATAL, 0, _("FD gave bad response to JobId command: %s\n"),
} else {
Jmsg(jcr, M_FATAL, 0, _("FD gave bad response to JobId command: %s\n"),
bnet_strerror(fd));
jcr->setJobStatus(JS_ErrorTerminated);
return 0;
jcr->setJobStatus(JS_ErrorTerminated);
return 0;
}
}

return 1;
}

Expand Down Expand Up @@ -866,7 +869,7 @@ bool cancel_file_daemon_job(UAContext *ua, JCR *jcr)
BSOCK *fd;

ua->jcr->res.client = jcr->res.client;
if (!connect_to_file_daemon(ua->jcr, 10, me->FDConnectTimeout, 1)) {
if (!connect_to_file_daemon(ua->jcr, 10, me->FDConnectTimeout, true, false)) {
ua->error_msg(_("Failed to connect to File daemon.\n"));
return false;
}
Expand Down Expand Up @@ -897,23 +900,14 @@ void do_native_client_status(UAContext *ua, CLIENTRES *client, char *cmd)
ua->jcr->res.client = client;

/*
* Release any old dummy key
* Try to connect for 15 seconds
*/
if (ua->jcr->sd_auth_key) {
free(ua->jcr->sd_auth_key);
if (!ua->api) {
ua->send_msg(_("Connecting to Client %s at %s:%d\n"),
client->name(), client->address, client->FDport);
}

/*
* Create a new dummy SD auth key
*/
ua->jcr->sd_auth_key = bstrdup("dummy");

/*
* Try to connect for 15 seconds
*/
if (!ua->api) ua->send_msg(_("Connecting to Client %s at %s:%d\n"),
client->name(), client->address, client->FDport);
if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) {
if (!connect_to_file_daemon(ua->jcr, 1, 15, false, false)) {
ua->send_msg(_("Failed to connect to Client %s.\n====\n"),
client->name());
if (ua->jcr->file_bsock) {
Expand All @@ -922,16 +916,70 @@ void do_native_client_status(UAContext *ua, CLIENTRES *client, char *cmd)
}
return;
}

Dmsg0(20, _("Connected to file daemon\n"));
fd = ua->jcr->file_bsock;
if (cmd) {
fd->fsend(".status %s", cmd);
} else {
fd->fsend("status");
}

while (fd->recv() >= 0) {
ua->send_msg("%s", fd->msg);
}

fd->signal(BNET_TERMINATE);
fd->close();
ua->jcr->file_bsock = NULL;

return;
}

/*
* resolve a host on a filedaemon
*/
void do_client_resolve(UAContext *ua, CLIENTRES *client)
{
BSOCK *fd;

/*
* Connect to File daemon
*/
ua->jcr->res.client = client;

/*
* Try to connect for 15 seconds
*/
if (!ua->api) {
ua->send_msg(_("Connecting to Client %s at %s:%d\n"),
client->name(), client->address, client->FDport);
}

if (!connect_to_file_daemon(ua->jcr, 1, 15, false, false)) {
ua->send_msg(_("Failed to connect to Client %s.\n====\n"),
client->name());
if (ua->jcr->file_bsock) {
ua->jcr->file_bsock->close();
ua->jcr->file_bsock = NULL;
}
return;
}

Dmsg0(20, _("Connected to file daemon\n"));
fd = ua->jcr->file_bsock;

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

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

fd->signal(BNET_TERMINATE);
fd->close();
ua->jcr->file_bsock = NULL;
Expand Down
6 changes: 3 additions & 3 deletions src/dird/migrate.c
Expand Up @@ -431,7 +431,7 @@ bool do_migration(JCR *jcr)
/*
* Start conversation with Storage daemon
*/
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, 1)) {
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, true)) {
return false;
}

Expand Down Expand Up @@ -485,7 +485,7 @@ bool do_migration(JCR *jcr)
* Start conversation with Reading Storage daemon
*/
jcr->setJobStatus(JS_WaitSD);
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, 1)) {
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, true)) {
goto bail_out;
}

Expand All @@ -498,7 +498,7 @@ bool do_migration(JCR *jcr)
* Start conversation with Writing Storage daemon
*/
mig_jcr->setJobStatus(JS_WaitSD);
if (!connect_to_storage_daemon(mig_jcr, 10, me->SDConnectTimeout, 1)) {
if (!connect_to_storage_daemon(mig_jcr, 10, me->SDConnectTimeout, true)) {
goto bail_out;
}

Expand Down
4 changes: 2 additions & 2 deletions src/dird/msgchan.c
Expand Up @@ -83,7 +83,7 @@ bool update_device_res(JCR *jcr, DEVICERES *dev)
{
POOL_MEM device_name;
BSOCK *sd;
if (!connect_to_storage_daemon(jcr, 5, 30, 0)) {
if (!connect_to_storage_daemon(jcr, 5, 30, false)) {
return false;
}
sd = jcr->store_bsock;
Expand Down Expand Up @@ -490,7 +490,7 @@ extern "C" void *device_thread(void *arg)
pthread_detach(pthread_self());
jcr = new_control_jcr("*DeviceInit*", JT_SYSTEM);
for (i=0; i < MAX_TRIES; i++) {
if (!connect_to_storage_daemon(jcr, 10, 30, 1)) {
if (!connect_to_storage_daemon(jcr, 10, 30, true)) {
Dmsg0(900, "Failed connecting to SD.\n");
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/dird/ndmp_dma.c
Expand Up @@ -1712,7 +1712,7 @@ bool do_ndmp_backup(JCR *jcr)
set_paired_storage(jcr);

jcr->setJobStatus(JS_WaitSD);
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, 1)) {
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, true)) {
return false;
}

Expand Down Expand Up @@ -2221,7 +2221,7 @@ static inline bool do_ndmp_restore_bootstrap(JCR *jcr)
/*
* Start conversation with Storage daemon
*/
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, 1)) {
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, true)) {
goto cleanup;
}
sd = jcr->store_bsock;
Expand Down
8 changes: 5 additions & 3 deletions src/dird/protos.h
Expand Up @@ -90,8 +90,8 @@ extern "C" char *job_code_callback_director(JCR *jcr, const char*);
int variable_expansion(JCR *jcr, char *inp, POOLMEM **exp);

/* fd_cmds.c */
int connect_to_file_daemon(JCR *jcr, int retry_interval,
int max_retry_time, int verbose);
int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time,
bool verbose, bool start_job);
bool send_include_list(JCR *jcr);
bool send_exclude_list(JCR *jcr);
bool send_level_command(JCR *jcr);
Expand All @@ -105,6 +105,7 @@ bool send_plugin_options(JCR *jcr);
bool send_restore_objects(JCR *jcr);
bool cancel_file_daemon_job(UAContext *ua, JCR *jcr);
void do_native_client_status(UAContext *ua, CLIENTRES *client, char *cmd);
void do_client_resolve(UAContext *ua, CLIENTRES *client);

/* getmsg.c */
bool response(JCR *jcr, BSOCK *fd, char *resp, const char *cmd, e_prtmsg prtmsg);
Expand Down Expand Up @@ -204,7 +205,7 @@ void generate_restore_summary(JCR *jcr, int msg_type, const char *term_msg);

/* sd_cmds.c */
bool connect_to_storage_daemon(JCR *jcr, int retry_interval,
int max_retry_time, int verbose);
int max_retry_time, bool verbose);
BSOCK *open_sd_bsock(UAContext *ua);
void close_sd_bsock(UAContext *ua);
char *get_volume_name_from_SD(UAContext *ua, int Slot, int drive);
Expand All @@ -220,6 +221,7 @@ bool transfer_volume(UAContext *ua, STORERES *store, int src_slot, int dst_slot)
bool do_autochanger_volume_operation(UAContext *ua, STORERES *store,
const char *operation, int drive, int slot);
bool send_bwlimit_to_sd(JCR *jcr, const char *Job);
bool do_storage_resolve(UAContext *ua, STORERES *store);

/* scheduler.c */
JCR *wait_for_next_job(char *one_shot_job_to_run);
Expand Down
4 changes: 2 additions & 2 deletions src/dird/restore.c
Expand Up @@ -159,7 +159,7 @@ static inline bool do_native_restore_bootstrap(JCR *jcr)
/*
* Start conversation with Storage daemon
*/
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, 1)) {
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, true)) {
goto bail_out;
}
sd = jcr->store_bsock;
Expand All @@ -177,7 +177,7 @@ static inline bool do_native_restore_bootstrap(JCR *jcr)
*/
jcr->setJobStatus(JS_WaitFD);
jcr->keep_sd_auth_key = true; /* don't clear the sd_auth_key now */
if (!connect_to_file_daemon(jcr, 10, me->FDConnectTimeout, 1)) {
if (!connect_to_file_daemon(jcr, 10, me->FDConnectTimeout, true, true)) {
goto bail_out;
}
fd = jcr->file_bsock;
Expand Down

0 comments on commit 6a4e8f7

Please sign in to comment.