]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-login: add sd_session_get_username
authorMike Yuan <me@yhndnzj.com>
Thu, 23 Feb 2023 16:48:10 +0000 (00:48 +0800)
committerMike Yuan <me@yhndnzj.com>
Thu, 23 Feb 2023 18:12:08 +0000 (02:12 +0800)
man/sd_session_is_active.xml
src/libsystemd/libsystemd.sym
src/libsystemd/sd-login/sd-login.c
src/systemd/sd-login.h

index b69fa137821ad932b698ad07880b45e1c93f5b61..b62c35ae7401236e9b780d81d1f1a7e9148c19d3 100644 (file)
@@ -21,6 +21,7 @@
     <refname>sd_session_is_remote</refname>
     <refname>sd_session_get_state</refname>
     <refname>sd_session_get_uid</refname>
+    <refname>sd_session_get_username</refname>
     <refname>sd_session_get_seat</refname>
     <refname>sd_session_get_service</refname>
     <refname>sd_session_get_type</refname>
         <paramdef>uid_t *<parameter>uid</parameter></paramdef>
       </funcprototype>
 
+      <funcprototype>
+        <funcdef>int <function>sd_session_get_username</function></funcdef>
+        <paramdef>const char *<parameter>session</parameter></paramdef>
+        <paramdef>char **<parameter>username</parameter></paramdef>
+      </funcprototype>
+
       <funcprototype>
         <funcdef>int <function>sd_session_get_seat</function></funcdef>
         <paramdef>const char *<parameter>session</parameter></paramdef>
     determine the user identifier of the Unix user the session
     identified by the specified session identifier belongs to.</para>
 
+    <para><function>sd_session_get_username()</function> may be used to
+    determine the name of the Unix user the session identified by
+    the specified session identifier belongs to. The returned string
+    needs to be freed with the libc
+    <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+    call after use.</para>
+
     <para><function>sd_session_get_seat()</function> may be used to
     determine the seat identifier of the seat the session identified
     by the specified session identifier belongs to. Note that not all
     positive integer; if it fails, 0.  On success,
     <function>sd_session_get_state()</function>,
     <function>sd_session_get_uid()</function>,
+    <function>sd_session_get_username()</function>,
     <function>sd_session_get_seat()</function>,
     <function>sd_session_get_service()</function>,
     <function>sd_session_get_type()</function>,
index 802009b710013132316a9cce19984dd9c5507d8e..013167f0979e084426adaf8f95e5f3cc56b558c0 100644 (file)
@@ -812,3 +812,8 @@ global:
         sd_pidfd_get_user_unit;
         sd_journal_get_seqnum;
 } LIBSYSTEMD_252;
+
+LIBSYSTEMD_254 {
+global:
+        sd_session_get_username;
+} LIBSYSTEMD_253;
index d483889fd18531c8bc8d3dadd2fa65a6531d2041..a01855d5830d11fe3dbf02804ec8e68b4669ced3 100644 (file)
@@ -742,6 +742,10 @@ static int session_get_string(const char *session, const char *field, char **val
         return 0;
 }
 
+_public_ int sd_session_get_username(const char *session, char **username) {
+        return session_get_string(session, "USER", username);
+}
+
 _public_ int sd_session_get_seat(const char *session, char **seat) {
         return session_get_string(session, "SEAT", seat);
 }
index 85dd086e2b94e384887d849a166bc9256c89bf78..fefc05667b1b7cc9603937ec73ff57222f9e259e 100644 (file)
@@ -157,6 +157,9 @@ int sd_session_get_state(const char *session, char **state);
 /* Determine user ID of session */
 int sd_session_get_uid(const char *session, uid_t *uid);
 
+/* Determine username of session */
+int sd_session_get_username(const char *session, char **username);
+
 /* Determine seat of session */
 int sd_session_get_seat(const char *session, char **seat);