su - nowy patch

Arkadiusz Miśkiewicz misiek w zsz2.starachowice.pl
Czw, 22 Paź 1998, 08:11:16 CEST


Przyjżałem się dokładniej temu su. Jednak nie jest tak źle ;)
Aktualnie jest (z moim nowym patchem):

static void
run_shell (struct passwd *pw, const char *shell, const char *command, char **additional_args)
{
  ....
  retval = pam_open_session(pamh,0);	// To jest robione z roota
  					// <- tu wcześniej było GŁÓWNE
					// change_identity()
  if (retval != PAM_SUCCESS) {
    change_identity(pw);	// tu dałej change_identity (bezpieczniej (?))
    fprintf (stderr, "could not open session\n");
    exit (1);
  }
  child = fork();
  if (child == 0) {  /* child shell */
  change_identity(pw);		// tu GŁÓWNE change_identity()
  pam_end(pamh, 0);		// to wywoływane z nie-roota (nie przeszkadza?)
  .....
  execv (shell, (char **) args);
  error (1, errno, _("cannot run %s"), shell);
  }
  ... (jakieś tam regułki sprawdzające - ubijają childa jeśli coś jest nie tak)
  retval = pam_close_session(pamh, 0);
  PAM_BAIL_P;
  retval = pam_end(pamh, PAM_SUCCESS);
  PAM_BAIL_P;
}
	Teraz jest IMHO zgodnie z zaleceniami Grześka (Grzesiek - nic nie
spaprałem ?).

PS> Przynajmniej się C trochę nauczę ;)

-- 
 -< Arkadiusz Miśkiewicz >------------------------< Cron on IRC >-
  http://www.misiek.eu.org     mailto:misiek w zsz2.starachowice.pl
  SysAdm ZSZ2                     http://www.zsz2.starachowice.pl
 -< Linux micq UIN: 13798733 >-----------< Starachowice, POLAND >-
-------------- następna część ---------
diff -urN sh-utils-1.16.orig/src/su.c sh-utils-1.16/src/su.c
--- sh-utils-1.16.orig/src/su.c	Wed Oct 21 21:45:18 1998
+++ sh-utils-1.16/src/su.c	Wed Oct 21 22:10:51 1998
@@ -502,7 +502,7 @@
    arguments.  */
 
 static void
-run_shell (const char *shell, const char *command, char **additional_args)
+run_shell (struct passwd *pw, const char *shell, const char *command, char **additional_args)
 {
   const char **args;
   int argno = 1;
@@ -513,11 +513,13 @@
 
   retval = pam_open_session(pamh,0);
   if (retval != PAM_SUCCESS) {
+    change_identity(pw);
     fprintf (stderr, "could not open session\n");
     exit (1);
   }
   child = fork();
   if (child == 0) {  /* child shell */
+  change_identity(pw);
   pam_end(pamh, 0);
 #endif
   if (additional_args)
@@ -664,6 +666,7 @@
   char *shell = 0;
   struct passwd *pw;
   struct passwd pw_copy;
+  uid_t old_pw_uid;
 
   program_name = argv[0];
   setlocale (LC_ALL, "");
@@ -774,9 +777,11 @@
     }
   modify_environment (pw, shell);
 
-  change_identity (pw);
+  old_pw_uid=geteuid();
+  seteuid(pw->pw_uid);
   if (simulate_login && chdir (pw->pw_dir))
     error (0, errno, _("warning: cannot change directory to %s"), pw->pw_dir);
+  seteuid(old_pw_uid);
 
-  run_shell (shell, command, additional_args);
+  run_shell (pw, shell, command, additional_args);
 }


Więcej informacji o liście dyskusyjnej pld-devel-pl