*** su.c	Sun Jul 30 17:30:55 2000
--- gsu-suid.c	Sun Jul 30 17:46:57 2000
***************
*** 32,37 ****
--- 32,44 ----
   * consistency -- Ben Collins
   */
  
+ #define USE_GSU_SUID 1
+ 
+ #ifdef USE_GSU_SUID
+ #include "gsu-suid-api.h"
+ #endif /* USE_GSU_SUID */
+ 
  #include <config.h>
  
  #include "rcsid.h"
***************
*** 213,220 ****
--- 220,232 ----
        args[argno++] = *additional_args;
    args[argno] = NULL;
    execv (shell, (char **) args);
+ #ifndef USE_GSU_SUID
    fprintf (stderr, _("No shell\n"));
+ #else /* USE_GSU_SUID */
+   gsu_suid_error(_("No shell"));
+ #endif /* USE_GSU_SUID */
    SYSLOG((LOG_WARN, "Cannot execute %s\n", shell));
+ 
  }
  
  
***************
*** 230,236 ****
--- 242,252 ----
  			name[0] ? name:"???"));
  	closelog();
  #endif
+ #ifndef USE_GSU_SUID
  	puts(_("Sorry."));
+ #else /* USE_GSU_SUID */
+ 	gsu_suid_error(_("Sorry."));
+ #endif /* USE_GSU_SUID */
  	exit(1);
  }
  
***************
*** 274,279 ****
--- 290,299 ----
  #endif
  #endif /* !USE_PAM */
  
+ #ifdef USE_GSU_SUID
+ 	gsu_suid_init(&argc, argv); /* Does not use env */
+ #endif /* USE_GSU_SUID */
+ 
  	/* sanitize_env(); */
  
  	setlocale(LC_ALL, "");
***************
*** 287,295 ****
--- 307,323 ----
  	 * prefix to most error messages.
  	 */
  
+ #ifndef USE_GSU_SUID
  	Prog = Basename(argv[0]);
+ #else /* USE_GSU_SUID */
+ 	Prog = "GNOME-su";
+ #endif /* USE_GSU_SUID */
  
+ #ifndef USE_GSU_SUID
  	openlog("su", LOG_PID|LOG_CONS|LOG_NOWAIT, LOG_AUTH);
+ #else /* USE_GSU_SUID */
+ 	openlog("gsu-suid", LOG_PID|LOG_CONS|LOG_NOWAIT, LOG_AUTH);
+ #endif /* USE_GSU_SUID */
  
  	initenv();
  
***************
*** 302,307 ****
--- 330,336 ----
  	 * current terminal.
  	 */
  
+ #ifndef USE_GSU_SUID
  	if (isatty(0) && (cp = ttyname(0))) {
  		if (strncmp (cp, "/dev/", 5) == 0)
  			tty = cp + 5;
***************
*** 321,326 ****
--- 350,358 ----
  		}
  		tty = "???";
  	}
+ #else
+ 	tty = "GNOME-su pipe";
+ #endif /* ! USE_GSU_SUID */
  
  	/*
  	 * Process the command line arguments. 
***************
*** 419,426 ****
  #else  /* USE_PAM */
  	ret = pam_start("su", name, &conv, &pamh);
  	if (ret != PAM_SUCCESS) {
! 		SYSLOG((LOG_ERR, "pam_start: error %d\n", ret);
! 		fprintf(stderr, _("%s: pam_start: error %d\n"), Prog, ret));
  		exit(1);
  	}
  
--- 451,462 ----
  #else  /* USE_PAM */
  	ret = pam_start("su", name, &conv, &pamh);
  	if (ret != PAM_SUCCESS) {
! 		SYSLOG((LOG_ERR, "pam_start: error %d\n", ret));
! #ifndef USE_GSU_SUID
! 		fprintf(stderr, _("%s: pam_start: error %d\n"), Prog, ret);
! #else
! 		gsu_suid_error(_("%s: pam_start: error %d"), Prog, ret);
! #endif /* USE_GSU_SUID */
  		exit(1);
  	}
  
***************
*** 429,435 ****
--- 465,475 ----
  		ret = pam_set_item(pamh, PAM_RUSER, (const void *) oldname);
  	if (ret != PAM_SUCCESS) {
  		SYSLOG((LOG_ERR, "pam_set_item: %s\n", PAM_STRERROR(pamh, ret)));
+ #ifndef USE_GSU_SUID
  		fprintf(stderr, "%s: %s\n", Prog, PAM_STRERROR(pamh, ret));
+ #else /* USE_GSU_SUID */
+ 		gsu_suid_error("%s: %s", Prog, PAM_STRERROR(pamh, ret));
+ #endif /* USE_GSU_SUID */
  		pam_end(pamh, ret);
  		exit(1);
  	}
