2
3
4
5
6
7
8
12#include <security/pam_appl.h>
13#include <security/pam_misc.h>
21#include <sys/resource.h>
28#ifdef __USE_GNU_GETTEXT
30#define _(String) gettext(String)
31#define gettext_noop(String) String
32#define N_(String) gettext_noop(String)
34#define _(String) (String)
35#define N_(String) String
36#define textdomain(Domain)
37#define bindtextdomain(Package, Directory)
40#define HOST "localhost"
52static struct pam_conv conv = {
58
59
60
61
62
63
64void ABEND(
int e,
char const *);
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88int main(
int argc,
char **argv) {
90 char exec_cmd[
MAXLEN] =
"/usr/bin/bash";
93 bool ssh_login =
false;
98 pam_handle_t *pamh = NULL;
100 char *username = getenv(
"USER");
101 if (username == NULL) {
102 syslog(LOG_ERR,
"USER environment variable not set");
103 fprintf(stderr,
"Error: USER environment variable not set\n");
106 retval = pam_start(
"rsh-auth", username, &conv, &pamh);
107 if (retval != PAM_SUCCESS) {
108 syslog(LOG_ERR,
_(
"PAM start failed: %s"), pam_strerror(pamh, retval));
109 fprintf(stderr,
_(
"PAM start failed: %s\n"), pam_strerror(pamh, retval));
122 retval = pam_authenticate(pamh, 0);
123 if (retval == PAM_SUCCESS) {
124 syslog(LOG_AUTH,
_(
"Authentication succeeded for user '%s': %s"), username, pam_strerror(pamh, retval));
126 syslog(LOG_AUTH,
_(
"Authentication failed for user '%s': %s"), username, pam_strerror(pamh, retval));
127 fprintf(stderr,
_(
"Failure: Authentication failed: %s\n"), pam_strerror(pamh, retval));
131 pam_end(pamh, retval);
133 if (retval != PAM_SUCCESS) {
134 fprintf(stderr,
_(
"PAM authentication failed: %s\n"), pam_strerror(pamh, retval));
139 if ((p = getenv(
"SHELL")))
140 strncpy(exec_cmd, p,
MAXLEN - 1);
141 cargv[0] = strdup(exec_cmd);
144 for (
int i = 1; i < argc; i++) {
145 if (strcmp(argv[i],
"-i") == 0) {
146 cargv[c++] = strdup(
"-i");
147 }
else if (strcmp(argv[i],
"-D1") == 0 && ssh_login) {
148 fprintf(stderr,
_(
"SSH authentication succeeded\n"));
150 cargv[c++] = strdup(argv[i]);
161 if (argv[0] && strstr(argv[0],
"rsh")) {
162 if (setuid(0) || setgid(0))
163 ABEND(EXIT_FAILURE
, _(
"setuid(0) fatal error"));
165 getrlimit(RLIMIT_FSIZE, &rl);
166 rl.rlim_cur = RLIM_INFINITY;
167 rl.rlim_max = RLIM_INFINITY;
168 setrlimit(RLIMIT_FSIZE, &rl);
170 execvp(exec_cmd, cargv);
171 ABEND(EXIT_FAILURE
, _(
"execvp() fatal error"));
174 waitpid(pid, &status, 0);
175 for (
int i = 0; i < c; i++)
178 if (WIFEXITED(status)) {
179 rc = WEXITSTATUS(status);
181 ABEND(rc, _(
"Child process exited"));
183 if (WIFSIGNALED(status)) {
184 rc = WTERMSIG(status);
185 ABEND(rc, _(
"Child process terminated by signal"));
187 ABEND(EXIT_FAILURE, _(
"Child process terminated abnormally"));
196 fprintf(stderr,
"%s: %d %s\n", s, e, strerror(e));
void ABEND(int)
The ABEND function is a signal handler that is called when the program receives certain signals (e....
int main(int argc, char **argv)
Capture the current terminal settings for later restoration.