static int prepare_connections(struct traverse_state *state)
{
- /* always print header line */
- d_printf("\n%-12s %-7s %-13s %-32s %-12s %-12s\n", "Service", "pid", "Machine", "Connected at", "Encryption", "Signing");
- d_printf("---------------------------------------------------------------------------------------------\n");
-
+ if (!state->json_output) {
+ /* always print header line */
+ d_printf("\n%-12s %-7s %-13s %-32s %-12s %-12s\n", "Service", "pid", "Machine", "Connected at", "Encryption", "Signing");
+ d_printf("---------------------------------------------------------------------------------------------\n");
+ } else {
+ add_section_to_json(state, "tcons");
+ }
return 0;
}
}
}
- result = traverse_connections_stdout(state,
- crec->servicename,
- server_id_str_buf(crec->pid, &tmp),
- crec->machine,
- timestr,
- encryption,
- signing);
+ if (!state->json_output) {
+ result = traverse_connections_stdout(state,
+ crec->servicename,
+ server_id_str_buf(crec->pid, &tmp),
+ crec->machine,
+ timestr,
+ encryption,
+ signing);
+ } else {
+ result = traverse_connections_json(state,
+ crec);
+ }
TALLOC_FREE(timestr);
TALLOC_FREE(tmp_ctx);
#include "includes.h"
#include "smbprofile.h"
+#include "conn_tdb.h"
#include "status_json.h"
#include "../libcli/security/security.h"
#include "status.h"
return result;
}
+
+int traverse_connections_json(struct traverse_state *state,
+ const struct connections_data *crec)
+{
+ struct json_object sub_json;
+ struct json_object connections_json;
+ int result = 0;
+ char *tcon_id_str = NULL;
+
+ TALLOC_CTX *tmp_ctx = talloc_stackframe();
+ if (tmp_ctx == NULL) {
+ return -1;
+ }
+
+ sub_json = json_new_object();
+ if (json_is_invalid(&sub_json)) {
+ goto failure;
+ }
+ connections_json = json_get_object(&state->root_json, "tcons");
+ if (json_is_invalid(&connections_json)) {
+ goto failure;
+ }
+
+ result = json_add_string(&sub_json, "service", crec->servicename);
+ if (result < 0) {
+ goto failure;
+ }
+ tcon_id_str = talloc_asprintf(tmp_ctx, "%u", crec->cnum);
+ if (tcon_id_str == NULL) {
+ goto failure;
+ }
+ result = json_add_string(&sub_json, "tcon_id", tcon_id_str);
+ if (result < 0) {
+ goto failure;
+ }
+ result = json_add_string(&sub_json, "machine", crec->machine);
+ if (result < 0) {
+ goto failure;
+ }
+
+ result = json_add_object(&connections_json, tcon_id_str, &sub_json);
+ if (result < 0) {
+ goto failure;
+ }
+
+ result = json_update_object(&state->root_json, "tcons", &connections_json);
+ if (result < 0) {
+ goto failure;
+ }
+
+ TALLOC_FREE(tmp_ctx);
+ return 0;
+failure:
+ json_free(&sub_json);
+ TALLOC_FREE(tmp_ctx);
+ return -1;
+}
int add_general_information_to_json(struct traverse_state *state);
+int traverse_connections_json(struct traverse_state *state,
+ const struct connections_data *crec);
+
#endif
#include "smbprofile.h"
#include "../libcli/security/security.h"
#include "librpc/gen_ndr/open_files.h"
+#include "conn_tdb.h"
#include "status_json.h"
int add_section_to_json(struct traverse_state *state,
{
return 0;
}
+
+int traverse_connections_json(struct traverse_state *state,
+ const struct connections_data *crec)
+{
+ return 0;
+}