[uim-commit] r676 - in trunk: scm uim

tkng at freedesktop.org tkng at freedesktop.org
Sun Feb 20 05:12:51 PST 2005


Author: tkng
Date: 2005-02-20 05:12:48 -0800 (Sun, 20 Feb 2005)
New Revision: 676

Modified:
   trunk/scm/init.scm
   trunk/scm/plugin.scm
   trunk/scm/skk.scm
   trunk/uim/uim-helper.c
   trunk/uim/uim-ipc.c
   trunk/uim/uim-util.c
   trunk/uim/uim-util.h
   trunk/uim/uim.c
Log:
* uim/uim-helper.c:
 -(is_setugid): New function to check uid and euid.
 
* uim/uim-ipc.c:
 -(uim_ipc_open_command_with_option): If uid and euid is not the same,
   full path of the command should be passed to execlp.

* uim/uim.c:
 -(uim_init_scm): If uid and euid is not the same,
  getenv() shouldn't be called.
  
* scm/init.scm: If uid and euid is not the same,
  getenv shouldn't be called.
  
* scm/plugin.scm; If uid and euid is not the same,
  getenv shouldn't be called.

* scm/skk.scm; If uid and euid is not the same,
  getenv shouldn't be called



Modified: trunk/scm/init.scm
===================================================================
--- trunk/scm/init.scm	2005-02-19 05:02:08 UTC (rev 675)
+++ trunk/scm/init.scm	2005-02-20 13:12:48 UTC (rev 676)
@@ -48,15 +48,17 @@
 
 (define load-user-conf
   (lambda ()
-    (let ((orig-verbose (verbose))
-	  (file (or (getenv "LIBUIM_USER_SCM_FILE")
-		    (string-append (getenv "HOME") "/.uim"))))
-      (if (>= (verbose)
-	      1)
-	  (verbose 1))
-      (let ((succeeded (try-load file)))
-	(verbose orig-verbose)
-	succeeded))))
+    (if (is-set-ugid?)
+	#f
+	(let ((orig-verbose (verbose))
+	      (file (or (getenv "LIBUIM_USER_SCM_FILE")
+			(string-append (getenv "HOME") "/.uim"))))
+	  (if (>= (verbose)
+		  1)
+	      (verbose 1))
+	  (let ((succeeded (try-load file)))
+	    (verbose orig-verbose)
+	    succeeded)))))
 
 (define load-modules
   (lambda ()

Modified: trunk/scm/plugin.scm
===================================================================
--- trunk/scm/plugin.scm	2005-02-19 05:02:08 UTC (rev 675)
+++ trunk/scm/plugin.scm	2005-02-20 13:12:48 UTC (rev 676)
@@ -35,21 +35,24 @@
 (require "util.scm")
 
 (define uim-plugin-lib-load-path
-  (filter string?
-	  (append (list (getenv "LIBUIM_PLUGIN_LIB_DIR")
-			(string-append (getenv "HOME") "/.uim.d/plugin")
-			(string-append (sys-pkglibdir) "/plugin"))
-		  ;; XXX
-		  (if (getenv "LD_LIBRARY_PATH")
-		      (string-split (getenv "LD_LIBRARY_PATH") ":")
-		      ()))))
+   (if (is-set-ugid?)
+       (list (string-append (sys-pkglibdir) "/plugin"))
+       (filter string?
+ 	      (append (list (getenv "LIBUIM_PLUGIN_LIB_DIR")
+ 			    (string-append (getenv "HOME") "/.uim.d/plugin")
+ 			    (string-append (sys-pkglibdir) "/plugin"))
+ 		      ;; XXX
+ 		      (if (getenv "LD_LIBRARY_PATH")
+ 			  (string-split (getenv "LD_LIBRARY_PATH") ":")
+ 			  ())))))
 
 (define uim-plugin-scm-load-path
-  (filter string?
-	  (list (getenv "LIBUIM_SCM_FILES")
-		(string-append (getenv "HOME") "/.uim.d/plugin")
-		(sys-pkgdatadir))))
-		
+  (if (is-set-ugid?)
+      (list (sys-pkgdatadir))
+      (filter string?
+ 	      (list (getenv "LIBUIM_SCM_FILES")
+ 		    (string-append (getenv "HOME") "/.uim.d/plugin")
+ 		    (sys-pkgdatadir)))))
 
 (define plugin-alist ())
 (define plugin-func-alist ())
