After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 787073 - rtsp-server permissions: need add_role() function that's bindings friendly and can be used in python
rtsp-server permissions: need add_role() function that's bindings friendly an...
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-rtsp-server
git master
Other Linux
: Normal major
: 1.13.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
: 792547 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2017-08-31 10:55 UTC by Aurelien BOUIN
Modified: 2018-07-13 08:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
rtsp-token: add some API to set fields from bindings (4.73 KB, patch)
2018-01-18 11:34 UTC, Tim-Philipp Müller
committed Details | Review
rtsp-token: annotate constructors for bindings (1.37 KB, patch)
2018-01-18 11:35 UTC, Tim-Philipp Müller
committed Details | Review

Description Aurelien BOUIN 2017-08-31 10:55:07 UTC
In c we have :
auth = gst_rtsp_auth_new ();
[...]
 /* make user token */
  token =
      gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
      "user", NULL);
  basic = gst_rtsp_auth_make_basic ("user", "password");
  gst_rtsp_auth_add_basic (auth, basic, token);
[...]
  /* configure in the server */
  gst_rtsp_server_set_auth (server, auth);

[and later]

  permissions = gst_rtsp_permissions_new ();
  gst_rtsp_permissions_add_role (permissions, "user",
      GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE,
      GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL);
  gst_rtsp_media_factory_set_permissions (factory, permissions);

but in python :
auth = GstRtspServer.RTSPAuth()
token = GstRtspServer.RTSPToken(GstRtspServer.RTSP_TOKEN_MEDIA_FACTORY_ROLE, 
                   GObject.TYPE_STRING, 
                   'user', 
                   None)

# But this fails with: 
# TypeError: Passing arguments to gi.types.Boxed.__init__() is deprecated. All arguments passed will be ignored.

basic = auth.make_basic("user", "password")
auth.add_basic(basic, token)
server.set_auth(auth)

[and later]

permissions = GstRtspServer.RTSPPermissions()

# but neither permissions nor auth have a method add_role(), which I need



How to help ?
Thank you


Someone else get the problem here : https://github.com/thaytan/gst-rpicamsrc/issues/20
Comment 1 Aurelien BOUIN 2017-08-31 14:28:19 UTC
Seems like va_list is not compatible with GObjectIntrospection :
https://wiki.gnome.org/Projects/GObjectIntrospection/WritingBindingableAPIs
So authentication is not working at all with python
Aurelien BOUIN
Comment 2 Tim-Philipp Müller 2017-09-02 19:17:15 UTC
So we need to come up with functions that are bindable and that can be used to achieve the same thing.

It appears the vararg bits are basically just read into a GstStructure, so maybe we can make a function that takes a GstStructure as argument. I assume there's decent-enough support in bindings for GstStructures, or at least some sugar in gst-python? (someone should test/confirm this)

Alternatively, a function that takes a fieldname + GValue might work and we can then build up the GstStructure internally. Not entirely sure how GValue args get mapped for bindings though, if that's a good choice or not.
Comment 3 Tim-Philipp Müller 2018-01-17 19:48:06 UTC
*** Bug 792547 has been marked as a duplicate of this bug. ***
Comment 4 cp.unid 2018-01-17 19:53:03 UTC
@Tim-Philipp Can you give me some more direction for resolving this bug through the current Python bindings? I can look into doing something myself unless this has to be done at the rtsp-server addon level.
Comment 5 Tim-Philipp Müller 2018-01-17 19:58:02 UTC
I don't think there is a solution with the current Python bindings. It needs new C API that is usable for bindings.
Comment 6 Tim-Philipp Müller 2018-01-18 11:34:50 UTC
Created attachment 367007 [details] [review]
rtsp-token: add some API to set fields from bindings
Comment 7 Tim-Philipp Müller 2018-01-18 11:35:16 UTC
Created attachment 367008 [details] [review]
rtsp-token: annotate constructors for bindings
Comment 8 Tim-Philipp Müller 2018-01-18 11:36:46 UTC
With the above patches, this works for me now:

import gi
from gi.repository import Gst
from gi.repository import GstRtspServer
Gst.init()
print(Gst.version_string())
server = GstRtspServer.RTSPServer()
auth = GstRtspServer.RTSPAuth()
#token = GstRtspServer.RTSPToken.new_empty()
#token = GstRtspServer.RTSPToken.new()
token = GstRtspServer.RTSPToken()
print(token)
token.set_string('role','user')
print(token.get_string('role'))
print(token.is_allowed('perm'))
token.set_bool('perm',True)
print(token.is_allowed('perm'))
basic = auth.make_basic("user", "password")
auth.add_basic(basic, token)
server.set_auth(auth)
Comment 9 Tim-Philipp Müller 2018-01-19 00:00:00 UTC
Pushed slightly modified version that uses _get_writable_structure() to make sure the token is writable:

commit 8708262ebe27f04f66fad4448c95042713ea5d49 (HEAD -> master)
Author: Tim-Philipp Müller <tim@centricular.com>
Date:   Thu Jan 18 11:32:32 2018 +0000

    rtsp-token: annotate constructors for bindings
    
    This maps _new_empty() to _new(), which also makes RTSPToken()
    work properly now. Since this API wasn't usable from bindings
    before, this should hopefully be fine.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=787073

commit 54a8c6bddfb877c5eb953ffeb3892ceae4b91835
Author: Tim-Philipp Müller <tim@centricular.com>
Date:   Thu Jan 18 11:07:45 2018 +0000

    rtsp-token: add some API to set fields from bindings
    
    The existing functions are all vararg-based and as such
    not usable from bindings.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=787073

commit b1f515178a363df0322d7adbd5754e1f6e2083c9 (HEAD -> master)
Author: Tim-Philipp Müller <tim@centricular.com>
Date:   Thu Jan 18 23:53:20 2018 +0000

    permissions: add some new API to make this usable from bindings
    
    https://bugzilla.gnome.org/show_bug.cgi?id=787073


Probably needs more work for advanced use cases.
Comment 10 cp.unid 2018-01-19 00:02:41 UTC
What's the release cycle like to get these fixes into aptitude? I'm running this in multiple operating systems (Windows, stretch) but getting it into stretch would be nice.
Comment 11 Sebastian Dröge (slomo) 2018-01-19 07:42:32 UTC
That's for the Debian release / stable updates team to decide and you should file a bug there or send a mail to them. I'll upload the fix to Debian unstable (and that way it will become part of the next stable release) once there is a new GStreamer release in a few weeks.
Comment 12 cp.unid 2018-01-19 15:51:46 UTC
Thanks guys.
Comment 13 oliver.schwaneberg 2018-07-13 08:56:52 UTC
I always get the following error:

ERROR rtspclient rtsp-client.c:1021:find_media: client 0xa9a0d080: not authorized to see factory path /test

ERROR rtspclient rtsp-client.c:2907:handle_describe_request: client 0xa9a0d080: no media

How do I set the right permissions for the factory via Python bindings?
I tried the following, but it had no effect:

perm = GstRtspServer.RTSPPermissions()
perm.add_role("user")
perm.add_permission_for_role("user", "media.factory.access", True)
perm.add_permission_for_role("user", "media.factory.construct", True)
factory.set_permissions(perm)

Any idea? Thanks in advance!