#include #include #include #include #include "aitpwd.h" int main() { pwd_root_t ddd, db; char str[256]; int ret = 0; if (cfgLoadPasswd("test.pwd", &db)) { printf("Error #%d - %s\n", pwd_GetErrno(), pwd_GetError()); return 1; } /* unit test find */ // count elements printf("attr=%d Count of array %d w/ NULL \n", ALL, pwd_FindAttribute(db, ALL, NULL)); printf("attr=%d Count of array %d w/o NULL \n", ALL, pwd_FindAttribute(db, ALL, "")); printf("attr=%d Count of array %d\n", ALL, pwd_FindAttribute(db, ALL, "user_l")); // find by attributes printf("attr=%d Count of array %d w/ NULL \n", Username, pwd_FindAttribute(db, Username, NULL)); printf("attr=%d Count of array %d w/o NULL \n", Username, pwd_FindAttribute(db, Username, "")); printf("attr=%d Count of array %d 'user_l' \n", Username, pwd_FindAttribute(db, Username, "user_l")); printf("attr=%d Count of array %d 'a' \n", Username, pwd_FindAttribute(db, Username, "a")); printf("attr=%d Count of array %d 'class4e' \n", Class, pwd_FindAttribute(db, Class, "class4e")); printf("attr=%d Count of array %d 'clas' \n", Class, pwd_FindAttribute(db, Class, "clas")); printf("attr=%d Count of array %d 'ii' \n", Home, pwd_FindAttribute(db, Home, "ii")); printf("attr=%d Count of array %d 'i' \n", Home, pwd_FindAttribute(db, Home, "i")); printf("attr=%d Count of array %d '' \n", Home, pwd_FindAttribute(db, Home, "")); printf("attr=%d Count of array %d NULL \n", Home, pwd_FindAttribute(db, Home, NULL)); /* unit end find */ /* unit test set */ printf("attr=%d set %d NULL\n", ALL, pwd_SetAttribute(&db, ALL, NULL)); printf("attr=%d set %d w/ empty\n", ALL, pwd_SetAttribute(&db, ALL, ddd)); pwdSetValue(&ddd, ALL, "use"); pwdSetValue(&ddd, Password, "alabala"); pwdSetValue(&ddd, UID, "101"); pwdGetValue(ddd, Password, str, 256); printf("attr=%d set %d use getvalue=%s\n", ALL, pwd_SetAttribute(&db, ALL, ddd), str); pwdFreeValue(&ddd, ALL); pwdSetValue(&ddd, ALL, "user_l"); pwdSetValue(&ddd, UID, "999"); pwdSetValue(&ddd, Password, "pliok"); pwdGetValue(ddd, Username, str, 256); printf("attr=%d %s db=%p ddd=%p set %d\n", ALL, str, db, ddd, pwd_SetAttribute(&db, ALL, ddd)); pwdSetValue(&ddd, Username, "use"); pwdSetValue(&ddd, Password, "WC_00"); printf("2.attr=%d %s db=%p ddd=%p set %d\n", Password, str, db, ddd, pwd_SetAttribute(&db, Password, ddd)); printf("get fail.attr=%d %s db=%p ddd=%p set %d\n", Password, str, db, ddd, pwd_GetAttribute(db, Password, ddd)); pwdFreeValue(&ddd, ALL); /* unit end set */ /* unit test get */ pwdSetValue(&ddd, ALL, "user_l"); printf("GET attr=%d %s db=%p ddd=%p set %d\n", Password, ddd->psPass, db, ddd, pwd_GetAttribute(db, Password, ddd)); pwdFreeValue(&ddd, ALL); /* unit end set */ /* unit test unset */ pwdSetValue(&ddd, ALL, "ttt"); printf("attr=%d Count of array %d w/ NULL \n", Username, pwd_FindAttribute(db, Username, ddd->psUser)); printf("UNset attr=%d %s db=%p ddd=%p set %d\n", Class, ddd->psClass, db, ddd, pwd_UnsetAttribute(&db, Class, ddd)); printf("UNset attr=%d %s db=%p ddd=%p set %d\n", Password, ddd->psPass, db, ddd, pwd_UnsetAttribute(&db, Password, ddd)); pwdFreeValue(&ddd, ALL); pwdSetValue(&ddd, ALL, "aa"); printf("UNset attr=%d %s db=%p ddd=%p set %d\n", ALL, ddd->psUser, db, ddd, pwd_UnsetAttribute(&db, ALL, ddd)); pwdFreeValue(&ddd, ALL); /* unit end unset */ printf("ALL el. Count of array %d w/ NULL \n", pwd_FindAttribute(db, ALL, NULL)); WritePasswd(stdout, &db); pwdSetValue(&ddd, ALL, "user_l"); pwdSetValue(&ddd, Password, "000"); switch ((ret = pwd_Authenticate(db, ddd))) { case -1: printf("Error:: #%d - %s\n", pwd_GetErrno(), pwd_GetError()); break; case 0: printf("Access denied!\n"); break; default: printf("Access granted - user found at position %d\n", ret); } pwdFreeValue(&ddd, ALL); if (CreatePasswd("test4e.pwd", &db)) { printf("Error #%d - %s\n", pwd_GetErrno(), pwd_GetError()); return 2; } UnloadPasswd(&db); return 0; }