@@ -122,14 +125,16 @@
 	   (conf-file "installed-modules.scm")
 	   (user-conf-file (string-append user-module-dir conf-file)))
       (try-load conf-file)
-      (if (not (getenv "LIBUIM_VANILLA"))
-	  (let ((orig-module-list installed-im-module-list)
-		(orig-enabled-list enabled-im-list))
-	    (and (try-load user-conf-file)
-		 (set! installed-im-module-list
-		       (append orig-module-list installed-im-module-list))
-		 (set! enabled-im-list
-		       (append orig-enabled-list enabled-im-list))))))))
+      (if (is-set-ugid?)
+	  #f
+	  (if (not (getenv "LIBUIM_VANILLA"))
+	      (let ((orig-module-list installed-im-module-list)
+		    (orig-enabled-list enabled-im-list))
+		(and (try-load user-conf-file)
+		     (set! installed-im-module-list
+			   (append orig-module-list installed-im-module-list))
+		     (set! enabled-im-list
+			   (append orig-enabled-list enabled-im-list)))))))))
 
 
 ;; TODO: write test
@@ -139,5 +144,7 @@
 	   (file "loader.scm")
 	   (user-file (string-append user-module-dir file)))
       (and (try-load file)
-	   (or (try-load user-file)
-	       #t)))))
+	   (or 
+	    (if (is-set-ugid?) 
+		(try-load user-file)
+		#t))))))

Modified: trunk/scm/skk.scm
===================================================================
--- trunk/scm/skk.scm	2005-02-19 05:02:08 UTC (rev 675)
+++ trunk/scm/skk.scm	2005-02-20 13:12:48 UTC (rev 676)
@@ -268,12 +268,14 @@
 
 (define skk-read-personal-dictionary
   (lambda ()
-    (or (skk-lib-read-personal-dictionary skk-uim-personal-dic-filename)
-	(skk-lib-read-personal-dictionary skk-personal-dic-filename))))
+    (if (not (is-set-ugid?))
+	(or (skk-lib-read-personal-dictionary skk-uim-personal-dic-filename)
+	    (skk-lib-read-personal-dictionary skk-personal-dic-filename)))))
 
 (define skk-save-personal-dictionary
   (lambda ()
-    (skk-lib-save-personal-dictionary skk-uim-personal-dic-filename)))
+    (if (not (is-set-ugid?))
+	(skk-lib-save-personal-dictionary skk-uim-personal-dic-filename))))
 
 (define skk-flush
   (lambda (sc)

Modified: trunk/uim/uim-helper.c
===================================================================
--- trunk/uim/uim-helper.c	2005-02-19 05:02:08 UTC (rev 675)
+++ trunk/uim/uim-helper.c	2005-02-20 13:12:48 UTC (rev 676)
@@ -164,11 +164,13 @@
 uim_helper_get_pathname(void)
 {
   char *path;
-  char *login;
+  char *login = NULL;
   struct passwd *pw = NULL;
  
-  login = getenv("LOGNAME");
-  
+  if(is_setugid() == 0) {
+    login = getenv("LOGNAME");
+  }
+
   if (!login) {
     pw = getpwuid(getuid());
     login = strdup(pw->pw_name);
@@ -205,3 +207,17 @@
 
   return 0;
 }
+
+int
+is_setugid(void)
+{
+  uid_t ruid = getuid();  /* real uid */
+  gid_t rgid = getgid();  /* real gid */
+  uid_t euid = geteuid(); /* effective uid */
+  gid_t egid = getegid(); /* effective gid */
+
+  if (ruid != euid || rgid != egid) {
+    return 1;
+  }
+  return 0;
+}

Modified: trunk/uim/uim-ipc.c
===================================================================
--- trunk/uim/uim-ipc.c	2005-02-19 05:02:08 UTC (rev 675)
+++ trunk/uim/uim-ipc.c	2005-02-20 13:12:48 UTC (rev 676)
@@ -197,8 +197,24 @@
       }
       *ap = NULL;
     }
+    if(is_setugid() != 0) {
+      int cmd_len = strlen(command) + 30;
+      char *fullpath_command = malloc(cmd_len);
+      
+      /*if(setuid(getuid())!=0) abort();*/ /* discarding privilege */
+      
+      snprintf(fullpath_command, cmd_len, "/usr/local/bin/%s", command);
 
-    result = execvp(command, argv);
+      result = execvp(fullpath_command, argv);
+
+      if(result == -1) {
+ 	snprintf(fullpath_command, cmd_len, "/usr/bin/%s", command);
+	result = execvp(fullpath_command, argv);
+      }
+      free(fullpath_command);
+    } else {
+      result = execvp(command, argv);
+    }
     free(str);
 
     if(result == -1) {

Modified: trunk/uim/uim-util.c
===================================================================
--- trunk/uim/uim-util.c	2005-02-19 05:02:08 UTC (rev 675)
+++ trunk/uim/uim-util.c	2005-02-20 13:12:48 UTC (rev 676)
@@ -284,6 +284,7 @@
   if (!str) {
     return uim_scm_f();
   }
+
   val = getenv(str);
   if (val) {
     return uim_scm_make_str(val);
@@ -484,6 +485,15 @@
   return (name) ? uim_scm_make_str(name) : uim_scm_f();
 }
 
+static uim_lisp
+is_setugidp(void)
+{
+  if(is_setugid()) {
+    return uim_scm_t();
+  }
+  return uim_scm_f();
+}
+
 void
 uim_init_util_subrs()
 {
@@ -511,4 +521,5 @@
   uim_scm_init_subr_2("string-split", uim_split_string);
   uim_scm_init_subr_1("string-to-list", eucjp_string_to_list);
   uim_scm_init_subr_1("lang-code->lang-name-raw", lang_code_to_lang_name_raw);
+  uim_scm_init_subr_0("is-set-ugid?", is_setugidp);
 }

Modified: trunk/uim/uim-util.h
===================================================================
--- trunk/uim/uim-util.h	2005-02-19 05:02:08 UTC (rev 675)
+++ trunk/uim/uim-util.h	2005-02-20 13:12:48 UTC (rev 676)
@@ -52,6 +52,9 @@
 const char *
 uim_get_language_name_from_locale(const char *localename);
 
+int
+is_setugid(void);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/uim/uim.c
===================================================================
--- trunk/uim/uim.c	2005-02-19 05:02:08 UTC (rev 675)
+++ trunk/uim/uim.c	2005-02-20 13:12:48 UTC (rev 676)
@@ -610,10 +610,12 @@
 uim_init_scm()
 {
   int i;
-  char *scm_files;
-  char *env;
+  char *scm_files = NULL;
+  char *env = NULL;
 
-  env = getenv("LIBUIM_VERBOSE");
+  /*  if(is_setugid() == 0) {*/
+    env = getenv("LIBUIM_VERBOSE");
+    /*  }*/
   uim_scm_init(env);  /* init Scheme interpreter */
 
 #ifdef UIM_COMPAT_SCM
@@ -628,7 +630,10 @@
   uim_init_table_subrs();
 #endif
 
-  scm_files = getenv("LIBUIM_SCM_FILES");
+  
+  if(is_setugid() == 0) {
+    scm_files = getenv("LIBUIM_SCM_FILES");
+  }
   uim_scm_set_lib_path((scm_files) ? scm_files : SCM_FILES);
 
   uim_scm_require_file("init.scm");



More information about the Uim-commit mailing list