bus-dump.c revision ee04388a54f0e045377eeaf33c17eb357fe12d69
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "util.h"
#include "capability.h"
#include "strv.h"
#include "audit.h"
#include "macro.h"
#include "cap-list.h"
#include "bus-message.h"
#include "bus-internal.h"
#include "bus-type.h"
#include "bus-dump.h"
char *p;
unsigned n, i = 0;
n = 0;
level -= 1;
n += 2;
if (!p)
return NULL;
if (flags & BUS_MESSAGE_DUMP_WITH_HEADER) {
p[i++] = ' ';
p[i++] = ' ';
}
p[i + level*8] = 0;
return p;
}
unsigned level = 1;
int r;
assert(m);
if (!f)
f = stdout;
if (flags & BUS_MESSAGE_DUMP_WITH_HEADER) {
fprintf(f,
"%s%s%s Type=%s%s%s Endian=%c Flags=%u Version=%u Priority=%"PRIi64,
m->header->type != SD_BUS_MESSAGE_SIGNAL ? ansi_highlight() : "", draw_special_char(DRAW_TRIANGULAR_BULLET), ansi_highlight_off(),
m->priority);
/* Display synthetic message serial number in a more readable
* format than (uint32_t) -1 */
if (BUS_MESSAGE_COOKIE(m) == 0xFFFFFFFFULL)
fprintf(f, " Cookie=-1");
else
if (m->reply_cookie != 0)
fputs("\n", f);
if (m->sender)
if (m->destination)
if (m->path)
if (m->interface)
if (m->member)
fputs("\n", f);
if (sd_bus_error_is_set(&m->error))
fprintf(f,
" ErrorName=%s%s%s"
" ErrorMessage=%s\"%s\"%s\n",
if (m->monotonic != 0)
if (m->realtime != 0)
if (m->seqnum != 0)
fputs("\n", f);
bus_creds_dump(&m->creds, f, true);
}
if (r < 0)
return log_error_errno(r, "Failed to rewind: %m");
if (!(flags & BUS_MESSAGE_DUMP_SUBTREE_ONLY)) {
if (!prefix)
return log_oom();
}
for (;;) {
char type;
union {
double d64;
const char *string;
int i;
} basic;
if (r < 0)
return log_error_errno(r, "Failed to peek type: %m");
if (r == 0) {
if (level <= 1)
break;
r = sd_bus_message_exit_container(m);
if (r < 0)
return log_error_errno(r, "Failed to exit container: %m");
level--;
if (!prefix)
return log_oom();
continue;
}
if (!prefix)
return log_oom();
if (bus_type_is_container(type) > 0) {
if (r < 0)
return log_error_errno(r, "Failed to enter container: %m");
if (type == SD_BUS_TYPE_ARRAY)
else if (type == SD_BUS_TYPE_VARIANT)
else if (type == SD_BUS_TYPE_STRUCT)
else if (type == SD_BUS_TYPE_DICT_ENTRY)
level ++;
continue;
}
if (r < 0)
return log_error_errno(r, "Failed to get basic: %m");
assert(r > 0);
switch (type) {
case SD_BUS_TYPE_BYTE:
break;
case SD_BUS_TYPE_BOOLEAN:
fprintf(f, "%sBOOLEAN %s%s%s;\n", prefix, ansi_highlight(), true_false(basic.i), ansi_highlight_off());
break;
case SD_BUS_TYPE_INT16:
break;
case SD_BUS_TYPE_UINT16:
break;
case SD_BUS_TYPE_INT32:
break;
case SD_BUS_TYPE_UINT32:
break;
case SD_BUS_TYPE_INT64:
break;
case SD_BUS_TYPE_UINT64:
break;
case SD_BUS_TYPE_DOUBLE:
break;
case SD_BUS_TYPE_STRING:
break;
case SD_BUS_TYPE_OBJECT_PATH:
fprintf(f, "%sOBJECT_PATH \"%s%s%s\";\n", prefix, ansi_highlight(), basic.string, ansi_highlight_off());
break;
case SD_BUS_TYPE_SIGNATURE:
fprintf(f, "%sSIGNATURE \"%s%s%s\";\n", prefix, ansi_highlight(), basic.string, ansi_highlight_off());
break;
case SD_BUS_TYPE_UNIX_FD:
break;
default:
assert_not_reached("Unknown basic type.");
}
}
if (!(flags & BUS_MESSAGE_DUMP_SUBTREE_ONLY)) {
if (!prefix)
return log_oom();
}
return 0;
}
static void dump_capabilities(
sd_bus_creds *c,
FILE *f,
const char *name,
bool terse,
unsigned long i, last_cap;
unsigned n = 0;
int r;
assert(c);
assert(f);
i = 0;
r = has(c, i);
if (r < 0)
return;
last_cap = cap_last_cap();
for (;;) {
if (r > 0) {
if (n > 0)
fputc(' ', f);
if (n % 4 == 3)
n++;
}
i++;
if (i > last_cap)
break;
r = has(c, i);
}
fputs("\n", f);
if (!terse)
fputs(ansi_highlight_off(), f);
}
bool audit_sessionid_is_set = false, audit_loginuid_is_set = false;
int r;
assert(c);
if (!f)
f = stdout;
if (terse) {
prefix = " ";
suffix = "";
color = "";
} else {
const char *off;
prefix = "";
color = ansi_highlight();
off = ansi_highlight_off();
}
if (c->mask & SD_BUS_CREDS_PID)
if (c->mask & SD_BUS_CREDS_TID)
fputs("\n", f);
if (c->mask & SD_BUS_CREDS_UID)
if (c->mask & SD_BUS_CREDS_EUID)
if (c->mask & SD_BUS_CREDS_SUID)
if (c->mask & SD_BUS_CREDS_FSUID)
r = sd_bus_creds_get_owner_uid(c, &owner);
if (r >= 0)
if (c->mask & SD_BUS_CREDS_GID)
if (c->mask & SD_BUS_CREDS_EGID)
if (c->mask & SD_BUS_CREDS_SGID)
if (c->mask & SD_BUS_CREDS_FSGID)
if (c->mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) {
unsigned i;
for (i = 0; i < c->n_supplementary_gids; i++)
}
SD_BUS_CREDS_SUPPLEMENTARY_GIDS)) || r >= 0))
fputs("\n", f);
if (c->mask & SD_BUS_CREDS_COMM)
if (c->mask & SD_BUS_CREDS_TID_COMM)
if (c->mask & SD_BUS_CREDS_EXE)
fputs("\n", f);
if (sd_bus_creds_get_cmdline(c, &cmdline) >= 0) {
char **i;
STRV_FOREACH(i, cmdline) {
if (i != cmdline)
fputc(' ', f);
fputs(*i, f);
}
}
if (c->mask & SD_BUS_CREDS_SELINUX_CONTEXT)
if (c->mask & SD_BUS_CREDS_DESCRIPTION)
fputs("\n", f);
if (c->mask & SD_BUS_CREDS_CGROUP)
(void) sd_bus_creds_get_unit(c, &u);
if (u)
(void) sd_bus_creds_get_user_unit(c, &uu);
if (uu)
(void) sd_bus_creds_get_slice(c, &sl);
if (sl)
(void) sd_bus_creds_get_session(c, &s);
if (s)
fputs("\n", f);
if (sd_bus_creds_get_audit_login_uid(c, &audit_loginuid) >= 0) {
audit_loginuid_is_set = true;
}
if (sd_bus_creds_get_audit_session_id(c, &audit_sessionid) >= 0) {
audit_sessionid_is_set = true;
}
fputs("\n", f);
if (c->mask & SD_BUS_CREDS_UNIQUE_NAME)
if (sd_bus_creds_get_well_known_names(c, &well_known) >= 0) {
char **i;
STRV_FOREACH(i, well_known) {
if (i != well_known)
fputc(' ', f);
fputs(*i, f);
}
}
fputc('\n', f);
return 0;
}
/*
* For details about the file format, see:
*
*/
typedef struct _packed_ pcap_hdr_s {
} pcap_hdr_t ;
typedef struct _packed_ pcaprec_hdr_s {
pcap_hdr_t hdr = {
.magic_number = 0xa1b2c3d4U,
.version_major = 2,
.version_minor = 4,
.thiszone = 0, /* UTC */
.sigfigs = 0,
};
if (!f)
f = stdout;
fflush(f);
return 0;
}
struct bus_body_part *part;
pcaprec_hdr_t hdr = {};
unsigned i;
size_t w;
if (!f)
f = stdout;
assert(m);
if (m->realtime != 0)
else
/* write the pcap header */
/* write the dbus header */
snaplen -= w;
/* write the dbus body */
MESSAGE_FOREACH_PART(part, i, m) {
if (snaplen <= 0)
break;
snaplen -= w;
}
fflush(f);
return 0;
}