pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS

Difference between
modified post be52 by Anonymous on Wed 20th Mar 2019 12:52
original post a0d0e8526d by Anonymous on Fri 22nd Feb 2019 10:49
Download diff
Show old version | new version | both versions

    
11
/******************************************************************************
22
* (C) 2019 ECKELMANN AG INDUSTRIEAUTOMATION, WIESBADEN
33
*******************************************************************************
44
*
55
* Author  schenk, ECKELMANN AG
66
* Date    20.02.2019
77
*
88
******************************************************************************/
99
1010
1111
#include <sys/types.h>
1212
#include <pwd.h>
1313
#include <shadow.h>
1414
#include <crypt.h>
1515
#include <string.h>
1616
#include <stdio.h>
1717
1818
#define ERR_NO_ERROR 0
1919
#define ERR_PASSWORD_MISMATCH 1
2020
#define ERR_USER_DOES_NOT_EXIST 2
2121
#define ERR_NO_PERMISSION 3
2222
#define ERR_UNKNOWN 4
2323
2424
2525
int system_authentificate_user (const char*username, const char*password)
2626
{
2727
    struct passwd*pw;
2828
    struct spwd*sp;
2929
    char*encrypted, *theGoodHash;
3030
    int result=ERR_UNKNOWN;
3131
3232
    pw = getpwnam (username);
3333
    endpwent();
3434
3535
    if (!pw) return ERR_USER_DOES_NOT_EXIST;
3636
3737
    sp = getspnam (pw->pw_name);
3838
    endspent();
3939
    if (sp)
4040
        theGoodHash = sp->sp_pwdp;
4141
    else
4242
        theGoodHash = pw->pw_passwd;
4343
4444
    if (NULL == theGoodHash){
4545
        return ERR_NO_PERMISSION;
4646
    }
4747
4848
    encrypted = crypt (password, theGoodHash);
4949
5050
    if( 0 == strcmp (encrypted, theGoodHash)){
5151
        result = ERR_NO_ERROR;
5252
    }
5353
    else{
5454
        result = ERR_PASSWORD_MISMATCH;
5555
    }
5656
    return result;
5757
}
5858
5959
6060
int main(int argc, char *argv[])
6161
{
6262
    int result;
6363
6464
    if( argc < 3){
6565
        printf("prog <USER> <PASSWORD>\n");
6666
        return 3;
6767
    }
6868
6969
    const char* user= argv[1];
7070
    const char* pw= argv[2];
7171
7272
    result = system_authentificate_user( user, pw);
7373
7474
    if( result == ERR_NO_ERROR ){
7575
        printf("password for %s ist valid.\n", user);
7676
    }
7777
7878
    if( result == ERR_PASSWORD_MISMATCH){
7979
        printf("password for %s ist invalid.\n", user);
8080
    }
8181
8282
    if( result > ERR_PASSWORD_MISMATCH ){
8383
        printf("Error authentificate user %s.\n", user);
8484
    }
8585
8686
    return result;
8787
8888
}
8989

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at