diff options
author | Weblate <noreply@weblate.org> | 2017-11-14 00:04:49 +0000 |
---|---|---|
committer | Weblate <noreply@weblate.org> | 2017-11-14 00:04:49 +0000 |
commit | dc40a01ae695b47f87daff7ee08f3519d79b12ae (patch) | |
tree | 6e1d58f23d4537f8f501ba7e531f9ed90f269dda /src-qt5/core/lumina-checkpass/main.c | |
parent | Translated using Weblate (German) (diff) | |
parent | Add a special rule for Ubuntu Linux: (diff) | |
download | lumina-dc40a01ae695b47f87daff7ee08f3519d79b12ae.tar.gz lumina-dc40a01ae695b47f87daff7ee08f3519d79b12ae.tar.bz2 lumina-dc40a01ae695b47f87daff7ee08f3519d79b12ae.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src-qt5/core/lumina-checkpass/main.c')
-rw-r--r-- | src-qt5/core/lumina-checkpass/main.c | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src-qt5/core/lumina-checkpass/main.c b/src-qt5/core/lumina-checkpass/main.c index e12e7c78..2f54c8e6 100644 --- a/src-qt5/core/lumina-checkpass/main.c +++ b/src-qt5/core/lumina-checkpass/main.c @@ -14,23 +14,56 @@ //=========================================== //Standard C libary #include <unistd.h> // Standard C +#include <stdlib.h> #include <stdio.h> // Usage output #include <pwd.h> // User DB information +#include <string.h> //PAM/security libraries #include <sys/types.h> #include <security/pam_appl.h> #include <security/openpam.h> +void showUsage(){ + puts("lumina-checkpass: Simple user-level check for password validity (for screen unlockers and such)."); + puts("Usage:"); + //puts(" lumina-checkpass <password>"); + puts(" lumina-checkpass -fd <file descriptor>"); + puts(" lumina-checkpass -f <file path>"); + puts("Returns: 0 for a valid password, 1 for invalid"); +} + int main(int argc, char** argv){ //Check the inputs - if(argc!=2){ + if(argc!=3){ //Invalid inputs - show the help text - puts("lumina-checkpass: Simple user-level check for password validity (for screen unlockers and such)."); - puts("Usage: lumina-checkpass <password>"); - puts("Returns: 0 for a valid password, 1 for invalid"); + showUsage(); return 1; } + char*pass = 0; + if(argc==3 && 0==strcmp(argv[1],"-fd") ){ + FILE *fp = fdopen(atoi(argv[2]), "r"); + size_t len; + if(fp!=0){ + ssize_t slen = getline(&pass, &len, fp); + if(pass[slen-1]=='\n'){ pass[slen-1] = '\0'; } + } + fclose(fp); + }else if(argc==3 && 0==strcmp(argv[1],"-f") ){ + FILE *fp = fopen(argv[2], "r"); + size_t len; + if(fp!=0){ + ssize_t slen = getline(&pass, &len, fp); + if(pass[slen-1]=='\n'){ pass[slen-1] = '\0'; } + }else{ + puts("[ERROR] Unknown option provided"); + puts("----------------"); + showUsage(); + return 1; + } + fclose(fp); + } + if(pass == 0){ puts("Could not read password!!"); return 1; } //error in reading password //Validate current user (make sure current UID matches the logged-in user, char* cUser = getlogin(); struct passwd *pwd = 0; @@ -44,7 +77,7 @@ int main(int argc, char** argv){ int ret = pam_start( "system", cUser, &pamc, &pamh); if(ret != PAM_SUCCESS){ return 1; } //could not init PAM //char* cPassword = argv[1]; - ret = pam_set_item(pamh, PAM_AUTHTOK, argv[1]); + ret = pam_set_item(pamh, PAM_AUTHTOK, pass); //Authenticate with PAM ret = pam_authenticate(pamh,0); //this can be true without verifying password if pam_self.so is used in the auth procedures (common) if( ret == PAM_SUCCESS ){ ret = pam_acct_mgmt(pamh,0); } //Check for valid, unexpired account and verify access restrictions |