void set_host( const char *host) { char *cmd = NULL; struct hostent *hp = NULL; char **hostp; int found_host = 0; char *uqhost = unquote_string(host); if (is_extract_list_nonempty()) { g_printf(_("Must clear extract list before changing host\n")); amfree(uqhost); return; } /* * The idea here is to try as many permutations of the hostname * as we can imagine. The server will reject anything it doesn't * recognize. */ cmd = stralloc2("HOST ", uqhost); if (converse(cmd) == -1) exit(1); if (server_happy()) found_host = 1; /* * Try converting the given host to a fully qualified, canonical * name. */ if (!found_host) { if ((hp = gethostbyname(uqhost)) != NULL) { host = hp->h_name; g_printf(_("Trying host %s ...\n"), host); cmd = newstralloc2(cmd, "HOST ", host); if (converse(cmd) == -1) exit(1); if(server_happy()) found_host = 1; } } /* * Since we have them, try any CNAMEs that were traversed from uqhost * to the canonical name (this assumes gethostbyname was called above) */ if (!found_host) { if (hp) { for (hostp = hp->h_aliases; (host = *hostp) != NULL; hostp++) { g_printf(_("Trying host %s ...\n"), host); cmd = newstralloc2(cmd, "HOST ", host); if (converse(cmd) == -1) exit(1); if(server_happy()) { found_host = 1; break; } } } } /* Try looking up the canonical name of the host */ if (!found_host) { char *canonname; int result; result = resolve_hostname(uqhost, 0, NULL, &canonname); if (result == 0 && canonname) { host = canonname; g_printf(_("Trying host %s ...\n"), host); cmd = newstralloc2(cmd, "HOST ", host); if (converse(cmd) == -1) exit(1); if(server_happy()) found_host = 1; } } if(found_host) { dump_hostname = newstralloc(dump_hostname, host); amfree(disk_name); amfree(mount_point); amfree(disk_path); clear_dir_list(); } amfree(cmd); amfree(uqhost); }
void set_host( const char * host) { char *cmd = NULL; struct hostent *hp; char **hostp; int found_host = 0; char *uqhost; if (is_extract_list_nonempty()) { g_printf(_("Must clear extract list before changing host\n")); return; } uqhost = unquote_string(host); cmd = g_strconcat("HOST ", uqhost, NULL); if (converse(cmd) == -1) exit(1); if (server_happy()) { found_host = 1; } else { /* * Try converting the given host to a fully qualified name * and then try each of the aliases. */ if ((hp = gethostbyname(uqhost)) != NULL) { host = hp->h_name; g_printf(_("Trying host %s ...\n"), host); g_free(cmd); cmd = g_strconcat("HOST ", host, NULL); if (converse(cmd) == -1) exit(1); if(server_happy()) { found_host = 1; } else { for (hostp = hp->h_aliases; (host = *hostp) != NULL; hostp++) { g_printf(_("Trying host %s ...\n"), host); g_free(cmd); cmd = g_strconcat("HOST ", host, NULL); if (converse(cmd) == -1) exit(1); if(server_happy()) { found_host = 1; break; } } } } } if(found_host) { g_free(dump_hostname); dump_hostname = g_strdup(host); amfree(disk_name); amfree(mount_point); amfree(disk_path); clear_dir_list(); } amfree(cmd); amfree(uqhost); }
void set_disk( char * dsk, char * mtpt) { char *cmd = NULL; char *qdsk; char *uqdsk; char *uqmtpt = NULL; if (is_extract_list_nonempty()) { g_printf(_("Must clear extract list before changing disk\n")); return; } /* if mount point specified, check it is valid */ if (mtpt != NULL) { uqmtpt = unquote_string(mtpt); if (*mtpt != '/') { g_printf(_("Mount point \"%s\" invalid - must start with /\n"), uqmtpt); amfree(uqmtpt); return; } } clear_dir_list(); uqdsk = unquote_string(dsk); qdsk = quote_string(uqdsk); cmd = stralloc2("DISK ", qdsk); amfree(qdsk); if (converse(cmd) == -1) exit(1); amfree(cmd); if (!server_happy()) { amfree(uqmtpt); amfree(uqdsk); return; } disk_name = newstralloc(disk_name, uqdsk); if (mtpt == NULL) { /* mount point not specified */ if (*uqdsk == '/') { /* disk specified by mount point, hence use it */ mount_point = newstralloc(mount_point, uqdsk); } else { /* device name given, use '/' because nothing better */ mount_point = newstralloc(mount_point, "/"); } } else { /* mount point specified */ mount_point = newstralloc(mount_point, uqmtpt); } /* set the working directory to the mount point */ /* there is the possibility that there are no index records for the disk for the given date, hence setting the directory to the mount point will fail. Preempt this by checking first so we can write a more informative message. */ if (exchange("OISD /") == -1) exit(1); if (server_happy()) { disk_path = newstralloc(disk_path, "/"); suck_dir_list_from_server(); /* get list of directory contents */ } else { g_printf(_("No index records for disk for specified date\n")); g_printf(_("If date correct, notify system administrator\n")); disk_path = newstralloc(disk_path, "/"); /* fake it */ clear_dir_list(); } amfree(uqmtpt); amfree(uqdsk); if (am_has_feature(indexsrv_features, fe_amindexd_DLE)) { char *dle_str; char *errmsg = NULL; cmd = stralloc("DLE"); if (exchange(cmd) == -1) exit(1); amfree(cmd); if (!server_happy()) return; dle_str = reply_line(); if (BSTRNCMP(dle_str+4, "NODLE") == 0) { dump_dle = NULL; } else { dle_str = unquote_string(dle_str+4); dump_dle = amxml_parse_node_CHAR(dle_str, &errmsg); amfree(dle_str); } } }
void set_disk( char * dsk, char * mtpt) { char *cmd = NULL; char *uqdsk; char *uqmtpt = NULL; if (is_extract_list_nonempty()) { g_printf(_("Must clear extract list before changing disk\n")); return; } /* if mount point specified, check it is valid */ if (mtpt != NULL) { uqmtpt = unquote_string(mtpt); if (*mtpt != '/') { g_printf(_("Mount point \"%s\" invalid - must start with /\n"), uqmtpt); amfree(uqmtpt); return; } } clear_dir_list(); uqdsk = unquote_string(dsk); cmd = g_strconcat("DISK ", uqdsk, NULL); if (converse(cmd) == -1) exit(1); amfree(cmd); if (!server_happy()) { amfree(uqdsk); amfree(uqmtpt); return; } g_free(disk_name); disk_name = g_strdup(uqdsk); if (mtpt == NULL) { /* mount point not specified */ if (*uqdsk == '/') { /* disk specified by mount point, hence use it */ g_free(mount_point); mount_point = g_strdup(uqdsk); } else { /* device name given, use '/' because nothing better */ g_free(mount_point); mount_point = g_strdup("/"); } } else { /* mount point specified */ g_free(mount_point); mount_point = g_strdup(uqmtpt); } /* set the working directory to the mount point */ /* there is the possibility that there are no index records for the disk for the given date, hence setting the directory to the mount point will fail. Preempt this by checking first so we can write a more informative message. */ if (exchange("OISD /") == -1) exit(1); if (server_happy()) { g_free(disk_path); disk_path = g_strdup("/"); suck_dir_list_from_server(); /* get list of directory contents */ } else { g_printf(_("No index records for disk for specified date\n")); g_printf(_("If date correct, notify system administrator\n")); g_free(disk_path); disk_path = g_strdup("/"); /* fake it */ clear_dir_list(); } amfree(uqmtpt); amfree(uqdsk); }