*** su.c	Sun Aug  6 21:03:57 2000
--- /home/aj/su.c	Sun Aug  6 20:59:11 2000
***************
*** 132,139 ****
  
  #include "error.h"
  
  /* The official name of this program (e.g., no `g' prefix).  */
! #define PROGRAM_NAME "su"
  
  #define AUTHORS "David MacKenzie"
  
--- 132,170 ----
  
  #include "error.h"
  
+ #define USE_GSU_SUID 1
+ 
+ #ifdef USE_GSU_SUID
+ #include <stdarg.h>
+ #include "gsu-suid-api.c"
+ 
+ /* Overlay the error.h library call */
+ extern void error (int status, int errnum, const char *format, ...)
+ {
+ 	va_list args;
+ 
+ 	va_start(args, format);
+ 
+ 	if(status) {
+ 		char msg[GSU_MAX_MESSAGE_LEN];
+ 
+ 		vsnprintf(msg, GSU_MAX_MESSAGE_LEN, format, args);
+ 		gsu_suid_error(msg);
+ 
+ 		va_end(args);
+ 		exit(status);
+ 	}
+ 	
+ 	vfprintf(stdout, format, args);
+ 	if(errno)
+ 		fprintf(stdout, ": %s", strerror(errnum)); 
+ 
+ 	va_end(args);
+ }
+ #endif /* USE_GSU_SUID */
+ 
  /* The official name of this program (e.g., no `g' prefix).  */
! #define PROGRAM_NAME "GNOME-su"
  
  #define AUTHORS "David MacKenzie"
  
***************
*** 269,277 ****
--- 300,313 ----
        struct passwd *pwd = getpwuid (getuid ());
        old_user = (pwd ? pwd->pw_name : "");
      }
+ #ifndef USE_GSU_SUID
    tty = ttyname (2);
    if (tty == NULL)
      tty = "none";
+ # else
+   tty="GNOME-su pipe";
+ # endif
+ 
    /* 4.2BSD openlog doesn't have the third parameter.  */
    openlog (base_name (program_name), 0
  # ifdef LOG_AUTH
***************
*** 316,321 ****
--- 352,362 ----
  static int
  correct_password (const struct passwd *pw)
  {
+ 
+ #ifdef USE_GSU_SUID
+   GSU_PASSWD_STDIN_START
+ #endif
+ 
  #ifdef USE_PAM
    /* root always succeeds; this isn't an authentication question (no
     * extra privs are being granted) so it shouldn't authenticate with PAM.
***************
*** 326,335 ****
--- 367,378 ----
    if (getuid () == 0)
      return 1;
  
+ #ifndef USE_GSU_SUID
    if (!isatty(0)) {
  	fprintf(stderr, "standard in must be a tty\n");
  	exit(1);
    }
+ #endif
  
  
    retval = pam_authenticate(pamh, 0);
***************
*** 369,374 ****
--- 412,421 ----
    memset (unencrypted, 0, strlen (unencrypted));
    return strcmp (encrypted, correct) == 0;
  #endif /* !USE_PAM */
+ 
+ #ifdef USE_GSU_SUID
+   GSU_PASSWD_STDIN_END
+ #endif
  }
  
  /* Update `environ' for the new shell based on PW, with SHELL being
***************
*** 480,487 ****
  
    retval = pam_open_session(pamh,0);
    if (retval != PAM_SUCCESS) {
!     fprintf (stderr, "could not open session\n");
!     exit (1);
    }
  
  /* do this at the last possible moment, because environment variables may
--- 527,533 ----
  
    retval = pam_open_session(pamh,0);
    if (retval != PAM_SUCCESS) {
!     error(1, 0, "could not open session\n");
    }
  
  /* do this at the last possible moment, because environment variables may
***************
*** 642,647 ****
--- 688,697 ----
    char *shell = 0;
    struct passwd *pw;
    struct passwd pw_copy;
+ 
+ #ifdef USE_GSU_SUID
+   gsu_suid_init(&argc, argv);
+ #endif /* USE_GSU_SUID */
  
    program_name = argv[0];
    setlocale (LC_ALL, "");
