'Is there a way to pass unicode symbols in the PAM conv function?
I am creating a PAM module to show a QR code to users that are trying to log onto a system over SSH to allow them to scan it and authenticate using biometrics on their phone. Is there a way to pass unicode characters into the PAM conv function to allow the application to display them to the user?
The reason I need to hand in unicode characters is because I want to use the uincode character █ (U+2588 Full Block) as a way to print the QR code to the screen.
I have tried using the type wchar_t to hand in the value and also just trying to hand it in as char but both end up printing the missing character question mark to the screen.
If this is not possible is there a way of being able to show a QR code prior to authentication at all or is regular text the only possible thing to show?
Pam conv struct from PAM source:
struct pam_conv {
int (*conv)(int num_msg, const struct pam_message **msg,
struct pam_response **resp, void *appdata_ptr);
void *appdata_ptr;
};
Edit (31/10/21): I have tried the suggestion of encoding as UTF8 which I beleive is done like so: \u[unicode char code]. This produced the following compiler warning:
src/pam-qr.c:118:58: warning: multi-character character constant [-Wmultichar]
118 | row[x] = qrcodegen_getModule(qrcode, x, y) ? '\u2588' : ' ';
and this output:
\210\210\210\210\210\210\210 \210 \210\210\210 \210\210 \210\210\210\210\210\210\210\214\2723O\177
\210 \210 \210 \210 \210 \210\214\2723O\177
\210 \210\210\210 \210 \210\210 \210 \210\210 \210 \210\210\210 \210\214\2723O\177
\210 \210\210\210 \210 \210 \210 \210\210 \210 \210\210\210 \210\214\2723O\177
\210 \210\210\210 \210 \210\210 \210\210\210 \210 \210\210\210 \210\214\2723O\177
\210 \210 \210 \210 \210\214\2723O\177
\210\210\210\210\210\210\210 \210 \210 \210 \210 \210 \210\210\210\210\210\210\210\214\2723O\177
\210\210\210 \210\210 \214\2723O\177
\210 \210 \210\210\210\210 \210 \210\210 \210\210\210\210\210 \210\214\2723O\177
\210 \210 \210\210 \210 \210\210\210 \210\210 \214\2723O\177
\210\210\210 \210\210 \210\210\210\210\210 \210 \210 \210\210\210 \214\2723O\177
\210\210\210\210\210 \210 \210\210 \210 \210\210 \214\2723O\177
\210\210 \210\210\210 \210\210 \210 \210\210\210\210 \210\210\210\210\214\272
The following is the output I get when using # instead of the block character:
####### # ### ## #######
# # # # # #
# ### # ## # ## # ### #
# ### # # # ## # ### #
# ### # ## ### # ### #
# # # # #
####### # # # # # #######
### ##
# # #### # ## ##### #
# # ## # ### ##
### ## ##### # # ###
##### # ## # ##
## ### ## # #### ####
# ## # # #### ### #
# ## ## ### # ##
#### # ## # # # #
### ## ## # ## ##### #
### # # # ### #
####### # ##### # # #
# # ## # # # #
# ### # # # ## #########
# ### # # ### ## ##
# ### # ## ### # #
# # # ## ### ##
####### ## # ### # # ###
This can't be scanned but the printed version with the block character can be hence why I want to use it. This is the desired output using the block character that I'm trying to achieve:
███████ █ ███ ██ ███████
█ █ █ █ █ █
█ ███ █ ██ █ ██ █ ███ █
█ ███ █ █ █ ██ █ ███ █
█ ███ █ ██ ███ █ ███ █
█ █ █ █ █
███████ █ █ █ █ █ ███████
███ ██
█ █ ████ █ ██ █████ █
█ █ ██ █ ███ ██
███ ██ █████ █ █ ███
█████ █ ██ █ ██
██ ███ ██ █ ████ ████
█ ██ █ █ ████ ███ █
█ ██ ██ ███ █ ██
████ █ ██ █ █ █ █
███ ██ ██ █ ██ █████ █
███ █ █ █ ███ █
███████ █ █████ █ █ █
█ █ ██ █ █ █ █
█ ███ █ █ █ ██ █████████
█ ███ █ █ ███ ██ ██
█ ███ █ ██ ███ █ █
█ █ █ ██ ███ ██
███████ ██ █ ███ █ █ ███
Solution 1:[1]
You can try encoding your Unicode data as UTF-8. That's the most commonly used encoding on Linux, and many programs justifiably refuse to support anything else. Unless you need to emit U+0000, you can use a standard C string to store all your Unicode code points in UTF-8.
However, if your goal is to print the QR code on a terminal, you may end up with problems, since terminal characters are usually not square and there is no standard proportion for them. Thus, it's possible that your QR code won't render acceptably on the terminal and that it will be difficult or impossible to read for the phone. There are programs that do this, so presumably it works in at least some cases, although it may not work everywhere. You may find that libqrencode is useful in your endeavours.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | bk2204 |
