PageRenderTime 70ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/amanda/tags/3_3_0_qa07/recover-src/set_commands.c

#
C | 875 lines | 682 code | 93 blank | 100 comment | 192 complexity | cdd444528c78d3e4d138e1b8833cf26f MD5 | raw file
  1. /*
  2. * Amanda, The Advanced Maryland Automatic Network Disk Archiver
  3. * Copyright (c) 1991-1998, 2000 University of Maryland at College Park
  4. * All Rights Reserved.
  5. *
  6. * Permission to use, copy, modify, distribute, and sell this software and its
  7. * documentation for any purpose is hereby granted without fee, provided that
  8. * the above copyright notice appear in all copies and that both that
  9. * copyright notice and this permission notice appear in supporting
  10. * documentation, and that the name of U.M. not be used in advertising or
  11. * publicity pertaining to distribution of the software without specific,
  12. * written prior permission. U.M. makes no representations about the
  13. * suitability of this software for any purpose. It is provided "as is"
  14. * without express or implied warranty.
  15. *
  16. * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
  18. * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  21. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. *
  23. * Authors: the Amanda Development Team. Its members are listed in a
  24. * file named AUTHORS, in the root directory of this distribution.
  25. */
  26. /*
  27. * $Id: set_commands.c,v 1.26 2006/07/05 13:14:58 martinea Exp $
  28. *
  29. * implements the "set" commands in amrecover
  30. */
  31. #include "amanda.h"
  32. #include "match.h"
  33. #include "util.h"
  34. #include "amrecover.h"
  35. #include "amxml.h"
  36. extern unsigned short samba_extract_method;
  37. /* sets a date, mapping given date into standard form if needed */
  38. int
  39. set_date(
  40. char * date)
  41. {
  42. char *cmd = NULL;
  43. char *qdisk_path;
  44. clear_dir_list();
  45. cmd = stralloc2("DATE ", date);
  46. if (converse(cmd) == -1)
  47. exit(1);
  48. /* if a host/disk/directory is set, then check if that directory
  49. is still valid at the new date, and if not set directory to
  50. mount_point */
  51. if (disk_path != NULL) {
  52. qdisk_path = quote_string(disk_path);
  53. cmd = newstralloc2(cmd, "OISD ", qdisk_path);
  54. amfree(qdisk_path);
  55. if (exchange(cmd) == -1)
  56. exit(1);
  57. if (server_happy())
  58. {
  59. suck_dir_list_from_server();
  60. }
  61. else
  62. {
  63. g_printf(_("No index records for cwd on new date\n"));
  64. g_printf(_("Setting cwd to mount point\n"));
  65. disk_path = newstralloc(disk_path, "/"); /* fake it */
  66. disk_tpath = newstralloc(disk_tpath, "/"); /* fake it */
  67. clear_dir_list();
  68. }
  69. }
  70. amfree(cmd);
  71. return 0;
  72. }
  73. void
  74. set_host(
  75. const char *host)
  76. {
  77. char *cmd = NULL;
  78. struct hostent *hp = NULL;
  79. char **hostp;
  80. int found_host = 0;
  81. char *uqhost = unquote_string(host);
  82. if (is_extract_list_nonempty())
  83. {
  84. g_printf(_("Must clear extract list before changing host\n"));
  85. amfree(uqhost);
  86. return;
  87. }
  88. /*
  89. * The idea here is to try as many permutations of the hostname
  90. * as we can imagine. The server will reject anything it doesn't
  91. * recognize.
  92. */
  93. cmd = stralloc2("HOST ", uqhost);
  94. if (converse(cmd) == -1)
  95. exit(1);
  96. if (server_happy())
  97. found_host = 1;
  98. /*
  99. * Try converting the given host to a fully qualified, canonical
  100. * name.
  101. */
  102. if (!found_host) {
  103. if ((hp = gethostbyname(uqhost)) != NULL) {
  104. host = hp->h_name;
  105. g_printf(_("Trying host %s ...\n"), host);
  106. cmd = newstralloc2(cmd, "HOST ", host);
  107. if (converse(cmd) == -1)
  108. exit(1);
  109. if(server_happy())
  110. found_host = 1;
  111. }
  112. }
  113. /*
  114. * Since we have them, try any CNAMEs that were traversed from uqhost
  115. * to the canonical name (this assumes gethostbyname was called above)
  116. */
  117. if (!found_host) {
  118. if (hp) {
  119. for (hostp = hp->h_aliases; (host = *hostp) != NULL; hostp++)
  120. {
  121. g_printf(_("Trying host %s ...\n"), host);
  122. cmd = newstralloc2(cmd, "HOST ", host);
  123. if (converse(cmd) == -1)
  124. exit(1);
  125. if(server_happy())
  126. {
  127. found_host = 1;
  128. break;
  129. }
  130. }
  131. }
  132. }
  133. /* Try looking up the canonical name of the host */
  134. if (!found_host) {
  135. char *canonname;
  136. int result;
  137. result = resolve_hostname(uqhost, 0, NULL, &canonname);
  138. if (result == 0 && canonname) {
  139. host = canonname;
  140. g_printf(_("Trying host %s ...\n"), host);
  141. cmd = newstralloc2(cmd, "HOST ", host);
  142. if (converse(cmd) == -1)
  143. exit(1);
  144. if(server_happy())
  145. found_host = 1;
  146. }
  147. }
  148. if(found_host) {
  149. dump_hostname = newstralloc(dump_hostname, host);
  150. amfree(disk_name);
  151. amfree(mount_point);
  152. amfree(disk_path);
  153. amfree(disk_tpath);
  154. clear_dir_list();
  155. }
  156. amfree(cmd);
  157. amfree(uqhost);
  158. }
  159. void
  160. list_host(void)
  161. {
  162. char *cmd = NULL;
  163. cmd = stralloc("LISTHOST");
  164. if (converse(cmd) == -1)
  165. exit(1);
  166. amfree(cmd);
  167. }
  168. void
  169. set_disk(
  170. char * dsk,
  171. char * mtpt)
  172. {
  173. char *cmd = NULL;
  174. char *qdsk;
  175. char *uqdsk;
  176. char *uqmtpt = NULL;
  177. if (is_extract_list_nonempty())
  178. {
  179. g_printf(_("Must clear extract list before changing disk\n"));
  180. return;
  181. }
  182. /* if mount point specified, check it is valid */
  183. if (mtpt != NULL) {
  184. uqmtpt = unquote_string(mtpt);
  185. if (*mtpt != '/') {
  186. g_printf(_("Mount point \"%s\" invalid - must start with /\n"), uqmtpt);
  187. amfree(uqmtpt);
  188. return;
  189. }
  190. }
  191. clear_dir_list();
  192. uqdsk = unquote_string(dsk);
  193. qdsk = quote_string(uqdsk);
  194. cmd = stralloc2("DISK ", qdsk);
  195. amfree(qdsk);
  196. if (converse(cmd) == -1)
  197. exit(1);
  198. amfree(cmd);
  199. if (!server_happy()) {
  200. amfree(uqmtpt);
  201. amfree(uqdsk);
  202. return;
  203. }
  204. disk_name = newstralloc(disk_name, uqdsk);
  205. if (mtpt == NULL)
  206. {
  207. /* mount point not specified */
  208. if (*uqdsk == '/')
  209. {
  210. /* disk specified by mount point, hence use it */
  211. mount_point = newstralloc(mount_point, uqdsk);
  212. }
  213. else
  214. {
  215. /* device name given, use '/' because nothing better */
  216. mount_point = newstralloc(mount_point, "/");
  217. }
  218. }
  219. else
  220. {
  221. /* mount point specified */
  222. mount_point = newstralloc(mount_point, uqmtpt);
  223. }
  224. /* set the working directory to the mount point */
  225. /* there is the possibility that there are no index records for the
  226. disk for the given date, hence setting the directory to the
  227. mount point will fail. Preempt this by checking first so we can write
  228. a more informative message. */
  229. if (exchange("OISD /") == -1)
  230. exit(1);
  231. if (server_happy())
  232. {
  233. disk_path = newstralloc(disk_path, "/");
  234. disk_tpath = newstralloc(disk_tpath, "/");
  235. suck_dir_list_from_server(); /* get list of directory contents */
  236. }
  237. else
  238. {
  239. g_printf(_("No index records for disk for specified date\n"));
  240. g_printf(_("If date correct, notify system administrator\n"));
  241. disk_path = newstralloc(disk_path, "/"); /* fake it */
  242. disk_tpath = newstralloc(disk_tpath, "/"); /* fake it */
  243. clear_dir_list();
  244. }
  245. amfree(uqmtpt);
  246. amfree(uqdsk);
  247. if (am_has_feature(indexsrv_features, fe_amindexd_DLE)) {
  248. char *dle_str;
  249. char *errmsg = NULL;
  250. cmd = stralloc("DLE");
  251. if (exchange(cmd) == -1)
  252. exit(1);
  253. amfree(cmd);
  254. if (!server_happy())
  255. return;
  256. dle_str = reply_line();
  257. if (BSTRNCMP(dle_str+4, "NODLE") == 0) {
  258. dump_dle = NULL;
  259. } else {
  260. dle_str = unquote_string(dle_str+4);
  261. dump_dle = amxml_parse_node_CHAR(dle_str, &errmsg);
  262. amfree(dle_str);
  263. }
  264. }
  265. }
  266. void
  267. list_disk(
  268. char * amdevice)
  269. {
  270. char *cmd = NULL;
  271. char *qamdevice, *uqamdevice;
  272. if(amdevice) {
  273. uqamdevice = unquote_string(amdevice);
  274. qamdevice = quote_string(uqamdevice);
  275. cmd = stralloc2("LISTDISK ", qamdevice);
  276. amfree(uqamdevice);
  277. amfree(qamdevice);
  278. if (converse(cmd) == -1)
  279. exit(1);
  280. amfree(cmd);
  281. }
  282. else {
  283. cmd = stralloc("LISTDISK");
  284. if (converse(cmd) == -1)
  285. exit(1);
  286. amfree(cmd);
  287. }
  288. }
  289. static GSList *prop_values = NULL;
  290. void
  291. set_property_name(
  292. char *name,
  293. int append)
  294. {
  295. property_t *prop;
  296. char *property_name, *pn;
  297. pn = unquote_string(name);
  298. property_name = amandaify_property_name(pn);
  299. amfree(pn);
  300. if (!append) {
  301. g_hash_table_remove(proplist, property_name);
  302. prop = NULL;
  303. } else {
  304. prop = g_hash_table_lookup(proplist, property_name);
  305. }
  306. if (!prop) {
  307. prop = malloc(sizeof(property_t));
  308. prop->append = 0;
  309. prop->priority = 1;
  310. prop->values = NULL;
  311. g_hash_table_insert(proplist, stralloc(property_name), prop);
  312. }
  313. /* add prop_values to prop->values */
  314. if (!prop->values) {
  315. prop->values = prop_values;
  316. prop_values = NULL;
  317. } else {
  318. GSList *pv;
  319. for(pv = prop_values; pv != NULL; pv = pv->next) {
  320. prop->values = g_slist_append(prop->values, pv->data);
  321. }
  322. g_slist_free(prop_values);
  323. prop_values = NULL;
  324. }
  325. amfree(property_name);
  326. }
  327. void
  328. add_property_value(
  329. char *value)
  330. {
  331. if (value) {
  332. prop_values = g_slist_prepend(prop_values, unquote_string(value));
  333. }
  334. }
  335. /* A GHFunc (callback for g_hash_table_foreach) */
  336. static void list_one_property(
  337. gpointer key_p,
  338. gpointer value_p,
  339. gpointer user_data_p G_GNUC_UNUSED)
  340. {
  341. char *property_s = key_p;
  342. char *qproperty;
  343. property_t *property = value_p;
  344. GSList *value;
  345. char *qvalue;
  346. qproperty = quote_string_always(property_s);
  347. printf("property %s", qproperty);
  348. amfree(qproperty);
  349. for (value = property->values; value != NULL; value = value->next) {
  350. qvalue = quote_string_always((char*)value->data);
  351. printf(" %s", qvalue);
  352. amfree(qvalue);
  353. }
  354. printf("\n");
  355. }
  356. void
  357. list_property(void)
  358. {
  359. if (proplist) {
  360. g_hash_table_foreach(proplist, list_one_property, NULL);
  361. } else {
  362. printf("No property set\n");
  363. }
  364. }
  365. void
  366. local_cd(
  367. char *dir)
  368. {
  369. char *uqdir = unquote_string(dir);
  370. if (chdir(uqdir) == -1) {
  371. perror(uqdir);
  372. }
  373. amfree(uqdir);
  374. }
  375. int
  376. cd_glob(
  377. char * glob,
  378. int verbose)
  379. {
  380. char *regex;
  381. char *regex_path;
  382. char *s;
  383. char *uqglob;
  384. int result;
  385. char *tpath_on_disk = NULL;
  386. if (disk_name == NULL) {
  387. g_printf(_("Must select disk before changing directory\n"));
  388. return 0;
  389. }
  390. uqglob = unquote_string(glob);
  391. regex = glob_to_regex(uqglob);
  392. dbprintf(_("cd_glob (%s) -> %s\n"), uqglob, regex);
  393. if ((s = validate_regexp(regex)) != NULL) {
  394. g_printf(_("\"%s\" is not a valid shell wildcard pattern: "), glob);
  395. puts(s);
  396. amfree(regex);
  397. amfree(uqglob);
  398. return 0;
  399. }
  400. /*
  401. * glob_to_regex() anchors the beginning of the pattern with ^,
  402. * but we will be tacking it onto the end of the current directory
  403. * in add_file, so strip that off. Also, it anchors the end with
  404. * $, but we need to match a trailing /, add it if it is not there
  405. */
  406. regex_path = stralloc(regex + 1);
  407. amfree(regex);
  408. if(regex_path[strlen(regex_path) - 2] != '/' ) {
  409. regex_path[strlen(regex_path) - 1] = '\0';
  410. strappend(regex_path, "/$");
  411. }
  412. /* convert path (assumed in cwd) to one on disk */
  413. if (strcmp(disk_path, "/") == 0)
  414. tpath_on_disk = stralloc2("/", regex_path);
  415. else {
  416. char *clean_disk_tpath = clean_regex(disk_tpath, 0);
  417. tpath_on_disk = vstralloc(clean_disk_tpath, "/", regex_path, NULL);
  418. amfree(clean_disk_tpath);
  419. }
  420. result = cd_dir(tpath_on_disk, uqglob, verbose);
  421. amfree(regex_path);
  422. amfree(tpath_on_disk);
  423. amfree(uqglob);
  424. return result;
  425. }
  426. int
  427. cd_regex(
  428. char * regex,
  429. int verbose)
  430. {
  431. char *s;
  432. char *uq_orig_regex;
  433. char *uqregex;
  434. int len_uqregex;
  435. int result;
  436. char *tpath_on_disk = NULL;
  437. if (disk_name == NULL) {
  438. g_printf(_("Must select disk before changing directory\n"));
  439. return 0;
  440. }
  441. uq_orig_regex = unquote_string(regex);
  442. uqregex = stralloc(uq_orig_regex);
  443. /* Add a terminating '/' if it is not there, maybe before a '$' */
  444. len_uqregex = strlen(uqregex);
  445. if (uqregex[len_uqregex-1] == '$') {
  446. if (uqregex[len_uqregex-2] != '/') {
  447. uqregex[len_uqregex-1] = '\0';
  448. strappend(uqregex, "/$");
  449. }
  450. } else if (uqregex[len_uqregex-1] != '/') {
  451. //uqregex[len_uqregex-1] = '\0';
  452. strappend(uqregex, "/");
  453. }
  454. if ((s = validate_regexp(uqregex)) != NULL) {
  455. g_printf(_("\"%s\" is not a valid regular expression: "), uq_orig_regex);
  456. amfree(uqregex);
  457. amfree(uq_orig_regex);
  458. puts(s);
  459. return 0;
  460. }
  461. /* convert path (assumed in cwd) to one on disk */
  462. if (strcmp(disk_path, "/") == 0)
  463. tpath_on_disk = stralloc2("/", uqregex);
  464. else {
  465. char *clean_disk_tpath = clean_regex(disk_tpath, 0);
  466. tpath_on_disk = vstralloc(clean_disk_tpath, "/", regex, NULL);
  467. amfree(clean_disk_tpath);
  468. }
  469. result = cd_dir(tpath_on_disk, uq_orig_regex, verbose);
  470. amfree(tpath_on_disk);
  471. amfree(uqregex);
  472. amfree(uq_orig_regex);
  473. return result;
  474. }
  475. int
  476. cd_dir(
  477. char *tpath_on_disk,
  478. char *default_dir,
  479. int verbose)
  480. {
  481. char *dir = NULL;
  482. char *s;
  483. int nb_found;
  484. int result;
  485. size_t i;
  486. DIR_ITEM *ditem;
  487. if ((s = validate_regexp(tpath_on_disk)) != NULL) {
  488. result = set_directory(default_dir, verbose);
  489. return result;
  490. }
  491. nb_found = 0;
  492. for (ditem=get_dir_list(); ditem!=NULL && nb_found <= 1;
  493. ditem=get_next_dir_item(ditem))
  494. {
  495. if (match(tpath_on_disk, ditem->tpath))
  496. {
  497. i = strlen(ditem->tpath);
  498. if((i > 0 && ditem->tpath[i-1] == '/')
  499. || (i > 1 && ditem->tpath[i-2] == '/' && ditem->tpath[i-1] == '.'))
  500. { /* It is a directory */
  501. char *dir1, *dir2;
  502. nb_found++;
  503. dir = newstralloc(dir,ditem->path);
  504. if(dir[strlen(dir)-1] == '/')
  505. dir[strlen(dir)-1] = '\0'; /* remove last / */
  506. /* remove everything before the last / */
  507. dir1 = strrchr(dir,'/');
  508. if (dir1) {
  509. dir1++;
  510. dir2 = stralloc(dir1);
  511. amfree(dir);
  512. dir = dir2;
  513. }
  514. }
  515. }
  516. }
  517. if(nb_found==0) {
  518. result = set_directory(default_dir, verbose);
  519. }
  520. else if(nb_found==1) {
  521. result = set_directory(dir, verbose);
  522. }
  523. else {
  524. g_printf(_("Too many directories matching '%s'\n"), default_dir);
  525. result = 0;
  526. }
  527. amfree(dir);
  528. return result;
  529. }
  530. /* dir is relative to dir_path or absolute with mount_point */
  531. int
  532. set_directory(
  533. char * dir,
  534. int verbose)
  535. {
  536. char *cmd = NULL;
  537. char *new_dir = NULL;
  538. char *qnew_dir;
  539. char *dp, *de;
  540. char *ldir = NULL;
  541. int result;
  542. /* do nothing if "." */
  543. if(strcmp(dir,".")==0) {
  544. show_directory(); /* say where we are */
  545. return 1;
  546. /*NOTREACHED*/
  547. }
  548. if (disk_name == NULL) {
  549. g_printf(_("Must select disk before setting directory\n"));
  550. return 0;
  551. /*NOTREACHED*/
  552. }
  553. ldir = stralloc(dir);
  554. clean_pathname(ldir);
  555. /* convert directory into absolute path relative to disk mount point */
  556. if (ldir[0] == '/')
  557. {
  558. /* absolute path specified, must start with mount point */
  559. if (strcmp(mount_point, "/") == 0)
  560. {
  561. new_dir = stralloc(ldir);
  562. }
  563. else
  564. {
  565. if (strncmp(mount_point, ldir, strlen(mount_point)) != 0)
  566. {
  567. g_printf(_("Invalid directory - Can't cd outside mount point \"%s\"\n"),
  568. mount_point);
  569. amfree(ldir);
  570. return 0;
  571. /*NOTREACHED*/
  572. }
  573. new_dir = stralloc(ldir+strlen(mount_point));
  574. if (strlen(new_dir) == 0) {
  575. new_dir = newstralloc(new_dir, "/");
  576. /* i.e. ldir == mount_point */
  577. }
  578. }
  579. }
  580. else
  581. {
  582. new_dir = stralloc(disk_path);
  583. dp = ldir;
  584. /* strip any leading ..s */
  585. while (strncmp(dp, "../", 3) == 0)
  586. {
  587. de = strrchr(new_dir, '/'); /* always at least 1 */
  588. if (de == new_dir)
  589. {
  590. /* at top of disk */
  591. *(de + 1) = '\0';
  592. dp = dp + 3;
  593. }
  594. else
  595. {
  596. *de = '\0';
  597. dp = dp + 3;
  598. }
  599. }
  600. if (strcmp(dp, "..") == 0) {
  601. if (strcmp(new_dir, "/") == 0) {
  602. /* at top of disk */
  603. g_printf(_("Invalid directory - Can't cd outside mount point \"%s\"\n"),
  604. mount_point);
  605. /*@ignore@*/
  606. amfree(new_dir);
  607. /*@end@*/
  608. amfree(ldir);
  609. return 0;
  610. /*NOTREACHED*/
  611. }
  612. de = strrchr(new_dir, '/'); /* always at least 1 */
  613. if (de == new_dir)
  614. {
  615. /* at top of disk */
  616. *(de+1) = '\0';
  617. }
  618. else
  619. {
  620. *de = '\0';
  621. }
  622. } else {
  623. /*@ignore@*/
  624. if (strcmp(new_dir, "/") != 0) {
  625. strappend(new_dir, "/");
  626. }
  627. strappend(new_dir, ldir);
  628. /*@end@*/
  629. }
  630. }
  631. qnew_dir = quote_string(new_dir);
  632. cmd = stralloc2("OISD ", qnew_dir);
  633. amfree(qnew_dir);
  634. if (exchange(cmd) == -1) {
  635. exit(1);
  636. /*NOTREACHED*/
  637. }
  638. amfree(cmd);
  639. if (server_happy())
  640. {
  641. disk_path = newstralloc(disk_path, new_dir);
  642. g_free(disk_tpath);
  643. disk_tpath = translate_octal(g_strdup(disk_path));
  644. suck_dir_list_from_server(); /* get list of directory contents */
  645. if (verbose)
  646. show_directory(); /* say where we moved to */
  647. result = 1;
  648. }
  649. else
  650. {
  651. g_printf(_("Invalid directory - %s\n"), dir);
  652. result = 0;
  653. }
  654. /*@ignore@*/
  655. amfree(new_dir);
  656. amfree(ldir);
  657. /*@end@*/
  658. return result;
  659. }
  660. /* prints the current working directory */
  661. void
  662. show_directory(void)
  663. {
  664. if (mount_point == NULL || disk_path == NULL)
  665. g_printf(_("Must select disk first\n"));
  666. else if (strcmp(mount_point, "/") == 0)
  667. g_printf("%s\n", disk_tpath);
  668. else if (strcmp(disk_path, "/") == 0)
  669. g_printf("%s\n", mount_point);
  670. else
  671. g_printf("%s%s\n", mount_point, disk_tpath);
  672. }
  673. /* set the tape server and device (deprecated version) */
  674. void
  675. set_tape(
  676. char * tape)
  677. {
  678. char *uqtape = unquote_string(tape);
  679. char *tapedev = strchr(uqtape, ':');
  680. char *host = NULL;
  681. g_printf(_("NOTE: 'settape' is deprecated; use setdevice instead.\n"));
  682. if (tapedev)
  683. {
  684. /* This command is deprecated because this parsing is going to fall
  685. * behind the list of available device names at some point, or to shadow
  686. * an interesting hostname (wouldn't 'tape' be a good name for a
  687. * tape server?) */
  688. if (tapedev != uqtape) {
  689. if((strchr(tapedev+1, ':') == NULL) &&
  690. (strncmp_const(uqtape, "null:") == 0 ||
  691. strncmp_const(uqtape, "rait:") == 0 ||
  692. strncmp_const(uqtape, "file:") == 0 ||
  693. strncmp_const(uqtape, "s3:") == 0 ||
  694. strncmp_const(uqtape, "tape:") == 0)) {
  695. tapedev = uqtape;
  696. }
  697. else {
  698. *tapedev = '\0';
  699. host = stralloc(uqtape);
  700. ++tapedev;
  701. }
  702. } else {
  703. ++tapedev;
  704. }
  705. } else
  706. tapedev = uqtape;
  707. if (tapedev[0])
  708. {
  709. if (strcmp(tapedev, "default") == 0)
  710. tapedev = NULL;
  711. }
  712. /* call out to the new version */
  713. set_device(host, tapedev);
  714. amfree(host);
  715. amfree(uqtape);
  716. }
  717. /* set the tape server and device, for real */
  718. void
  719. set_device(
  720. char * host,
  721. char * device)
  722. {
  723. if (host)
  724. tape_server_name = newstralloc(tape_server_name, host);
  725. else
  726. amfree(tape_server_name);
  727. if (device)
  728. tape_device_name = newstralloc(tape_device_name, device);
  729. else
  730. amfree(tape_device_name);
  731. /* print the current status */
  732. if (tape_device_name)
  733. g_printf (_("Using tape \"%s\""), tape_device_name);
  734. else
  735. g_printf (_("Using default tape"));
  736. if (tape_server_name)
  737. g_printf (_(" from server %s.\n"), tape_server_name);
  738. else
  739. g_printf (_(".\nTape server unspecified, assumed to be %s.\n"),
  740. server_name);
  741. }
  742. void
  743. set_translate(
  744. char *translate)
  745. {
  746. if (translate == NULL) {
  747. translate_mode = TRUE;
  748. } else if (strcasecmp(translate, "yes") == 0 ||
  749. strcasecmp(translate, "true") == 0 ||
  750. strcasecmp(translate, "on") == 0) {
  751. translate_mode = TRUE;
  752. } else {
  753. translate_mode = FALSE;
  754. }
  755. suck_dir_list_from_server(); /* get list of directory contents */
  756. }
  757. void
  758. set_mode(
  759. int mode)
  760. {
  761. if (mode == SAMBA_SMBCLIENT) {
  762. g_printf (_("SAMBA dumps will be extracted using smbclient\n"));
  763. samba_extract_method = SAMBA_SMBCLIENT;
  764. } else {
  765. if (mode == SAMBA_TAR) {
  766. g_printf (_("SAMBA dumps will be extracted as TAR dumps\n"));
  767. samba_extract_method = SAMBA_TAR;
  768. }
  769. }
  770. }
  771. void
  772. show_mode(void)
  773. {
  774. #ifdef SAMBA_CLIENT
  775. g_printf (_("SAMBA dumps are extracted "));
  776. if (samba_extract_method == SAMBA_TAR) {
  777. g_printf (_(" as TAR dumps\n"));
  778. } else {
  779. g_printf (_("using smbclient\n"));
  780. }
  781. #endif /* SAMBA_CLIENT */
  782. }