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