<div dir="ltr"><div><div>Hello,<br><br></div>I am writing one GTK application where I want to run GUI as normal user and issue one pthread with root privileges.<br><br>I have kept the following as policy file<br><br>=====================<br>$ cat /usr/share/polkit-1/actions/Myappln.policy<br><?xml version="1.0" encoding="UTF-8"?><br><!DOCTYPE policyconfig PUBLIC<br> "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"<br>  "<a href="http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd</a>"><br><policyconfig><br>    <vendor>Company Name</vendor><br>    <vendor_url><a href="http://www.website.com/">http://www.website.com/</a></vendor_url><br>    <action id="Myappln"><br>        <description>Policy Kit for Myappln</description><br>        <message>Administrator Authentication is required to run Myappln</message><br>        <icon_name>audio-x-generic</icon_name><br>        <defaults><br>            <allow_any>no</allow_any><br>            <allow_inactive>no</allow_inactive><br>            <allow_active>auth_admin</allow_active><br>        </defaults><br>        <annotate key="org.freedesktop.policykit.exec.path">/usr/local/bin/Myappln</annotate><br>    </action><br></policyconfig><br><br>=====================<br><br>I have written one small C function as follows:<br><br>=====================<br>static void check_authorization_cb(PolkitAuthority *authority, GAsyncResult *res, GMainLoop *loop)<br>{<br>    PolkitAuthorizationResult *result;<br>    GError *error = NULL;<br><br>    result = polkit_authority_check_authorization_finish(authority, res, &error);<br>    if (error)<br>    {<br>        append_gui_log( ERRNO_ERROR_MSG, "Error checking authorization: %s\n", error->message);<br>    }<br>    if( polkit_authorization_result_get_is_authorized(result) )<br>    {<br>        fprintf( stderr, "Authorization Success\n" );<br>    }<br>    else<br>    {<br>        fprintf( stderr, "Unable to get authorization. Exiting...\n" );<br>        exit(1);<br>    }<br>    if( socket( PF_PACKET, SOCK_RAW|SOCK_NONBLOCK, htons( ETH_P_ALL ) ) == -1 )<br>    {<br>        fprintf( stderr, "%s %d Unable to create socket\n", __func__, __LINE__ );<br>        char error_string[200] = "";<br>        strerror_r( errno, error_string, 200 );<br>        fprintf( stderr, "Message indicated by errno(%d) : %s\n", errno, error_string );<br>    }<br>    else<br>    {<br>        fprintf( stderr, "%s %d success\n", __func__, __LINE__ );<br>    }<br>    g_main_loop_quit(loop);<br>}<br><br>void get_authorization_to_proceed()<br>{<br>    PolkitAuthority *authority;<br>    PolkitSubject *subject;<br>    GMainLoop *loop;<br><br>    loop = g_main_loop_new(NULL, FALSE);<br>    authority = polkit_authority_get_sync(NULL, NULL); <br>    subject = polkit_unix_process_new_for_owner( getpid(), 0, -1 );<br>    polkit_authority_check_authorization(    authority,<br>                                    subject,<br>                                    "Myappln",<br>                                    NULL,<br>                                    POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,<br>                                    NULL,<br>                                    (GAsyncReadyCallback) check_authorization_cb,<br>                                    loop);<br>    g_main_loop_run(loop);<br>    g_object_unref(authority);<br>    g_object_unref(subject);<br>    g_main_loop_unref(loop);<br>}<br>=====================<br><br>I am seeing the "Authorization Success" message and "Unable to create socket".<br>Actually to create socket, root previliges are required.<br>I am not able to understand what mistake I am doing.<br>Can someone help me how to spawn pthread with root privileges ?<br><br></div>Complete Code is in C Language.<br><div><div><br><div><div><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Thanks & Regards<br>--<br>Lokesh Chakka,<br>Mobile: 9731023458<br></div></div></div></div></div></div></div></div></div>
</div></div></div></div></div>