<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>