- Timestamp:
- Feb 1, 2002, 10:20:07 PM (19 years ago)
- Location:
- trunk/bin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/Makefile
-
Property
svn:keywords
set to
Id LastChangedRevision HeadURL LastChangedDate LastChangedBy
-
Property
svn:keywords
set to
-
trunk/bin/su/Makefile
-
Property
svn:keywords
set to
Id LastChangedRevision HeadURL LastChangedDate LastChangedBy
-
Property
svn:keywords
set to
-
trunk/bin/su/su.c
-
Property
svn:keywords
set to
Id LastChangedRevision HeadURL LastChangedDate LastChangedBy
r15 r16 53 53 usage(void) 54 54 { 55 fprintf(stderr, "Usage: su [login [args]]\n"); 56 exit(1); 55 56 fprintf(stderr, "Usage: su [login [args]]\n"); 57 exit(1); 57 58 } 58 59 … … 60 61 check(const char *func, int pam_err) 61 62 { 62 if (pam_err == PAM_SUCCESS || pam_err == PAM_NEW_AUTHTOK_REQD) 63 return pam_err; 64 openlog("su", LOG_CONS, LOG_AUTH); 65 syslog(LOG_ERR, "%s(): %s", func, pam_strerror(pamh, pam_err)); 66 errx(1, "Sorry."); 63 64 if (pam_err == PAM_SUCCESS || pam_err == PAM_NEW_AUTHTOK_REQD) 65 return pam_err; 66 openlog("su", LOG_CONS, LOG_AUTH); 67 syslog(LOG_ERR, "%s(): %s", func, pam_strerror(pamh, pam_err)); 68 errx(1, "Sorry."); 67 69 } 68 70 … … 70 72 main(int argc, char *argv[]) 71 73 { 72 73 74 char hostname[MAXHOSTNAMELEN]; 75 const char *user, *tty; 74 76 struct passwd *pwd; 75 76 77 int o, status; 78 pid_t pid; 77 79 78 79 80 81 82 83 80 while ((o = getopt(argc, argv, "h")) != -1) 81 switch (o) { 82 case 'h': 83 default: 84 usage(); 85 } 84 86 85 86 87 argc -= optind; 88 argv += optind; 87 89 88 89 90 /* initialize PAM */ 91 pamc.conv = &openpam_ttyconv; 90 92 pam_start("su", argc ? *argv : "root", &pamc, &pamh); 91 93 92 93 94 95 96 97 98 94 /* set some items */ 95 gethostname(hostname, sizeof hostname); 96 check("pam_set_item", pam_set_item(pamh, PAM_RHOST, hostname)); 97 user = getlogin(); 98 check("pam_set_item", pam_set_item(pamh, PAM_RUSER, user)); 99 tty = ttyname(STDERR_FILENO); 100 check("pam_set_item", pam_set_item(pamh, PAM_TTY, tty)); 99 101 100 101 102 103 104 105 106 107 108 109 110 111 102 /* authenticate the applicant */ 103 check("pam_authenticate", pam_authenticate(pamh, 0)); 104 if (check("pam_acct_mgmt", pam_acct_mgmt(pamh, 0)) == 105 PAM_NEW_AUTHTOK_REQD) 106 check("pam_chauthtok", 107 pam_chauthtok(pamh, PAM_CHANGE_EXPIRED_AUTHTOK)); 108 109 /* establish the requested credentials */ 110 check("pam_setcred", pam_setcred(pamh, PAM_ESTABLISH_CRED)); 111 112 /* authentication succeeded; open a session */ 113 check("pam_open_session", pam_open_session(pamh, 0)); 112 114 113 115 if (initgroups(pwd->pw_name, pwd->pw_gid) == -1) … … 115 117 if (setuid(pwd->pw_uid) == -1) 116 118 err(1, "setuid()"); 117 119 118 120 /* XXX export environment variables */ 119 120 switch ((pid = fork())) {121 case -1:122 err(1, "fork()");123 case 0:124 /* child: start a shell */125 *argv = pwd->pw_shell;126 execvp(*argv, argv);127 err(1, "execvp()");128 default:129 /* parent: wait for child to exit */130 waitpid(pid, &status, 0);131 if (WIFEXITED(status))132 status = WEXITSTATUS(status);133 else134 status = 1;135 }136 121 137 /* close the session and release PAM resources */ 138 check("pam_close_session", pam_close_session(pamh, 0)); 139 check("pam_end", pam_end(pamh, 0)); 122 switch ((pid = fork())) { 123 case -1: 124 err(1, "fork()"); 125 case 0: 126 /* child: start a shell */ 127 *argv = pwd->pw_shell; 128 execvp(*argv, argv); 129 err(1, "execvp()"); 130 default: 131 /* parent: wait for child to exit */ 132 waitpid(pid, &status, 0); 133 if (WIFEXITED(status)) 134 status = WEXITSTATUS(status); 135 else 136 status = 1; 137 } 140 138 141 exit(status); 139 /* close the session and release PAM resources */ 140 check("pam_close_session", pam_close_session(pamh, 0)); 141 check("pam_end", pam_end(pamh, 0)); 142 143 exit(status); 142 144 } -
Property
svn:keywords
set to
Note: See TracChangeset
for help on using the changeset viewer.