main.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /* snac - A simple, minimalistic ActivityPub instance */
  2. /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */
  3. #include "xs.h"
  4. #include "xs_io.h"
  5. #include "xs_json.h"
  6. #include "xs_time.h"
  7. #include "xs_openssl.h"
  8. #include "xs_match.h"
  9. #include "snac.h"
  10. #include <sys/stat.h>
  11. int usage(void)
  12. {
  13. printf("snac " VERSION " - A simple, minimalistic ActivityPub instance\n");
  14. printf("Copyright (c) 2022 - 2025 grunfink et al. / MIT license\n");
  15. printf("\n");
  16. printf("Commands:\n");
  17. printf("\n");
  18. printf("init [{basedir}] Initializes the data storage\n");
  19. printf("upgrade {basedir} Upgrade to a new version\n");
  20. printf("adduser {basedir} [{uid}] Adds a new user\n");
  21. printf("deluser {basedir} {uid} Deletes a user\n");
  22. printf("httpd {basedir} Starts the HTTPD daemon\n");
  23. printf("purge {basedir} Purges old data\n");
  24. printf("state {basedir} Prints server state\n");
  25. printf("webfinger {basedir} {account} Queries about an account (@user@host or actor url)\n");
  26. printf("queue {basedir} {uid} Processes a user queue\n");
  27. printf("follow {basedir} {uid} {actor} Follows an actor\n");
  28. printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n");
  29. printf("request {basedir} {uid} {url} Requests an object\n");
  30. printf("insert {basedir} {uid} {url} Requests an object and inserts it into the timeline\n");
  31. printf("actor {basedir} [{uid}] {url} Requests an actor\n");
  32. printf("note {basedir} {uid} {text} [files...] Sends a note with optional attachments\n");
  33. printf("note_unlisted {basedir} {uid} {text} [files...] Sends an unlisted note with optional attachments\n");
  34. printf("note_mention {basedir} {uid} {text} [files...] Sends a note only to mentioned accounts\n");
  35. printf("boost|announce {basedir} {uid} {url} Boosts (announces) a post\n");
  36. printf("unboost {basedir} {uid} {url} Unboosts a post\n");
  37. printf("resetpwd {basedir} {uid} Resets the password of a user\n");
  38. printf("ping {basedir} {uid} {actor} Pings an actor\n");
  39. printf("webfinger_s {basedir} {uid} {account} Queries about an account (@user@host or actor url)\n");
  40. printf("pin {basedir} {uid} {msg_url} Pins a message\n");
  41. printf("unpin {basedir} {uid} {msg_url} Unpins a message\n");
  42. printf("bookmark {basedir} {uid} {msg_url} Bookmarks a message\n");
  43. printf("unbookmark {basedir} {uid} {msg_url} Unbookmarks a message\n");
  44. printf("block {basedir} {instance_url} Blocks a full instance\n");
  45. printf("unblock {basedir} {instance_url} Unblocks a full instance\n");
  46. printf("limit {basedir} {uid} {actor} Limits an actor (drops their announces)\n");
  47. printf("unlimit {basedir} {uid} {actor} Unlimits an actor\n");
  48. printf("unmute {basedir} {uid} {actor} Unmutes a previously muted actor\n");
  49. printf("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n");
  50. printf("search {basedir} {uid} {regex} Searches posts by content\n");
  51. printf("export_csv {basedir} {uid} Exports data as CSV files\n");
  52. printf("alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n");
  53. printf("migrate {basedir} {uid} Migrates to the account defined as the alias\n");
  54. printf("import_csv {basedir} {uid} Imports data from CSV files\n");
  55. printf("import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n");
  56. printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n");
  57. return 1;
  58. }
  59. char *get_argv(int *argi, int argc, char *argv[])
  60. {
  61. if (*argi < argc)
  62. return argv[(*argi)++];
  63. else
  64. return NULL;
  65. }
  66. #define GET_ARGV() get_argv(&argi, argc, argv)
  67. int main(int argc, char *argv[])
  68. {
  69. char *cmd;
  70. char *basedir;
  71. char *user;
  72. char *url;
  73. int argi = 1;
  74. snac snac;
  75. /* ensure group has write access */
  76. umask(0007);
  77. if ((cmd = GET_ARGV()) == NULL)
  78. return usage();
  79. if (strcmp(cmd, "init") == 0) { /** **/
  80. /* initialize the data storage */
  81. /* ... */
  82. basedir = GET_ARGV();
  83. return snac_init(basedir);
  84. }
  85. if (strcmp(cmd, "markdown") == 0) { /** **/
  86. /* undocumented, for testing only */
  87. xs *c = xs_readall(stdin);
  88. xs *fc = not_really_markdown(c, NULL, NULL);
  89. printf("<html>\n%s\n</html>\n", fc);
  90. return 0;
  91. }
  92. if ((basedir = getenv("SNAC_BASEDIR")) == NULL) {
  93. if ((basedir = GET_ARGV()) == NULL)
  94. return usage();
  95. }
  96. if (strcmp(cmd, "upgrade") == 0) { /** **/
  97. int ret;
  98. /* upgrade */
  99. if ((ret = srv_open(basedir, 1)) == 1)
  100. srv_log(xs_dup("OK"));
  101. return ret;
  102. }
  103. if (!srv_open(basedir, 0)) {
  104. srv_log(xs_fmt("error opening data storage at %s", basedir));
  105. return 1;
  106. }
  107. if (strcmp(cmd, "adduser") == 0) { /** **/
  108. user = GET_ARGV();
  109. return adduser(user);
  110. return 0;
  111. }
  112. if (strcmp(cmd, "httpd") == 0) { /** **/
  113. httpd();
  114. srv_free();
  115. return 0;
  116. }
  117. if (strcmp(cmd, "purge") == 0) { /** **/
  118. purge_all();
  119. return 0;
  120. }
  121. if (strcmp(cmd, "state") == 0) { /** **/
  122. xs *shm_name = NULL;
  123. srv_state *p_state = srv_state_op(&shm_name, 1);
  124. if (p_state == NULL)
  125. return 1;
  126. srv_state ss = *p_state;
  127. int n;
  128. printf("server: %s (%s)\n", xs_dict_get(srv_config, "host"), USER_AGENT);
  129. xs *uptime = xs_str_time_diff(time(NULL) - ss.srv_start_time);
  130. printf("uptime: %s\n", uptime);
  131. printf("job fifo size (cur): %d\n", ss.job_fifo_size);
  132. printf("job fifo size (peak): %d\n", ss.peak_job_fifo_size);
  133. char *th_states[] = { "stopped", "waiting", "input", "output" };
  134. for (n = 0; n < ss.n_threads; n++)
  135. printf("thread #%d state: %s\n", n, th_states[ss.th_state[n]]);
  136. return 0;
  137. }
  138. if ((user = GET_ARGV()) == NULL)
  139. return usage();
  140. if (strcmp(cmd, "block") == 0) { /** **/
  141. int ret = instance_block(user);
  142. if (ret < 0) {
  143. fprintf(stderr, "Error blocking instance %s: %d\n", user, ret);
  144. return 1;
  145. }
  146. return 0;
  147. }
  148. if (strcmp(cmd, "unblock") == 0) { /** **/
  149. int ret = instance_unblock(user);
  150. if (ret < 0) {
  151. fprintf(stderr, "Error unblocking instance %s: %d\n", user, ret);
  152. return 1;
  153. }
  154. return 0;
  155. }
  156. if (strcmp(cmd, "webfinger") == 0) { /** **/
  157. xs *actor = NULL;
  158. xs *uid = NULL;
  159. int status;
  160. status = webfinger_request(user, &actor, &uid);
  161. printf("status: %d\n", status);
  162. if (actor != NULL)
  163. printf("actor: %s\n", actor);
  164. if (uid != NULL)
  165. printf("uid: %s\n", uid);
  166. return 0;
  167. }
  168. if (argi == argc && strcmp(cmd, "actor") == 0) { /** **/
  169. /* query an actor without user (non-signed) */
  170. xs *actor = NULL;
  171. int status;
  172. status = actor_request(NULL, user, &actor);
  173. printf("status: %d\n", status);
  174. if (valid_status(status)) {
  175. xs_json_dump(actor, 4, stdout);
  176. printf("\n");
  177. }
  178. return 0;
  179. }
  180. if (!user_open(&snac, user)) {
  181. printf("invalid user '%s'\n", user);
  182. return 1;
  183. }
  184. lastlog_write(&snac, "cmdline");
  185. if (strcmp(cmd, "resetpwd") == 0) { /** **/
  186. return resetpwd(&snac);
  187. }
  188. if (strcmp(cmd, "deluser") == 0) { /** **/
  189. return deluser(&snac);
  190. }
  191. if (strcmp(cmd, "update") == 0) { /** **/
  192. xs *a_msg = msg_actor(&snac);
  193. xs *u_msg = msg_update(&snac, a_msg);
  194. enqueue_message(&snac, u_msg);
  195. return 0;
  196. }
  197. if (strcmp(cmd, "queue") == 0) { /** **/
  198. process_user_queue(&snac);
  199. return 0;
  200. }
  201. if (strcmp(cmd, "verify_links") == 0) { /** **/
  202. verify_links(&snac);
  203. return 0;
  204. }
  205. if (strcmp(cmd, "timeline") == 0) { /** **/
  206. #if 0
  207. xs *list = local_list(&snac, XS_ALL);
  208. xs *body = html_timeline(&snac, list, 1);
  209. printf("%s\n", body);
  210. user_free(&snac);
  211. srv_free();
  212. #endif
  213. xs *idx = xs_fmt("%s/private.idx", snac.basedir);
  214. xs *list = index_list_desc(idx, 0, 256);
  215. xs *tl = timeline_top_level(&snac, list);
  216. xs_json_dump(tl, 4, stdout);
  217. return 0;
  218. }
  219. if (strcmp(cmd, "export_csv") == 0) { /** **/
  220. export_csv(&snac);
  221. return 0;
  222. }
  223. if (strcmp(cmd, "import_csv") == 0) { /** **/
  224. import_csv(&snac);
  225. return 0;
  226. }
  227. if (strcmp(cmd, "migrate") == 0) { /** **/
  228. return migrate_account(&snac);
  229. }
  230. if ((url = GET_ARGV()) == NULL)
  231. return usage();
  232. if (strcmp(cmd, "alias") == 0) { /** **/
  233. xs *actor = NULL;
  234. xs *uid = NULL;
  235. int status = HTTP_STATUS_OK;
  236. if (*url == '\0')
  237. actor = xs_dup("");
  238. else
  239. status = webfinger_request(url, &actor, &uid);
  240. if (valid_status(status)) {
  241. if (strcmp(actor, snac.actor) == 0) {
  242. snac_log(&snac, xs_fmt("You can't be your own alias"));
  243. return 1;
  244. }
  245. else {
  246. snac.config = xs_dict_set(snac.config, "alias", actor);
  247. snac.config = xs_dict_set(snac.config, "alias_raw", url);
  248. user_persist(&snac, 1);
  249. }
  250. }
  251. else {
  252. snac_log(&snac, xs_fmt("Webfinger error for %s %d", url, status));
  253. return 1;
  254. }
  255. return 0;
  256. }
  257. if (strcmp(cmd, "webfinger_s") == 0) { /** **/
  258. xs *actor = NULL;
  259. xs *uid = NULL;
  260. int status;
  261. status = webfinger_request_signed(&snac, url, &actor, &uid);
  262. printf("status: %d\n", status);
  263. if (actor != NULL)
  264. printf("actor: %s\n", actor);
  265. if (uid != NULL)
  266. printf("uid: %s\n", uid);
  267. return 0;
  268. }
  269. if (strcmp(cmd, "boost") == 0 || strcmp(cmd, "announce") == 0) { /** **/
  270. xs *msg = msg_admiration(&snac, url, "Announce");
  271. if (msg != NULL) {
  272. enqueue_message(&snac, msg);
  273. if (dbglevel) {
  274. xs_json_dump(msg, 4, stdout);
  275. }
  276. }
  277. return 0;
  278. }
  279. if (strcmp(cmd, "assist") == 0) { /** **/
  280. /* undocumented: experimental (do not use) */
  281. xs *msg = msg_admiration(&snac, url, "Accept");
  282. if (msg != NULL) {
  283. enqueue_message(&snac, msg);
  284. if (dbglevel) {
  285. xs_json_dump(msg, 4, stdout);
  286. }
  287. }
  288. return 0;
  289. }
  290. if (strcmp(cmd, "unboost") == 0) { /** **/
  291. xs *msg = msg_repulsion(&snac, url, "Announce");
  292. if (msg != NULL) {
  293. enqueue_message(&snac, msg);
  294. if (dbglevel) {
  295. xs_json_dump(msg, 4, stdout);
  296. }
  297. }
  298. return 0;
  299. }
  300. if (strcmp(cmd, "follow") == 0) { /** **/
  301. xs *msg = msg_follow(&snac, url);
  302. if (msg != NULL) {
  303. const char *actor = xs_dict_get(msg, "object");
  304. following_add(&snac, actor, msg);
  305. enqueue_output_by_actor(&snac, msg, actor, 0);
  306. if (dbglevel) {
  307. xs_json_dump(msg, 4, stdout);
  308. }
  309. }
  310. return 0;
  311. }
  312. if (strcmp(cmd, "unfollow") == 0) { /** **/
  313. xs *object = NULL;
  314. if (valid_status(following_get(&snac, url, &object))) {
  315. xs *msg = msg_undo(&snac, xs_dict_get(object, "object"));
  316. following_del(&snac, url);
  317. enqueue_output_by_actor(&snac, msg, url, 0);
  318. snac_log(&snac, xs_fmt("unfollowed actor %s", url));
  319. }
  320. else
  321. snac_log(&snac, xs_fmt("actor is not being followed %s", url));
  322. return 0;
  323. }
  324. if (strcmp(cmd, "limit") == 0) { /** **/
  325. int ret;
  326. if (!following_check(&snac, url))
  327. snac_log(&snac, xs_fmt("actor %s is not being followed", url));
  328. else
  329. if ((ret = limit(&snac, url)) == 0)
  330. snac_log(&snac, xs_fmt("actor %s is now limited", url));
  331. else
  332. snac_log(&snac, xs_fmt("error limiting actor %s (%d)", url, ret));
  333. return 0;
  334. }
  335. if (strcmp(cmd, "unlimit") == 0) { /** **/
  336. int ret;
  337. if (!following_check(&snac, url))
  338. snac_log(&snac, xs_fmt("actor %s is not being followed", url));
  339. else
  340. if ((ret = unlimit(&snac, url)) == 0)
  341. snac_log(&snac, xs_fmt("actor %s is no longer limited", url));
  342. else
  343. snac_log(&snac, xs_fmt("error unlimiting actor %s (%d)", url, ret));
  344. return 0;
  345. }
  346. if (strcmp(cmd, "unmute") == 0) { /** **/
  347. if (is_muted(&snac, url)) {
  348. unmute(&snac, url);
  349. printf("%s unmuted\n", url);
  350. }
  351. else
  352. printf("%s actor is not muted\n", url);
  353. return 0;
  354. }
  355. if (strcmp(cmd, "search") == 0) { /** **/
  356. int to;
  357. /* 'url' contains the regex */
  358. xs *r = content_search(&snac, url, 1, 0, XS_ALL, 10, &to);
  359. int c = 0;
  360. const char *v;
  361. /* print results as standalone links */
  362. while (xs_list_next(r, &v, &c)) {
  363. printf("%s/admin/p/%s\n", snac.actor, v);
  364. }
  365. return 0;
  366. }
  367. if (strcmp(cmd, "ping") == 0) { /** **/
  368. xs *actor_o = NULL;
  369. if (!xs_startswith(url, "https:/")) {
  370. /* try to resolve via webfinger */
  371. if (!valid_status(webfinger_request(url, &url, NULL))) {
  372. srv_log(xs_fmt("cannot resolve %s via webfinger", url));
  373. return 1;
  374. }
  375. }
  376. if (valid_status(actor_request(&snac, url, &actor_o))) {
  377. xs *msg = msg_ping(&snac, url);
  378. enqueue_output_by_actor(&snac, msg, url, 0);
  379. if (dbglevel) {
  380. xs_json_dump(msg, 4, stdout);
  381. }
  382. srv_log(xs_fmt("Ping sent to %s -- see log for Pong reply", url));
  383. }
  384. else {
  385. srv_log(xs_fmt("Error getting actor %s", url));
  386. return 1;
  387. }
  388. return 0;
  389. }
  390. if (strcmp(cmd, "pin") == 0) { /** **/
  391. int ret = pin(&snac, url);
  392. if (ret < 0) {
  393. fprintf(stderr, "error pinning %s %d\n", url, ret);
  394. return 1;
  395. }
  396. return 0;
  397. }
  398. if (strcmp(cmd, "unpin") == 0) { /** **/
  399. int ret = unpin(&snac, url);
  400. if (ret < 0) {
  401. fprintf(stderr, "error unpinning %s %d\n", url, ret);
  402. return 1;
  403. }
  404. return 0;
  405. }
  406. if (strcmp(cmd, "bookmark") == 0) { /** **/
  407. int ret = bookmark(&snac, url);
  408. if (ret < 0) {
  409. fprintf(stderr, "error bookmarking %s %d\n", url, ret);
  410. return 1;
  411. }
  412. return 0;
  413. }
  414. if (strcmp(cmd, "unbookmark") == 0) { /** **/
  415. int ret = unbookmark(&snac, url);
  416. if (ret < 0) {
  417. fprintf(stderr, "error unbookmarking %s %d\n", url, ret);
  418. return 1;
  419. }
  420. return 0;
  421. }
  422. if (strcmp(cmd, "question") == 0) { /** **/
  423. int end_secs = 5 * 60;
  424. xs *opts = xs_split(url, ";");
  425. xs *msg = msg_question(&snac, "Poll", NULL, opts, 0, end_secs);
  426. xs *c_msg = msg_create(&snac, msg);
  427. if (dbglevel) {
  428. xs_json_dump(c_msg, 4, stdout);
  429. }
  430. enqueue_message(&snac, c_msg);
  431. enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs);
  432. timeline_add(&snac, xs_dict_get(msg, "id"), msg);
  433. return 0;
  434. }
  435. if (strcmp(cmd, "request") == 0) { /** **/
  436. int status;
  437. xs *data = NULL;
  438. status = activitypub_request(&snac, url, &data);
  439. printf("status: %d\n", status);
  440. if (data != NULL) {
  441. xs_json_dump(data, 4, stdout);
  442. }
  443. return 0;
  444. }
  445. if (strcmp(cmd, "insert") == 0) { /** **/
  446. int status;
  447. xs *data = NULL;
  448. status = activitypub_request(&snac, url, &data);
  449. printf("status: %d\n", status);
  450. if (data != NULL) {
  451. xs_json_dump(data, 4, stdout);
  452. enqueue_actor_refresh(&snac, xs_dict_get(data, "attributedTo"), 0);
  453. if (!timeline_here(&snac, url))
  454. timeline_add(&snac, url, data);
  455. else
  456. printf("Post %s already here\n", url);
  457. }
  458. return 0;
  459. }
  460. if (strcmp(cmd, "request2") == 0) { /** **/
  461. enqueue_object_request(&snac, url, 2);
  462. return 0;
  463. }
  464. if (strcmp(cmd, "actor") == 0) { /** **/
  465. int status;
  466. xs *data = NULL;
  467. status = actor_request(&snac, url, &data);
  468. printf("status: %d\n", status);
  469. if (valid_status(status)) {
  470. xs_json_dump(data, 4, stdout);
  471. }
  472. return 0;
  473. }
  474. if (strcmp(cmd, "import_list") == 0) { /** **/
  475. import_list_csv(&snac, url);
  476. return 0;
  477. }
  478. if (strcmp(cmd, "import_block_list") == 0) { /** **/
  479. import_blocked_accounts_csv(&snac, url);
  480. return 0;
  481. }
  482. if (strcmp(cmd, "note") == 0 || /** **/
  483. strcmp(cmd, "note_unlisted") == 0 || /** **/
  484. strcmp(cmd, "note_mention") == 0) { /** **/
  485. xs *content = NULL;
  486. xs *msg = NULL;
  487. xs *c_msg = NULL;
  488. xs *attl = xs_list_new();
  489. char *fn = NULL;
  490. /* iterate possible attachments */
  491. while ((fn = GET_ARGV())) {
  492. FILE *f;
  493. if ((f = fopen(fn, "rb")) != NULL) {
  494. /* get the file size and content */
  495. fseek(f, 0, SEEK_END);
  496. int sz = ftell(f);
  497. fseek(f, 0, SEEK_SET);
  498. xs *atc = xs_readall(f);
  499. fclose(f);
  500. char *ext = strrchr(fn, '.');
  501. xs *hash = xs_md5_hex(fn, strlen(fn));
  502. xs *id = xs_fmt("%s%s", hash, ext);
  503. xs *url = xs_fmt("%s/s/%s", snac.actor, id);
  504. /* store */
  505. static_put(&snac, id, atc, sz);
  506. xs *l = xs_list_new();
  507. l = xs_list_append(l, url);
  508. l = xs_list_append(l, ""); /* alt text */
  509. attl = xs_list_append(attl, l);
  510. }
  511. else
  512. fprintf(stderr, "Error opening '%s' as attachment\n", fn);
  513. }
  514. if (strcmp(url, "-e") == 0) {
  515. /* get the content from an editor */
  516. FILE *f;
  517. unlink("/tmp/snac-edit.txt");
  518. system("$EDITOR /tmp/snac-edit.txt");
  519. if ((f = fopen("/tmp/snac-edit.txt", "r")) != NULL) {
  520. content = xs_readall(f);
  521. fclose(f);
  522. unlink("/tmp/snac-edit.txt");
  523. }
  524. else {
  525. printf("Nothing to send\n");
  526. return 1;
  527. }
  528. }
  529. else
  530. if (strcmp(url, "-") == 0) {
  531. /* get the content from stdin */
  532. content = xs_readall(stdin);
  533. }
  534. else
  535. content = xs_dup(url);
  536. int scope = 0;
  537. if (strcmp(cmd, "note_mention") == 0)
  538. scope = 1;
  539. else
  540. if (strcmp(cmd, "note_unlisted") == 0)
  541. scope = 2;
  542. msg = msg_note(&snac, content, NULL, NULL, attl, scope, getenv("LANG"));
  543. c_msg = msg_create(&snac, msg);
  544. if (dbglevel) {
  545. xs_json_dump(c_msg, 4, stdout);
  546. }
  547. enqueue_message(&snac, c_msg);
  548. timeline_add(&snac, xs_dict_get(msg, "id"), msg);
  549. return 0;
  550. }
  551. fprintf(stderr, "ERROR: bad command '%s'\n", cmd);
  552. return 1;
  553. }