Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PAM message capability #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions i3lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ static char password[512];
static bool beep = false;
bool debug_mode = false;
bool unlock_indicator = true;
char pam_message_str[512];
bool show_pam_message = false;
char *modifier_string = NULL;
static bool dont_fork = false;
struct ev_loop *main_loop;
Expand Down Expand Up @@ -691,6 +693,15 @@ static int conv_callback(int num_msg, const struct pam_message **msg,
}

for (int c = 0; c < num_msg; c++) {

memset(pam_message_str, '\0', 512);
strcpy(pam_message_str, msg[c]->msg);
if (strlen(pam_message_str) > 0 && strcmp(pam_message_str, "Password: ") != 0 && msg[c]->msg_style != PAM_PROMPT_ECHO_OFF) {
redraw_screen();
} else {
memset(pam_message_str, '\0', 512);
}

if (msg[c]->msg_style != PAM_PROMPT_ECHO_OFF &&
msg[c]->msg_style != PAM_PROMPT_ECHO_ON)
continue;
Expand Down Expand Up @@ -906,6 +917,7 @@ int main(int argc, char *argv[]) {
{"verify-color", required_argument, NULL, 'o'},
{"wrong-color", required_argument, NULL, 'w'},
{"idle-color", required_argument, NULL, 'l'},
{"pam-messages", no_argument, NULL, 'm'},
{"24", no_argument, NULL, '4'},
{NULL, no_argument, NULL, 0}
};
Expand All @@ -915,7 +927,7 @@ int main(int argc, char *argv[]) {
if ((username = pw->pw_name) == NULL)
errx(EXIT_FAILURE, "pw->pw_name is NULL.\n");

char *optstring = "hvnbdc:o:w:l:p:ui:teI:f";
char *optstring = "hvnbdmc:o:w:l:p:ui:teI:f";
while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {
switch (o) {
case 'v':
Expand Down Expand Up @@ -976,9 +988,12 @@ int main(int argc, char *argv[]) {
case 'f':
show_failed_attempts = true;
break;
case 'm':
show_pam_message = true;
break;
default:
errx(EXIT_FAILURE, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-o color] [-w color] [-l color] [-u] [-p win|default]"
" [-i image.png] [-t] [-e] [-I] [-f] [--24]"
" [-i image.png] [-t] [-e] [-I] [-f] [--24] [-m]"
);
}
}
Expand Down Expand Up @@ -1145,6 +1160,7 @@ int main(int argc, char *argv[]) {

/* Explicitly call the screen redraw in case "locking…" message was displayed */
auth_state = STATE_AUTH_IDLE;
memset(pam_message_str, '\0', 512);
redraw_screen();

struct ev_io *xcb_watcher = calloc(sizeof(struct ev_io), 1);
Expand Down
48 changes: 48 additions & 0 deletions unlock_indicator.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ extern bool show_failed_attempts;
/* Number of failed unlock attempts. */
extern int failed_attempts;

/* Whether to show PAM messages or not. */
extern bool show_pam_message;

/* PAM_conv message. */
extern char pam_message_str[512];

/* PAM_conv message line 2. */
char pam_message_str_2[25];

/*******************************************************************************
* Variables defined in xcb.c.
******************************************************************************/
Expand Down Expand Up @@ -267,6 +276,45 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
cairo_show_text(ctx, timetext);
cairo_close_path(ctx);

if (show_pam_message) {
set_auth_color('l');
cairo_set_font_size(ctx, 10.0);

if (strcmp(pam_message_str, "Password: ") == 0) { // We don't want to show a "Password: " prompt since that is redundant
pam_message_str[0] = '\0'; // Two since we are using UTF-8
pam_message_str[1] = '\0';
}

memset(pam_message_str_2, '\0', 25); // Initialize the second line buffer

if (strlen(pam_message_str) > 24) {
memcpy(pam_message_str_2, &pam_message_str[25], 24);
pam_message_str[25] = '\0';
pam_message_str[26] = '\0';
pam_message_str_2[25] = '\0';
pam_message_str_2[26] = '\0';
}

cairo_text_extents_t pam_extents;
double pam_x, pam_y;
//cairo_select_font_face(ctx, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);

cairo_text_extents(ctx, pam_message_str, &pam_extents);
pam_x = BUTTON_CENTER - ((pam_extents.width / 2) + pam_extents.x_bearing);
pam_y = BUTTON_CENTER - ((pam_extents.height / 2) + pam_extents.y_bearing) + 35;

cairo_move_to(ctx, pam_x, pam_y);
cairo_show_text(ctx, pam_message_str);
if (strlen(pam_message_str_2) != 0) {
cairo_text_extents(ctx, pam_message_str_2, &pam_extents);
pam_x = BUTTON_CENTER - ((pam_extents.width / 2) + pam_extents.x_bearing);
pam_y = BUTTON_CENTER - ((pam_extents.height / 2) + pam_extents.y_bearing) + 45;
cairo_move_to(ctx, pam_x, pam_y);
cairo_show_text(ctx, pam_message_str_2);
}
cairo_close_path(ctx);
}

free(timetext);

if (auth_state == STATE_AUTH_WRONG && (modifier_string != NULL)) {
Expand Down