diff --git a/i3lock.c b/i3lock.c index 55c19c8..d98201c 100644 --- a/i3lock.c +++ b/i3lock.c @@ -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; @@ -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; @@ -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} }; @@ -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': @@ -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]" ); } } @@ -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); diff --git a/unlock_indicator.c b/unlock_indicator.c index 037f73f..7c3bdc4 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -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. ******************************************************************************/ @@ -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)) {