Definition at line 989 of file omp.c.
References server_connection_t::client_ca_cert_path, server_connection_t::client_cert_path, server_connection_t::client_key_path,DEFAULT_PING_TIMEOUT, get_configs(), server_connection_t::host_string, OPENVASMD_ADDRESS, OPENVASMD_PORT,server_connection_t::password, server_connection_t::port, server_connection_t::port_string, read_password(),server_connection_t::session, server_connection_t::timeout, server_connection_t::use_certs, and server_connection_t::username.
990 {
991 server_connection_t *connection = NULL;
992
993
int exit_status = -1;
994
995
996
static gboolean prompt = FALSE;
997
static gboolean print_version = FALSE;
998
static gboolean be_verbose = FALSE;
999
static gboolean use_certs = FALSE;
1000
static gchar *client_cert_path = NULL;
1001
static gchar *client_key_path = NULL;
1002
static gchar *client_ca_cert_path = NULL;
1003
static gchar *conf_file_path = NULL;
1004
static gchar *send_file_path = NULL;
1005
static gchar *manager_host_string = NULL;
1006
static gchar *manager_port_string = NULL;
1007
static gchar *omp_username = NULL;
1008
static gchar *omp_password = NULL;
1009
1010
static gchar *name = NULL;
1011
1012
static gboolean cmd_create_task = FALSE;
1013
static gchar *comment = NULL;
1014
static gchar *config = NULL;
1015
static gchar *target = NULL;
1016
1017
static gboolean cmd_delete_report = FALSE;
1018
1019
static gboolean cmd_delete_task = FALSE;
1020
1021
static gboolean cmd_get_report = FALSE;
1022
1023
static gboolean cmd_get_report_formats = FALSE;
1024
1025
static gboolean cmd_get_omp_version = FALSE;
1026
static gchar *format = NULL;
1027
1028
static gboolean cmd_get_tasks = FALSE;
1029
1030
static gboolean cmd_get_configs = FALSE;
1031
1032
static gboolean cmd_get_targets = FALSE;
1033
1034
static gboolean cmd_modify_task = FALSE;
1035
static gboolean file = FALSE;
1036
1037
static gboolean cmd_start_task = FALSE;
1038
1039
static gchar *filter = NULL;
1040
1041
static gboolean cmd_details = FALSE;
1042
1043
static gboolean cmd_ping = FALSE;
1044
static gint ping_timeout = DEFAULT_PING_TIMEOUT;
1045
1046
static gchar *cmd_xml = NULL;
1047
1048
static gchar **rest = NULL;
1049
1050
static gboolean pretty_print = FALSE;
1051
1052 GError *error = NULL;
1053
1054 GOptionContext *option_context;
1055
static GOptionEntry option_entries[] = {
1056
1057 {
"host",
'h', 0, G_OPTION_ARG_STRING, &manager_host_string,
1058
"Connect to manager on host ",
""},
1059 {
"port",
'p', 0, G_OPTION_ARG_STRING, &manager_port_string,
1060
"Use port number ",
""},
1061 {
"version",
'V', 0, G_OPTION_ARG_NONE, &print_version,
1062
"Print version.", NULL},
1063 {
"verbose",
'v', 0, G_OPTION_ARG_NONE, &be_verbose,
1064
"Verbose messages (WARNING: may reveal passwords).", NULL},
1065 {
"use-certs", 0, 0, G_OPTION_ARG_NONE, &use_certs,
1066
"Use client certificates to authenticate.", NULL},
1067 {
"client-cert", 0, 0, G_OPTION_ARG_FILENAME, &client_cert_path,
1068
"Client certificate. Default: " CLIENTCERT,
""},
1069 {
"client-key", 0, 0, G_OPTION_ARG_FILENAME, &client_key_path,
1070
"Client key. Default: " CLIENTKEY,
""},
1071 {
"client-ca-cert", 0, 0, G_OPTION_ARG_FILENAME, &client_ca_cert_path,
1072
"Client CA certificate. Default: " CACERT,
""},
1073 {
"username",
'u', 0, G_OPTION_ARG_STRING, &omp_username,
1074
"OMP username",
""},
1075 {
"password",
'w', 0, G_OPTION_ARG_STRING, &omp_password,
1076
"OMP password",
""},
1077 {
"config-file", 0, 0, G_OPTION_ARG_FILENAME, &conf_file_path,
1078
"Configuration file for connection parameters.",
""},
1079 {
"prompt",
'P', 0, G_OPTION_ARG_NONE, &prompt,
1080
"Prompt to exit.", NULL},
1081 {
"get-omp-version",
'O', 0, G_OPTION_ARG_NONE, &cmd_get_omp_version,
1082
"Print OMP version.", NULL},
1083
1084 {
"name",
'n', 0, G_OPTION_ARG_STRING, &name,
1085
"Name for create-task.",
1086
""},
1087
1088 {
"create-task",
'C', 0, G_OPTION_ARG_NONE, &cmd_create_task,
1089
"Create a task.", NULL},
1090 {
"comment",
'm', 0, G_OPTION_ARG_STRING, &comment,
1091
"Comment for create-task.",
1092
""},
1093 {
"config",
'c', 0, G_OPTION_ARG_STRING, &config,
1094
"Config for create-task.",
1095
""},
1096 {
"target",
't', 0, G_OPTION_ARG_STRING, &target,
1097
"Target for create-task.",
1098
""},
1099
1100 {
"delete-report",
'E', 0, G_OPTION_ARG_NONE, &cmd_delete_report,
1101
"Delete one or more reports.", NULL},
1102
1103 {
"delete-task",
'D', 0, G_OPTION_ARG_NONE, &cmd_delete_task,
1104
"Delete one or more tasks.", NULL},
1105
1106 {
"get-report",
'R', 0, G_OPTION_ARG_NONE, &cmd_get_report,
1107
"Get report of one task.", NULL},
1108 {
"get-report-formats",
'F', 0, G_OPTION_ARG_NONE, &cmd_get_report_formats,
1109
"Get report formats. (OMP 2.0 only)", NULL},
1110 {
"format",
'f', 0, G_OPTION_ARG_STRING, &format,
1111
"Format for get-report.",
1112
""},
1113 {
"filter", 0, 0, G_OPTION_ARG_STRING, &filter,
1114
"Filter string for get-report",
1115
""},
1116
1117 {
"get-tasks",
'G', 0, G_OPTION_ARG_NONE, &cmd_get_tasks,
1118
"Get status of one, many or all tasks.", NULL},
1119
1120 {
"get-configs",
'g', 0, G_OPTION_ARG_NONE, &cmd_get_configs,
1121
"Get configs.", NULL},
1122
1123 {
"get-targets",
'T', 0, G_OPTION_ARG_NONE, &cmd_get_targets,
1124
"Get targets.", NULL},
1125
1126 {
"pretty-print",
'i', 0, G_OPTION_ARG_NONE, &pretty_print,
1127
"In combination with -X, pretty print the response.", NULL},
1128
1129 {
"start-task",
'S', 0, G_OPTION_ARG_NONE, &cmd_start_task,
1130
"Start one or more tasks.", NULL},
1131
1132 {
"modify-task",
'M', 0, G_OPTION_ARG_NONE, &cmd_modify_task,
1133
"Modify a task.", NULL},
1134
1135 {
"ping", 0, 0, G_OPTION_ARG_NONE, &cmd_ping,
1136
"Ping OMP server", NULL},
1137 {
"timeout",
't', 0, G_OPTION_ARG_INT, &ping_timeout,
1138
"Wait seconds for OMP ping response",
""},
1139 {
"file", 0, 0, G_OPTION_ARG_NONE, &file,
1140
"Add text in stdin as file on task.", NULL},
1141
1142 {
"xml",
'X', 0, G_OPTION_ARG_STRING, &cmd_xml,
1143
"XML command (e.g. \"\"). \"-\" to read from stdin.",
1144
""},
1145 {
"send-file", 0, 0, G_OPTION_ARG_FILENAME, &send_file_path,
1146
"Replace SENDFILE in xml with base64 of file.",
""},
1147 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &rest,
1148 NULL, NULL},
1149
1150 {
"details", 0, 0, G_OPTION_ARG_NONE, &cmd_details,
1151
"Enable detailed view.", NULL},
1152 {NULL, 0, 0, 0, NULL, NULL, NULL}
1153 };
1154
1155
if (setlocale (LC_ALL,
"") == NULL)
1156 {
1157 printf (
"Failed to setlocale\n\n");
1158 exit (EXIT_FAILURE);
1159 }
1160
1161 option_context =
1162 g_option_context_new (
"- OpenVAS OMP Command Line Interface");
1163 g_option_context_add_main_entries (option_context, option_entries, NULL);
1164
if (!g_option_context_parse (option_context, &argc, &argv, &error))
1165 {
1166 printf (
"%s\n\n", error->message);
1167 exit (EXIT_FAILURE);
1168 }
1169
1170
1171
if (rest != NULL && *rest != NULL)
1172 {
1173
if (g_strstr_len (*rest, -1,
"/?") != NULL)
1174 {
1175 printf (
"%s", g_option_context_get_help (option_context, TRUE, NULL));
1176 exit (EXIT_SUCCESS);
1177 }
1178 }
1179
1180
if (print_version)
1181 {
1182 printf (
"OMP Command Line Interface %s\n", OPENVASCLI_VERSION);
1183 printf (
"Copyright (C) 2010-2016 Greenbone Networks GmbH\n");
1184 printf (
"License GPLv2+: GNU GPL version 2 or later\n");
1185 printf
1186 (
"This is free software: you are free to change and redistribute it.\n"
1187
"There is NO WARRANTY, to the extent permitted by law.\n\n");
1188 exit (EXIT_SUCCESS);
1189 }
1190
1191
1192 {
1193
int commands;
1194 commands =
1195 (int) cmd_create_task + (
int) cmd_delete_report + (int) cmd_delete_task +
1196 (
int) cmd_get_report + (
int) cmd_get_report_formats +
1197 (
int) cmd_get_tasks + (
int) cmd_modify_task + (
int) cmd_start_task +
1198 (
int) cmd_get_targets + (
int) cmd_get_omp_version + (
int) cmd_get_configs +
1199 (
int) cmd_ping + (
int) (cmd_xml != NULL);
1200 if (commands == 0)
1201 {
1202 fprintf (stderr,
"One command option must be present.\n");
1203 exit (EXIT_FAILURE);
1204 }
1205
if (commands > 1)
1206 {
1207 fprintf (stderr,
"Only one command option must be present.\n");
1208 exit (EXIT_FAILURE);
1209 }
1210 }
1211
1212
1213
1214
1215
1216
if (conf_file_path == NULL)
1217 conf_file_path = g_build_filename (g_get_home_dir (),
"omp.config", NULL);
1218 connection = connection_from_file (conf_file_path);
1219 g_free (conf_file_path);
1220
1221
if (manager_host_string != NULL)
1222 connection-> host_string = manager_host_string;
1223
else
if (connection-> host_string == NULL)
1224 connection-> host_string = OPENVASMD_ADDRESS;
1225
1226
if (manager_port_string != NULL)
1227 connection-> port = atoi (manager_port_string);
1228
else
if (connection-> port_string != NULL)
1229 connection-> port = atoi (connection-> port_string);
1230
else
1231 connection-> port = OPENVASMD_PORT;
1232
1233
if (connection-> port <= 0 || connection-> port >= 65536)
1234 {
1235 fprintf (stderr,
"Manager port must be a number between 0 and 65536.\n");
1236 exit (EXIT_FAILURE);
1237 }
1238
1239 connection-> use_certs = use_certs;
1240
if (omp_username != NULL)
1241 connection-> username = omp_username;
1242
else
if (connection-> username == NULL)
1243 connection-> username = g_strdup (g_get_user_name ());
1244
1245
if (client_cert_path != NULL)
1246 connection-> client_cert_path = client_cert_path;
1247
else
if (connection-> client_cert_path == NULL)
1248 connection-> client_cert_path = CLIENTCERT;
1249
1250
if (client_key_path != NULL)
1251 connection-> client_key_path = client_key_path;
1252
else
if (connection-> client_key_path == NULL)
1253 connection-> client_key_path = CLIENTKEY;
1254
1255
if (client_ca_cert_path != NULL)
1256 connection-> client_ca_cert_path = client_ca_cert_path;
1257
else
if (connection-> client_ca_cert_path == NULL)
1258 connection-> client_ca_cert_path = CACERT;
1259
1260
if (ping_timeout < 0)
1261 ping_timeout = DEFAULT_PING_TIMEOUT;
1262 connection-> timeout = ping_timeout;
1263
1264
if (omp_password != NULL)
1265 connection-> password = omp_password;
1266
else
if (connection-> password == NULL && !connection-> use_certs && !cmd_ping
1267 && !cmd_get_omp_version)
1268 {
1269 gchar *pw = NULL;
1270
size_t n;
1271
1272 printf (
"Enter password: ");
1273
int ret = read_password (&pw, &n, stdin);
1274 printf (
"\n");
1275
1276
if (ret < 0)
1277 {
1278 fprintf (stderr,
"Failed to read password from console!\n");
1279 exit (EXIT_FAILURE);
1280 }
1281
1282
1283 pw[ret - 1] =
'\0';
1284
1285
if (strlen (pw) > 0)
1286 connection-> password = pw;
1287
else
1288 {
1289 fprintf (stderr,
"Password must be set.\n");
1290 exit (EXIT_FAILURE);
1291 }
1292 }
1293
1294
if (be_verbose)
1295 {
1296
const
char *s;
1297
1299 printf (
"\nWARNING: Verbose mode may reveal passwords!\n\n");
1300 printf (
"Will try to connect to host %s, port %d...\n",
1301 connection-> host_string, connection-> port);
1302
1303
1304
1305
if ((s=getenv (
"OPENVAS_GNUTLS_DEBUG")))
1306 {
1307 gnutls_global_set_log_function (my_gnutls_log_func);
1308 gnutls_global_set_log_level (atoi (s));
1309 }
1310 }
1311
else
1312 {
1313
#ifndef _WIN32
1314 g_log_set_default_handler (openvas_log_silent, NULL);
1315
#endif
1316 }
1317
1318
1319
1320
if (cmd_create_task)
1321 {
1322
char *
id = NULL;
1323
1324
if (manager_open (connection))
1325 exit (EXIT_FAILURE);
1326
1327
if (omp_create_task
1328 (&(connection-> session), name ? name :
"unnamed task",
1329 config ? config :
"Full and fast", target ? target :
"Localhost",
1330 comment ? comment :
"", &
id))
1331 {
1332 fprintf (stderr,
"Failed to create task.\n");
1333 manager_close (connection);
1334 exit (EXIT_FAILURE);
1335 }
1336
1337 printf (
"%s",
id);
1338 putchar (
'\n');
1339
1340 manager_close (connection);
1341 exit_status = 0;
1342 }
1343
else
if (cmd_delete_report)
1344 {
1345 gchar **point = rest;
1346
1347
if (point == NULL || *point == NULL)
1348 {
1349 fprintf (stderr,
"delete-report requires at least one argument.\n");
1350 exit (EXIT_FAILURE);
1351 }
1352
1353
if (manager_open (connection))
1354 exit (EXIT_FAILURE);
1355
1356
while (*point)
1357 {
1358
if (omp_delete_report (&(connection-> session), *point))
1359 {
1360 fprintf (stderr,
"Failed to delete report %s, exiting.\n",
1361 *point);
1362 manager_close (connection);
1363 exit (EXIT_FAILURE);
1364 }
1365 point++;
1366 }
1367
1368 manager_close (connection);
1369 exit_status = 0;
1370 }
1371
else
if (cmd_delete_task)
1372 {
1373 gchar **point = rest;
1374
1375
if (point == NULL || *point == NULL)
1376 {
1377 fprintf (stderr,
"delete-task requires at least one argument.\n");
1378 exit (EXIT_FAILURE);
1379 }
1380
1381
if (manager_open (connection))
1382 exit (EXIT_FAILURE);
1383
1384
while (*point)
1385 {
1386
if (omp_delete_task (&(connection-> session), *point))
1387 {
1388 fprintf (stderr,
"Failed to delete task.\n");
1389 manager_close (connection);
1390 exit (EXIT_FAILURE);
1391 }
1392 point++;
1393 }
1394
1395 manager_close (connection);
1396 exit_status = 0;
1397 }
1398
else
if (cmd_get_tasks)
1399 {
1400 gchar **point = rest;
1401 entity_t status;
1402
1403
if (manager_open (connection))
1404 exit (EXIT_FAILURE);
1405
1406
if (point)
1407
while (*point)
1408 {
1409 omp_get_task_opts_t opts;
1410
1411 opts = omp_get_task_opts_defaults;
1412 opts.task_id = *point;
1413 opts.details = 1;
1414 opts.actions =
"g";
1415
1416
if (omp_get_task_ext (&(connection-> session), opts, &status))
1417 {
1418 fprintf (stderr,
"Failed to get status of task %s.\n", *point);
1419 manager_close (connection);
1420 exit (EXIT_FAILURE);
1421 }
1422
else
1423 {
1424
if (print_tasks (status->entities))
1425 {
1426 manager_close (connection);
1427 exit (EXIT_FAILURE);
1428 }
1429 }
1430
1431 point++;
1432 }
1433
else
1434 {
1435 omp_get_tasks_opts_t opts;
1436
1437 opts = omp_get_tasks_opts_defaults;
1438
if(cmd_details)
1439 opts.details = 1;
1440
else
1441 opts.details = 0;
1442 opts.filter =
"permission=any owner=any rows=-1";
1443
1444
if (omp_get_tasks_ext (&(connection-> session), opts, &status))
1445 {
1446 fprintf (stderr,
"Failed to get status of all tasks.\n");
1447 manager_close (connection);
1448 exit (EXIT_FAILURE);
1449 }
1450
if (print_tasks (status->entities))
1451 {
1452 manager_close (connection);
1453 exit (EXIT_FAILURE);
1454 }
1455 }
1456
1457 manager_close (connection);
1458 exit_status = 0;
1459 }
1460
else
if (cmd_get_configs)
1461 {
1462 entity_t status;
1463
1464
if (manager_open (connection))
1465 exit (EXIT_FAILURE);
1466
1467
if ( get_configs (&(connection-> session), &status))
1468 {
1469 fprintf (stderr,
"Failed to get configs.\n");
1470 exit (EXIT_FAILURE);
1471 }
1472
if (print_configs (status->entities))
1473 {
1474 manager_close (connection);
1475 exit (EXIT_FAILURE);
1476 }
1477
1478 manager_close (connection);
1479 exit_status = 0;
1480 }
1481
else
if (cmd_get_targets)
1482 {
1483 entity_t status;
1484
1485
if (manager_open (connection))
1486 exit (EXIT_FAILURE);
1487
1488
if (omp_get_targets (&(connection-> session), NULL, 0, 0, &status))
1489 {
1490 fprintf (stderr,
"Failed to get targets.\n");
1491 exit (EXIT_FAILURE);
1492 }
1493
if (print_targets (status->entities))
1494 {
1495 manager_close (connection);
1496 exit (EXIT_FAILURE);
1497 }
1498
1499 manager_close (connection);
1500 exit_status = 0;
1501 }
1502
else
if (cmd_get_report)
1503 {
1504 gchar **report_ids = rest;
1505
1506
if (report_ids == NULL || *report_ids == NULL)
1507 {
1508 fprintf (stderr,
"get-report requires one argument.\n");
1509 exit (EXIT_FAILURE);
1510 }
1511
1512
if (manager_open (connection))
1513 exit (EXIT_FAILURE);
1514 exit_status = manager_get_reports (connection, report_ids, format, filter);
1515
if (exit_status == 0)
1516 manager_close (connection);
1517 }
1518
else
if (cmd_get_report_formats)
1519 {
1520
if (manager_open (connection))
1521 exit (EXIT_FAILURE);
1522 exit_status = manager_get_report_formats (connection);
1523
if (exit_status == 0)
1524 manager_close (connection);
1525 }
1526
else
if (cmd_get_omp_version)
1527 {
1528 gchar *version = NULL;
1529
if (manager_open (connection))
1530 exit (EXIT_FAILURE);
1531 exit_status = manager_get_omp_version (connection, &version);
1532 printf (
"Version: %s\n", version);
1533 g_free (version);
1534
if (exit_status == 0)
1535 manager_close (connection);
1536 }
1537
else
if (cmd_ping)
1538 {
1539
if (manager_open (connection))
1540 {
1541 fprintf (stderr,
"OMP ping failed: Failed to establish connection.\n");
1542 exit_status = 1;
1543 }
1544
else
1545 {
1546
int res;
1547
1548
1549 res = omp_ping (&(connection-> session), connection-> timeout);
1550
if (res == 0)
1551 {
1552 fprintf (stdout,
"OMP ping was successful.\n");
1553 exit_status = 0;
1554 }
1555
else
if (res == 1)
1556 {
1557 fprintf (stderr,
"OMP ping failed: Server closed connection.\n");
1558 exit_status = 1;
1559 }
1560
else
if (res == 2)
1561 {
1562 fprintf (stderr,
"OMP ping failed: Timeout.\n");
1563 exit_status = 1;
1564 }
1565
else
1566 {
1567 fprintf (stderr,
"OMP ping failed: Unknown error.\n");
1568 exit_status = 1;
1569 }
1570 }
1571
if (exit_status == 0)
1572 manager_close (connection);
1573 }
1574
else
if (cmd_modify_task)
1575 {
1576 gchar **point = rest;
1577 gchar *content;
1578 gsize content_len;
1579
1580
if (point == NULL || *point == NULL)
1581 {
1582 fprintf (stderr,
"modify-task requires one argument.\n");
1583 exit (EXIT_FAILURE);
1584 }
1585
1586
if (name == NULL)
1587 {
1588 fprintf (stderr,
1589
"modify-task requires the name option (path to file).\n");
1590 exit (EXIT_FAILURE);
1591 }
1592
1593
if (file == FALSE)
1594 {
1595 fprintf (stderr,
"modify-task requires the file option.\n");
1596 exit (EXIT_FAILURE);
1597 }
1598
1599
if (file)
1600 {
1601 GIOChannel *stdin_channel;
1602
1603
if (manager_open (connection))
1604 exit (EXIT_FAILURE);
1605
1606 error = NULL;
1607 stdin_channel = g_io_channel_unix_new (fileno (stdin));
1608 g_io_channel_read_to_end (stdin_channel, &content, &content_len,
1609 &error);
1610 g_io_channel_shutdown (stdin_channel, TRUE, NULL);
1611 g_io_channel_unref (stdin_channel);
1612
if (error)
1613 {
1614 fprintf (stderr,
"failed to read from stdin: %s\n",
1615 error->message);
1616 g_error_free (error);
1617 exit (EXIT_FAILURE);
1618 }
1619
1620
#if 0
1621
1622 exit_status =
1623 manager_modify_task_file (connection, *point, name, content,
1624 content_len, error);
1625
#else
1626
if (omp_modify_task_file
1627 (&(connection-> session), *point, name, content, content_len))
1628 {
1629 g_free (content);
1630 fprintf (stderr,
"Failed to modify task.\n");
1631 manager_close (connection);
1632 exit (EXIT_FAILURE);
1633 }
1634
1635 manager_close (connection);
1636 exit_status = 0;
1637
#endif
1638 }
1639 }
1640
else
if (cmd_start_task)
1641 {
1642 gchar **point = rest;
1643
1644
if (point == NULL || *point == NULL)
1645 {
1646 fprintf (stderr,
"start-task requires at least one argument.\n");
1647 exit (EXIT_FAILURE);
1648 }
1649
1650
if (manager_open (connection))
1651 exit (EXIT_FAILURE);
1652
1653
while (*point)
1654 {
1655
char *report_id;
1656
if (omp_start_task_report
1657 (&(connection-> session), *point, &report_id))
1658 {
1659 fprintf (stderr,
"Failed to start task.\n");
1660 manager_close (connection);
1661 exit (EXIT_FAILURE);
1662 }
1663 printf (
"%s\n", report_id);
1664 free (report_id);
1665 point++;
1666 }
1667 exit_status = 0;
1668
1669 manager_close (connection);
1670 }
1671
else
if (cmd_xml)
1672 {
1673
if (manager_open (connection))
1674 exit (EXIT_FAILURE);
1675
1676
if (send_file_path)
1677 {
1678
char *new_xml = cmd_xml;
1679
if (replace_send_file_xml (&new_xml, send_file_path))
1680 exit (EXIT_FAILURE);
1681 g_free (cmd_xml);
1682 cmd_xml = new_xml;
1683 }
1684
1686
if (prompt)
1687 {
1688 fprintf (stderr,
"Connected, press a key to continue.\n");
1689 getchar ();
1690 }
1691
1692
if (strcmp (cmd_xml,
"-") == 0)
1693 {
1694 GError *error;
1695 gchar *content;
1696 gsize content_len;
1697 GIOChannel *stdin_channel;
1698
1699
1700 error = NULL;
1701 stdin_channel = g_io_channel_unix_new (fileno (stdin));
1702 g_io_channel_read_to_end (stdin_channel, &content, &content_len,
1703 &error);
1704 g_io_channel_shutdown (stdin_channel, TRUE, NULL);
1705 g_io_channel_unref (stdin_channel);
1706
if (error)
1707 {
1708 fprintf (stderr,
"Failed to read from stdin: %s\n",
1709 error->message);
1710 g_error_free (error);
1711 exit (EXIT_FAILURE);
1712 }
1713
1714 g_free (cmd_xml);
1715 cmd_xml = content;
1716 }
1717
1718
if (be_verbose)
1719 printf (
"Sending to manager: %s\n", cmd_xml);
1720
1721
if (openvas_server_sendf (&(connection-> session),
"%s", cmd_xml) == -1)
1722 {
1723 manager_close (connection);
1724 fprintf (stderr,
"Failed to send_to_manager.\n");
1725 exit (EXIT_FAILURE);
1726 }
1727
1728
1729
1730 entity_t entity = NULL;
1731
if (read_entity (&(connection-> session), &entity))
1732 {
1733 fprintf (stderr,
"Failed to read response.\n");
1734 manager_close (connection);
1735 exit (EXIT_FAILURE);
1736 }
1737
1738
if (be_verbose)
1739 printf (
"Got response:\n");
1740
if (pretty_print == FALSE)
1741 print_entity (stdout, entity);
1742
else
1743 print_entity_format (entity, GINT_TO_POINTER (2));
1744 printf (
"\n");
1745
1746
1747
1749
if (prompt)
1750 {
1751 fprintf (stderr,
"Press a key when done.\n");
1752 getchar ();
1753 }
1754
1755 manager_close (connection);
1756 free_entity (entity);
1757
1758 exit_status = 0;
1759 }
1760
else
1761
1762 assert (0);
1763
1764
1765
1766
if (be_verbose)
1767 {
1768
if (exit_status)
1769 printf (
"Command failed.\n");
1770
else
1771 printf (
"Command completed successfully.\n");
1772 }
1773
1774 exit (exit_status);
1775 }