Skip to content

Commit

Permalink
SBUS: get rid of uid/gid args
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-tikhonov committed Oct 21, 2023
1 parent 08aab3f commit 899c85f
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 58 deletions.
3 changes: 1 addition & 2 deletions src/monitor/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1577,8 +1577,7 @@ static int monitor_process_init(struct mt_ctx *ctx)

req = sbus_server_create_and_connect_send(ctx, ctx->ev, SSS_BUS_MONITOR,
NULL, SSS_MONITOR_ADDRESS,
false, 100, ctx->uid, ctx->gid,
NULL, NULL);
false, 100, NULL, NULL);
if (req == NULL) {
DEBUG(SSSDBG_TRACE_FUNC, "sbus_server_create_and_connect_send() failed\n");
ret = ENOMEM;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/data_provider/dp.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ dp_init_send(TALLOC_CTX *mem_ctx,
talloc_set_destructor(state->provider, dp_destructor);

subreq = sbus_server_create_and_connect_send(state->provider, ev,
sbus_name, NULL, sbus_address, true, 1000, uid, gid,
sbus_name, NULL, sbus_address, true, 1000,
(sbus_server_on_connection_cb)dp_client_init,
(sbus_server_on_connection_data)state->provider);
if (subreq == NULL) {
Expand Down
5 changes: 1 addition & 4 deletions src/sbus/connection/sbus_connection_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ sbus_server_create_and_connect_send(TALLOC_CTX *mem_ctx,
const char *address,
bool use_symlink,
uint32_t max_connections,
uid_t uid,
gid_t gid,
sbus_server_on_connection_cb on_conn_cb,
sbus_server_on_connection_data on_conn_data)
{
Expand All @@ -364,8 +362,7 @@ sbus_server_create_and_connect_send(TALLOC_CTX *mem_ctx,
}

state->server = sbus_server_create(state, ev, address, use_symlink,
max_connections, uid, gid,
on_conn_cb, on_conn_data);
max_connections, on_conn_cb, on_conn_data);
if (state->server == NULL) {
ret = ENOMEM;
goto done;
Expand Down
8 changes: 0 additions & 8 deletions src/sbus/sbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ errno_t sbus_connect_private_recv(TALLOC_CTX *mem_ctx,
* @param ev Tevent context.
* @param address Socket address.
* @param use_symlink If a symlink to @address should be created.
* @param uid Socket owner uid.
* @param gid Socket owner gid.
* @param on_conn_cb On new connection callback function.
* @param on_conn_data Private data passed to the callback.
*
Expand All @@ -149,8 +147,6 @@ sbus_server_create(TALLOC_CTX *mem_ctx,
const char *address,
bool use_symlink,
uint32_t max_connections,
uid_t uid,
gid_t gid,
sbus_server_on_connection_cb on_conn_cb,
sbus_server_on_connection_data on_conn_data);

Expand All @@ -164,8 +160,6 @@ sbus_server_create(TALLOC_CTX *mem_ctx,
* an event occurs on connection.
* @param address Socket address.
* @param use_symlink If a symlink to @address should be created.
* @param uid Socket owner uid.
* @param gid Socket owner gid.
* @param on_conn_cb On new connection callback function.
* @param on_conn_data Private data passed to the callback.
*
Expand All @@ -179,8 +173,6 @@ sbus_server_create_and_connect_send(TALLOC_CTX *mem_ctx,
const char *address,
bool use_symlink,
uint32_t max_connections,
uid_t uid,
gid_t gid,
sbus_server_on_connection_cb on_conn_cb,
sbus_server_on_connection_data on_conn_data);

Expand Down
2 changes: 0 additions & 2 deletions src/sbus/sbus_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ struct sbus_server {
hash_table_t *names;
hash_table_t *match_rules;
uint32_t max_connections;
uid_t uid;
gid_t gid;

struct sbus_server_on_connection *on_connection;
bool disconnecting;
Expand Down
43 changes: 3 additions & 40 deletions src/sbus/server/sbus_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ sbus_server_symlink_remove(const char *name)
}

static errno_t
sbus_server_check_file(const char *filename, uid_t uid, gid_t gid)
sbus_server_check_file(const char *filename)
{
struct stat stat_buf;
errno_t ret;
Expand All @@ -290,16 +290,6 @@ sbus_server_check_file(const char *filename, uid_t uid, gid_t gid)
}
}

if (stat_buf.st_uid != uid || stat_buf.st_gid != gid) {
ret = chown(filename, uid, gid);
if (ret != EOK) {
ret = errno;
DEBUG(SSSDBG_CRIT_FAILURE, "chown failed for [%s] [%d]: %s\n",
filename, ret, sss_strerror(ret));
return ret;
}
}

return EOK;
}

Expand All @@ -308,8 +298,6 @@ sbus_server_setup_dbus(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
const char *address,
bool use_symlink,
uid_t uid,
gid_t gid,
const char **_symlink)
{
TALLOC_CTX *tmp_ctx;
Expand Down Expand Up @@ -354,7 +342,7 @@ sbus_server_setup_dbus(TALLOC_CTX *mem_ctx,
}

/* Check file permissions and setup proper owner. */
ret = sbus_server_check_file(filename, uid, gid);
ret = sbus_server_check_file(filename);
if (ret != EOK) {
goto done;
}
Expand Down Expand Up @@ -404,22 +392,6 @@ sbus_server_filter_add(struct sbus_server *server,
return true;
}

static dbus_bool_t
sbus_server_check_connection_uid(DBusConnection *dbus_conn,
unsigned long uid,
void *data)
{
struct sbus_server *sbus_server;

sbus_server = talloc_get_type(data, struct sbus_server);

if (uid == 0 || uid == sbus_server->uid) {
return true;
}

return false;
}

static void
sbus_server_new_connection(DBusServer *dbus_server,
DBusConnection *dbus_conn,
Expand All @@ -435,11 +407,6 @@ sbus_server_new_connection(DBusServer *dbus_server,

DEBUG(SSSDBG_FUNC_DATA, "Adding connection %p.\n", dbus_conn);

/* Allow access from uid that is associated with this sbus server. */
dbus_connection_set_unix_user_function(dbus_conn,
sbus_server_check_connection_uid,
sbus_server, NULL);

/* First, add a message filter that will take care of routing messages
* between connections. */
bret = sbus_server_filter_add(sbus_server, dbus_conn);
Expand Down Expand Up @@ -638,8 +605,6 @@ sbus_server_create(TALLOC_CTX *mem_ctx,
const char *address,
bool use_symlink,
uint32_t max_connections,
uid_t uid,
gid_t gid,
sbus_server_on_connection_cb on_conn_cb,
sbus_server_on_connection_data on_conn_data)
{
Expand All @@ -658,7 +623,7 @@ sbus_server_create(TALLOC_CTX *mem_ctx,
talloc_set_destructor(sbus_server, sbus_server_destructor);

dbus_server = sbus_server_setup_dbus(sbus_server, ev, address,
use_symlink, uid, gid, &symlink);
use_symlink, &symlink);
if (dbus_server == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to setup a D-Bus server!\n");
ret = ENOMEM;
Expand All @@ -671,8 +636,6 @@ sbus_server_create(TALLOC_CTX *mem_ctx,
sbus_server->max_connections = max_connections;
sbus_server->name.major = 1;
sbus_server->name.minor = 0;
sbus_server->uid = uid;
sbus_server->gid = gid;

sbus_server->on_connection = talloc_zero(sbus_server,
struct sbus_server_on_connection);
Expand Down
2 changes: 1 addition & 1 deletion src/sbus/server/sbus_server_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ sbus_server_bus_get_connection_unix_user(TALLOC_CTX *mem_ctx,
dbus_bool_t dbret;

if (strcmp(name, DBUS_SERVICE_DBUS) == 0) {
*_uid = server->uid;
*_uid = geteuid();
return EOK;
}

Expand Down

0 comments on commit 899c85f

Please sign in to comment.