]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
winbind:varlink: Add io.systemd.UserDatabase interface
authorSamuel Cabrero <scabrero@samba.org>
Wed, 1 Feb 2023 16:02:38 +0000 (17:02 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 20 Feb 2025 08:07:32 +0000 (08:07 +0000)
$> varlink info unix:/run/systemd/userdb/org.samba.winbind
Vendor: Samba
Product: Winbind
Version: 1
URL: https://samba.org
Interfaces:
  io.systemd.UserDatabase
  org.varlink.service

TODO libvarlink bug handling camel case interface names:
https://github.com/varlink/libvarlink/pull/58

$> varlink help unix:/run/systemd/userdb/org.samba.winbind/io.systemd.UserDatabase
interface io.systemd.UserDatabase

method GetUserRecord(
  uid: ?int,
  userName: ?string,
  service: string
) -> (record: object, incomplete: bool)

method GetGroupRecord(
  gid: ?int,
  groupName: ?string,
  service: string
) -> (record: object, incomplete: bool)

method GetMemberships(
  userName: ?string,
  groupName: ?string,
  service: string
) -> (userName: string, groupName: string)

error NoRecordFound ()

error BadService ()

error ServiceNotAvailable ()

error ConflictingRecordFound ()

error EnumerationNotSupported ()

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/winbindd/winbindd_varlink.c
source3/winbindd/winbindd_varlink.h

index edc55143fd8314abe5d297aec98762af18d01db2..85ec59eb7e9167489269faeb4d3ccf8343cdf436 100644 (file)
 
 #define WB_VL_SOCKET_DIR  "/run/systemd/userdb"
 
+static const char s_interface[] =
+"interface io.systemd.UserDatabase\n"
+""
+"method GetUserRecord("
+"  uid: ?int,"
+"  userName: ?string,"
+"  service: string"
+") -> (record: object, incomplete: bool)\n"
+""
+"method GetGroupRecord("
+"  gid: ?int,"
+"  groupName: ?string,"
+"  service: string"
+") -> (record: object, incomplete: bool)\n"
+""
+"method GetMemberships("
+"  userName: ?string,"
+"  groupName: ?string,"
+"  service: string"
+") -> (userName: string, groupName: string)\n"
+""
+"error NoRecordFound ()\n"
+"error BadService ()\n"
+"error ServiceNotAvailable ()\n"
+"error ConflictingRecordFound ()\n"
+"error EnumerationNotSupported ()\n";
+
 struct wb_vl_state {
        VarlinkService *service;
        struct tevent_context *ev_ctx;
@@ -30,6 +57,38 @@ struct wb_vl_state {
        int fd;
 };
 
+static long io_systemd_getuserrecord(VarlinkService *service,
+                                    VarlinkCall *call,
+                                    VarlinkObject *parameters,
+                                    uint64_t flags,
+                                    void *userdata)
+{
+       return varlink_call_reply_error(call,
+                       WB_VL_REPLY_ERROR_NO_RECORD_FOUND,
+                       NULL);
+}
+
+static long io_systemd_getgrouprecord(VarlinkService *service,
+                                     VarlinkCall *call,
+                                     VarlinkObject *parameters,
+                                     uint64_t flags,
+                                     void *userdata)
+{
+       return varlink_call_reply_error(call,
+                       WB_VL_REPLY_ERROR_NO_RECORD_FOUND,
+                       NULL);
+}
+
+static long io_systemd_getmemberships(VarlinkService *service,
+                                     VarlinkCall *call,
+                                     VarlinkObject *parameters,
+                                     uint64_t flags,
+                                     void *userdata)
+{
+       return varlink_call_reply_error(call,
+                       WB_VL_REPLY_ERROR_NO_RECORD_FOUND,
+                       NULL);
+}
 
 static void varlink_listen_fde_handler(struct tevent_context *ev,
                                       struct tevent_fd *fde,
@@ -111,6 +170,17 @@ bool winbind_setup_varlink(TALLOC_CTX *mem_ctx,
                goto fail;
        }
 
+       rc = varlink_service_add_interface(state->service, s_interface,
+                       "GetUserRecord", io_systemd_getuserrecord, state,
+                       "GetGroupRecord", io_systemd_getgrouprecord, state,
+                       "GetMemberships", io_systemd_getmemberships, state,
+                       NULL);
+       if (rc < 0) {
+               DBG_ERR("Failed to add Varlink interface: %s\n",
+                       varlink_error_string(rc));
+               goto fail;
+       }
+
        state->fd = varlink_service_get_fd(state->service);
        if (state->fd < 0) {
                DBG_ERR("Failed to get varlink fd: %s\n",
index ed5ca6a5dd3810a0c867694d06b46f356ca65a32..997c04229707f28725164ee876916a017ab86950 100644 (file)
 
 #define WB_VL_SERVICE_NAME "org.samba.winbind"
 
+#define WB_VL_REPLY_ERROR_NO_RECORD_FOUND \
+       "io.systemd.UserDatabase.NoRecordFound"
+#define WB_VL_REPLY_ERROR_BAD_SERVICE \
+       "io.systemd.UserDatabase.BadService"
+#define WB_VL_REPLY_ERROR_SERVICE_NOT_AVAILABLE \
+       "io.systemd.UserDatabase.ServiceNotAvailable"
+#define WB_VL_REPLY_ERROR_CONFLICTING_RECORD_FOUND \
+       "io.systemd.UserDatabase.ConflictingRecordFound"
+#define WB_VL_REPLY_ERROR_ENUMERATION_NOT_SUPPORTED \
+       "io.systemd.UserDatabase.EnumerationNotSupported"
+
+
 bool winbind_setup_varlink(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx);
 
 #endif /* _SOURCE3_WINBIND_VARLINK_H_ */