Enlightenment CVS committal Author : mekius Project : e17 Module : proto
Dir : e17/proto/empower/src/bin/ewl Modified Files: Empower.h Makefile.am empower.c empower_cb_ewl.c empower_gui_ewl.c Added Files: empower_helper_ewl.c Removed Files: .cvsignore Log Message: Version 1.0\n - Empower now behaves much more like sudo itself. It respects the timeout\n and also will reask if you mistype your password. The amount of retries\n is all based on your settings in the sudoers file.\n - Also, command line options can be passed to sudo as well as EWL on the\n empower command line.\n - With the massive changes and cleanups, this release deserves a 1.0 :)\n\nI highly recommend all current empower users update to this version, it is much better ;) Let me know of any errors you find, I tried to test it a lot, but I usually miss some minor detail. =================================================================== RCS file: /cvs/e/e17/proto/empower/src/bin/ewl/Empower.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- Empower.h 12 Feb 2007 22:13:08 -0000 1.7 +++ Empower.h 30 May 2007 03:30:31 -0000 1.8 @@ -4,7 +4,9 @@ #include <unistd.h> #include <string.h> #include <stdio.h> +#include <stdlib.h> #include <sys/types.h> +#include <sys/wait.h> #include <pwd.h> #include "Ecore_X.h" #include "Ewl.h" @@ -12,18 +14,32 @@ #define WIDTH 0 #define HEIGHT 85 Ewl_Widget *win; -char password[1024]; -char buf[1024]; +Ewl_Widget *entry; +char cmd[1024]; +Ecore_Exe *sudo; /* empower_cb prototypes */ void key_down_cb(Ewl_Widget *w, void *event, void *data); void destroy_cb(Ewl_Widget *w, void *event, void *data); void reveal_cb(Ewl_Widget *w, void *event, void *data); -void pipe_to_sudo_cb(Ewl_Widget *w, void *event, void *data); +void check_pass_cb(Ewl_Widget *w, void *event, void *data); +int wait_for_sudo(void *data); +int sudo_done_cb(void *data, int type, void *event); +int sudo_data_cb(void *data, int type, void *event); +int exit_cb(void *data, int type, void *event); /* empower_cb prototypes end */ /* empower_gui prototypes */ +void setup_window(); void display_window(); +void hide_window(); /* empower_gui prototypes end */ + +/* empower_helper prototypes */ +int authorize(char* password); +int idle(void *data); +int idle_exit(void *data); +void check_sudo_timeout_job(void *data); +/* empower_helper prototypes end */ #endif =================================================================== RCS file: /cvs/e/e17/proto/empower/src/bin/ewl/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- Makefile.am 23 Mar 2007 02:27:16 -0000 1.3 +++ Makefile.am 30 May 2007 03:30:31 -0000 1.4 @@ -7,7 +7,8 @@ if BUILD_SEPARATE bin_PROGRAMS = empower_ewl -empower_ewl_SOURCES = empower.c empower_cb_ewl.c empower_gui_ewl.c +empower_ewl_SOURCES = empower.c empower_cb_ewl.c empower_gui_ewl.c \ + empower_helper_ewl.c empower_ewl_CFLAGS = @EWL_CFLAGS@ @@ -16,7 +17,8 @@ else bin_PROGRAMS = empower -empower_SOURCES = empower.c empower_cb_ewl.c empower_gui_ewl.c +empower_SOURCES = empower.c empower_cb_ewl.c empower_gui_ewl.c \ + empower_helper_ewl.c empower_CFLAGS = @EWL_CFLAGS@ =================================================================== RCS file: /cvs/e/e17/proto/empower/src/bin/ewl/empower.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- empower.c 7 Sep 2006 17:22:49 -0000 1.3 +++ empower.c 30 May 2007 03:30:31 -0000 1.4 @@ -2,37 +2,52 @@ int main(int argc, char** argv) { - --argc; ++argv; + --argc; ++argv; //pop off program name + sudo = NULL; - if(argc) //commands + if(!ecore_init()) { - pid_t id = fork(); + printf("Unable to init ecore\n"); + return 1; + } + + if(argc) //commands + { + int i; + + ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT,exit_cb,NULL); - if(id == 0) - { - ecore_exe_run("sudo -k", NULL); - return 0; - } - else + snprintf(cmd, 1024, "sudo"); + + while(argc) { - snprintf(buf, 1024, "sudo -S %s ", *argv); - - --argc; ++argv; - while(argc) + if(strcmp(*argv, "--")) //-- is used to stop sudo options, lets use that { - strncat(buf, " ", 1024); - strncat(buf, *argv, 1024); - --argc; ++argv; + strncat(cmd, " ", 1024); + strncat(cmd, *argv, 1024); + --argc; ++argv; //pop these options off so ewl just gets its options } + else + break; + } + + if(!ewl_init(&argc, argv)) + { + printf("Unable to init ewl\n"); + return; } + + ecore_job_add(check_sudo_timeout_job, NULL); + + ewl_main(); + + ecore_exe_run(cmd,NULL); } else { - printf("Usage: ./empower <program name>\n"); + printf("Usage: ./empower [SUDO OPTIONS] <program name> [PROGRAM OPTIONS] -- [EWL OPTIONS]\n"); return 1; } - - display_window(argc, argv); return 0; } =================================================================== RCS file: /cvs/e/e17/proto/empower/src/bin/ewl/empower_cb_ewl.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- empower_cb_ewl.c 6 Mar 2007 19:36:43 -0000 1.5 +++ empower_cb_ewl.c 30 May 2007 03:30:31 -0000 1.6 @@ -1,5 +1,4 @@ #include "Empower.h" -#include <Ecore_X.h> void key_down_cb(Ewl_Widget *w, void *event, void *data) { @@ -13,6 +12,7 @@ { ewl_widget_destroy(EWL_WIDGET(win)); ewl_main_quit(); + exit(-1); } } } @@ -21,6 +21,8 @@ { ewl_widget_destroy(EWL_WIDGET(win)); ewl_main_quit(); + + exit(-1); } void reveal_cb(Ewl_Widget *w, void *event, void *data) @@ -28,26 +30,42 @@ ewl_window_raise(EWL_WINDOW(win)); } -void pipe_to_sudo_cb(Ewl_Widget *w, void *event, void *data) +void check_pass_cb(Ewl_Widget *w, void *event, void *data) { - FILE *sudo_pipe; - - const char *pass = ewl_password_text_get(EWL_PASSWORD(data)); + char *pass = ewl_password_text_get(EWL_PASSWORD(data)); - ewl_widget_destroy(win); + authorize(pass); + ewl_widget_disable(win); +} + +int sudo_done_cb(void *data, int type, void *event) +{ + Ecore_Exe_Event_Del *ev = event; + int* code = data; + + sudo = NULL; ewl_main_quit(); + + if((ev->exit_code)) + exit(-1); + + return 0; +} - if(pass) - { - snprintf(password, 1024, "%s", pass); - - pid_t pid = fork(); - - if(pid == 0) - { - sudo_pipe = popen(buf, "w"); - fprintf(sudo_pipe, "%s\n", password); - pclose(sudo_pipe); - } - } +int sudo_data_cb(void *data, int type, void *event) +{ + Ecore_Exe_Event_Data *ev = event; + + if(ev->size > 1) + display_window(); + + return 0; +} + +//EXIT SIGNAL HANDLER +int exit_cb(void *data, int type, void *event) +{ + ewl_main_quit(); + + exit(-1); } =================================================================== RCS file: /cvs/e/e17/proto/empower/src/bin/ewl/empower_gui_ewl.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -3 -r1.17 -r1.18 --- empower_gui_ewl.c 13 Feb 2007 02:32:15 -0000 1.17 +++ empower_gui_ewl.c 30 May 2007 03:30:31 -0000 1.18 @@ -1,14 +1,7 @@ #include "Empower.h" -void display_window(int argc, char** argv) -{ - if(!ewl_init(&argc, argv)) - { - printf("Unable to init ewl\n"); - return; - } - - Ewl_Widget *entry = NULL; +void setup_window() +{ Ewl_Widget *ok_button = NULL; Ewl_Widget *cancel_button = NULL; Ewl_Widget *progtext = NULL; @@ -29,12 +22,10 @@ ewl_window_name_set(EWL_WINDOW(win), "Empower!"); ewl_window_class_set(EWL_WINDOW(win), "Empower!"); ewl_window_dialog_set(EWL_WINDOW(win), 1); - ewl_window_keyboard_grab_set(EWL_WINDOW(win), 1); ewl_callback_append(win, EWL_CALLBACK_DELETE_WINDOW, destroy_cb, NULL); ewl_callback_prepend(win, EWL_CALLBACK_REVEAL, reveal_cb, NULL); ewl_callback_append(win, EWL_CALLBACK_KEY_DOWN, key_down_cb, NULL); - ewl_widget_show(win); - + ewl_window_keyboard_grab_set(EWL_WINDOW(win), 1); ewl_dialog_active_area_set(EWL_DIALOG(win), EWL_POSITION_TOP); hbox = ewl_hbox_new(); @@ -66,7 +57,7 @@ entry = ewl_password_new(); ewl_container_child_append(EWL_CONTAINER(vbox), entry); - ewl_callback_append(entry, EWL_CALLBACK_VALUE_CHANGED, pipe_to_sudo_cb, + ewl_callback_append(entry, EWL_CALLBACK_VALUE_CHANGED, check_pass_cb, entry); ewl_widget_focus_send(entry); ewl_widget_show(entry); @@ -78,7 +69,7 @@ ewl_object_fill_policy_set(EWL_OBJECT(ok_button), EWL_FLAG_FILL_NONE | EWL_FLAG_FILL_HFILL); ewl_container_child_append(EWL_CONTAINER(win), ok_button); - ewl_callback_append(ok_button, EWL_CALLBACK_CLICKED, pipe_to_sudo_cb, + ewl_callback_append(ok_button, EWL_CALLBACK_CLICKED, check_pass_cb, entry); ewl_widget_show(ok_button); @@ -90,6 +81,10 @@ ewl_callback_append(cancel_button, EWL_CALLBACK_CLICKED, destroy_cb, NULL); ewl_widget_show(cancel_button); - - ewl_main(); +} + +void display_window() +{ + setup_window(); + ewl_widget_show(win); } ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs