Annotation of libaitcfg/example/test_pwd.c, revision 1.1.2.4

1.1.2.1   misho       1: #include <stdio.h>
                      2: #include <stdlib.h>
                      3: #include <string.h>
                      4: #include <time.h>
                      5: #include "aitpwd.h"
                      6: 
                      7: 
                      8: int main()
                      9: {
1.1.2.2   misho      10:        pwd_root_t ddd, db;
1.1.2.4 ! misho      11:        struct tagUser *u;
1.1.2.1   misho      12:        char str[256];
                     13:        int ret = 0;
                     14: 
1.1.2.2   misho      15:        if (cfgLoadPasswd("test.pwd", &db)) {
1.1.2.3   misho      16:                printf("Error #%d - %s\n", cfg_GetErrno(), cfg_GetError());
1.1.2.1   misho      17:                return 1;
                     18:        }
                     19: 
                     20:        /* unit test find */
                     21:        // count elements
1.1.2.4 ! misho      22:        u = (const struct tagUser *) cfg_findPasswdBy(&db, PWD_CRIT_UID, 0);
        !            23:        printf("cfg_findPasswdBy %p UID 0 User=%s %u:%u\n", u, AIT_GET_STR(&u->usr_name), 
        !            24:                        AIT_GET_U32(&u->usr_uid), AIT_GET_U32(&u->usr_gid));
        !            25:        u = (const struct tagUser *) cfg_findPasswdBy(&db, PWD_CRIT_UID, 444);
        !            26:        printf("cfg_findPasswdBy %p UID 444 User=%s %u:%u\n", u, AIT_GET_STR(&u->usr_name), 
        !            27:                        AIT_GET_U32(&u->usr_uid), AIT_GET_U32(&u->usr_gid));
        !            28:        /*
1.1.2.1   misho      29:        // find by attributes
1.1.2.4 ! misho      30:        printf("Count of array %d w/ NULL \n", Username, pwd_FindAttribute(db, Username, NULL));
        !            31:        printf("Count of array %d w/o NULL \n", Username, pwd_FindAttribute(db, Username, ""));
        !            32:        printf("Count of array %d 'user_l' \n", Username, pwd_FindAttribute(db, Username, "user_l"));
        !            33:        printf("Count of array %d 'a' \n", Username, pwd_FindAttribute(db, Username, "a"));
        !            34:        printf("Count of array %d 'class4e' \n", Class, pwd_FindAttribute(db, Class, "class4e"));
        !            35:        printf("Count of array %d 'clas' \n", Class, pwd_FindAttribute(db, Class, "clas"));
        !            36:        printf("Count of array %d 'ii' \n", Home, pwd_FindAttribute(db, Home, "ii"));
        !            37:        printf("Count of array %d 'i' \n", Home, pwd_FindAttribute(db, Home, "i"));
        !            38:        printf("Count of array %d '' \n", Home, pwd_FindAttribute(db, Home, ""));
        !            39:        printf("Count of array %d NULL \n", Home, pwd_FindAttribute(db, Home, NULL));
1.1.2.1   misho      40:        /* unit end find */
                     41: 
1.1.2.4 ! misho      42: #if 0
1.1.2.1   misho      43:        /* unit test set */
                     44:        printf("attr=%d set %d NULL\n", ALL, pwd_SetAttribute(&db, ALL, NULL));
                     45:        printf("attr=%d set %d w/ empty\n", ALL, pwd_SetAttribute(&db, ALL, ddd));
                     46:        pwdSetValue(&ddd, ALL, "use");
                     47:        pwdSetValue(&ddd, Password, "alabala");
                     48:        pwdSetValue(&ddd, UID, "101");
                     49:        pwdGetValue(ddd, Password, str, 256);
                     50:        printf("attr=%d set %d use getvalue=%s\n", ALL, pwd_SetAttribute(&db, ALL, ddd), str);
                     51:        pwdFreeValue(&ddd, ALL);
                     52: 
                     53:        pwdSetValue(&ddd, ALL, "user_l");
                     54:        pwdSetValue(&ddd, UID, "999");
                     55:        pwdSetValue(&ddd, Password, "pliok");
                     56:        pwdGetValue(ddd, Username, str, 256);
                     57:        printf("attr=%d %s db=%p ddd=%p set %d\n", ALL, str, db, ddd, pwd_SetAttribute(&db, ALL, ddd));
                     58:        pwdSetValue(&ddd, Username, "use");
                     59:        pwdSetValue(&ddd, Password, "WC_00");
                     60:        printf("2.attr=%d %s db=%p ddd=%p set %d\n", Password, str, db, ddd, pwd_SetAttribute(&db, Password, ddd));
                     61:        printf("get fail.attr=%d %s db=%p ddd=%p set %d\n", Password, str, db, ddd, pwd_GetAttribute(db, Password, ddd));
                     62:        pwdFreeValue(&ddd, ALL);
                     63:        /* unit end set */
                     64:        /* unit test get */
                     65:        pwdSetValue(&ddd, ALL, "user_l");
                     66:        printf("GET attr=%d %s db=%p ddd=%p set %d\n", Password, ddd->psPass, db, ddd, pwd_GetAttribute(db, Password, ddd));
                     67:        pwdFreeValue(&ddd, ALL);
                     68:        /* unit end set */
                     69: 
                     70:        /* unit test unset */
                     71:        pwdSetValue(&ddd, ALL, "ttt");
                     72:        printf("attr=%d Count of array %d w/ NULL \n", Username, pwd_FindAttribute(db, Username, ddd->psUser));
                     73:        printf("UNset attr=%d %s db=%p ddd=%p set %d\n", Class, ddd->psClass, db, ddd, pwd_UnsetAttribute(&db, Class, ddd));
                     74:        printf("UNset attr=%d %s db=%p ddd=%p set %d\n", Password, ddd->psPass, db, ddd, pwd_UnsetAttribute(&db, Password, ddd));
                     75:        pwdFreeValue(&ddd, ALL);
                     76:        pwdSetValue(&ddd, ALL, "aa");
                     77:        printf("UNset attr=%d %s db=%p ddd=%p set %d\n", ALL, ddd->psUser, db, ddd, pwd_UnsetAttribute(&db, ALL, ddd));
                     78:        pwdFreeValue(&ddd, ALL);
                     79:        /* unit end unset */
                     80:        printf("ALL el. Count of array %d w/ NULL \n", pwd_FindAttribute(db, ALL, NULL));
                     81: 
                     82:        WritePasswd(stdout, &db);
                     83: 
                     84:        pwdSetValue(&ddd, ALL, "user_l");
                     85:        pwdSetValue(&ddd, Password, "000");
                     86:        switch ((ret = pwd_Authenticate(db, ddd))) {
                     87:                case -1:
                     88:                        printf("Error:: #%d - %s\n", pwd_GetErrno(), pwd_GetError());
                     89:                        break;
                     90:                case 0:
                     91:                        printf("Access denied!\n");
                     92:                        break;
                     93:                default:
                     94:                        printf("Access granted - user found at position %d\n", ret);
                     95:        }
                     96:        pwdFreeValue(&ddd, ALL);
                     97: 
                     98:        if (CreatePasswd("test4e.pwd", &db)) {
                     99:                printf("Error #%d - %s\n", pwd_GetErrno(), pwd_GetError());
                    100:                return 2;
                    101:        }
1.1.2.3   misho     102: #endif
1.1.2.1   misho     103: 
1.1.2.4 ! misho     104:        cfgUnloadPasswd(&db);
1.1.2.1   misho     105:        return 0;
                    106: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>