***************
*** 446,452 ****
--- 486,496 ----
  	 */
  
  	if (!(pw = getpwnam(name))) {
+ #ifndef USE_GSU_SUID
  		(void) fprintf (stderr, _("Unknown id: %s\n"), name);
+ #else /* USE_GSU_SUID */
+ 		gsu_suid_error(_("Unknown id: %s"), name);
+ #endif /* USE_GSU_SUID */
  		closelog();
  		exit(1);
  	}
***************
*** 481,487 ****
--- 525,535 ----
  	if (!amroot) {
  		if (pwent.pw_uid == 0 && getdef_bool("SU_WHEEL_ONLY")
  		    && !iswheel(oldname)) {
+ #ifndef USE_GSU_SUID
  			fprintf(stderr, _("You are not authorized to su %s\n"), name);
+ #else /* USE_GSU_SUID */
+ 			gsu_suid_error(_("You are not authorized to su %s"), name);
+ #endif /* USE_GSU_SUID */
  			exit(1);
  		}
  #ifdef SU_ACCESS
***************
*** 496,502 ****
--- 544,554 ----
  			pwent.pw_passwd = oldpass;
  			break;
  		default:  /* access denied (-1) or unexpected value */
+ #ifndef USE_GSU_SUID
  			fprintf(stderr, _("You are not authorized to su %s\n"), name);
+ #else /* USE_GSU_SUID */
+ 			gsu_suid_error(_("You are not authorized to su %s"), name);
+ #endif /* USE_GSU_SUID */
  			exit(1);
  		}
  #endif  /* SU_ACCESS */
***************
*** 518,529 ****
--- 570,589 ----
  		shell = (char *) strdup (pwent.pw_shell);
  
  	signal(SIGINT, SIG_IGN);
+ 
+ #ifdef USE_GSU_SUID
+ 	GSU_PASSWD_STDIN_START
+ #endif
  #ifdef USE_PAM
  	ret = pam_authenticate(pamh, 0);
  	if (ret != PAM_SUCCESS) {
  		SYSLOG((LOG_ERR, "pam_authenticate: %s\n",
  			PAM_STRERROR(pamh, ret)));
+ #ifndef USE_GSU_SUID
  		fprintf(stderr, "%s: %s\n", Prog, PAM_STRERROR(pamh, ret));
+ #else /* USE_GSU_SUID */
+ 		gsu_suid_error("%s: %s", Prog, PAM_STRERROR(pamh, ret));
+ #endif /* USE_GSU_SUID */
  		pam_end(pamh, ret);
  		su_failure(tty);
  	}
***************
*** 540,546 ****
  			su_failure(tty);
  		}
  	}
! 	ret = pam_get_item(pamh, PAM_USER, &name);
  	if (ret != PAM_SUCCESS) {
  		SYSLOG((LOG_ERR, "pam_get_item: internal PAM error\n"));
  		fprintf(stderr, "%s: Internal PAM error retrieving username\n");
--- 600,606 ----
  			su_failure(tty);
  		}
  	}
! 	ret = pam_get_item(pamh, PAM_USER, (void *)&name);
  	if (ret != PAM_SUCCESS) {
  		SYSLOG((LOG_ERR, "pam_get_item: internal PAM error\n"));
  		fprintf(stderr, "%s: Internal PAM error retrieving username\n");
***************
*** 612,617 ****
--- 672,680 ----
  		}
  	}
  #endif  /* !USE_PAM */
+ #ifdef USE_GSU_SUID
+ 	GSU_PASSWD_STDIN_END
+ #endif
  
  	signal(SIGINT, SIG_DFL);
  	cp = getdef_str(pwent.pw_uid == 0 ? "ENV_SUPATH" : "ENV_PATH");
***************
*** 658,664 ****
--- 721,731 ----
  	ret = pam_setcred(pamh, PAM_ESTABLISH_CRED);
  	if (ret != PAM_SUCCESS) {
  		SYSLOG((LOG_ERR, "pam_setcred: %s\n", PAM_STRERROR(pamh, ret)));
+ #ifndef USE_GSU_SUID
  		fprintf(stderr, "%s: %s\n", Prog, PAM_STRERROR(pamh, ret));
+ #else /* USE_GSU_SUID */
+ 		gsu_suid_error("%s: %s", Prog, PAM_STRERROR(pamh, ret));
+ #endif /* USE_GSU_SUID */
  		pam_end(pamh, ret);
  		exit(1);
  	}
