Skip to content

Commit

Permalink
Set PAM_TTY
Browse files Browse the repository at this point in the history
Closes xyb3rt#110
  • Loading branch information
xxc3nsoredxx committed Mar 4, 2021
1 parent 4fbacee commit f8b0bdc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <pwd.h>
#include <signal.h>
#include <security/pam_misc.h>
#include <security/pam_modules.h>

static int oldvt;
static vt_t vt;
Expand Down Expand Up @@ -176,6 +177,12 @@ int main(int argc, char **argv) {
}
vt_secure(&vt);

/* Attempt to set PAM_TTY to the current VT, fixes #110 */
u->pam_status = pam_set_item(u->pamh, PAM_TTY, vt.vt_name);
if (u->pam_status != PAM_SUCCESS) {
error(EXIT_FAILURE, 0, "Unable to set PAM_TTY: %s", pam_strerror(u->pamh, u->pam_status));
}

dup2(vt.fd, 0);
dup2(vt.fd, 1);
dup2(vt.fd, 2);
Expand Down
1 change: 1 addition & 0 deletions physlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef struct vt_s {
int nr;
FILE *ios;
int fd;
char *vt_name;
struct termios term;
struct termios term_orig;
} vt_t;
Expand Down
6 changes: 6 additions & 0 deletions vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void vt_acquire(vt_t *vt) {
vt->nr = -1;
vt->ios = NULL;
vt->fd = -1;
vt->vt_name = NULL;

while ((ret = ioctl(fd, VT_OPENQRY, &vt->nr)) == -1 && errno == EINTR);
if (ret == -1)
Expand All @@ -89,6 +90,7 @@ void vt_acquire(vt_t *vt) {
if (vt->ios == NULL)
error(EXIT_FAILURE, errno, "%s", filename);
vt->fd = fileno(vt->ios);
vt->vt_name = estrdup(filename);

while ((ret = ioctl(fd, VT_ACTIVATE, vt->nr)) == -1 && errno == EINTR);
if (ret == -1)
Expand Down Expand Up @@ -139,6 +141,10 @@ CLEANUP int vt_release(vt_t *vt, int nr) {
}
vt->nr = -1;
}

if (vt->vt_name != NULL) {
free(vt->vt_name);
}
return 0;
}

Expand Down

0 comments on commit f8b0bdc

Please sign in to comment.