--- libaitcfg/example/test_pwd.c 2012/09/19 11:53:52 1.1.2.3 +++ libaitcfg/example/test_pwd.c 2012/09/19 12:35:10 1.1.2.7 @@ -8,6 +8,7 @@ int main() { pwd_root_t ddd, db; + struct tagUser *u; char str[256]; int ret = 0; @@ -16,25 +17,63 @@ int main() return 1; } -#if 0 /* 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 */ + u = (struct tagUser *) cfg_findPasswdBy(&db, PWD_CRIT_UID, 0); + printf("cfg_findPasswdBy %p UID 0 User=%s %u:%u\n", u, AIT_GET_STR(&u->usr_name), + AIT_GET_U32(&u->usr_uid), AIT_GET_U32(&u->usr_gid)); + u = (struct tagUser *) cfg_findPasswdBy(&db, PWD_CRIT_UID, 444); + printf("cfg_findPasswdBy %p UID 444 User=%s %u:%u\n", u, AIT_GET_STR(&u->usr_name), + AIT_GET_U32(&u->usr_uid), AIT_GET_U32(&u->usr_gid)); + u = (struct tagUser *) cfg_findPasswdBy(&db, PWD_CRIT_UID, 99999); + printf("cfg_findPasswdBy %p UID 99999\n", u); + u = (struct tagUser *) cfg_findPasswdBy(&db, PWD_CRIT_GID, 0); + printf("cfg_findPasswdBy %p GID 0 User=%s %u:%u\n", u, AIT_GET_STR(&u->usr_name), + AIT_GET_U32(&u->usr_uid), AIT_GET_U32(&u->usr_gid)); + u = (struct tagUser *) cfg_findPasswdBy(&db, PWD_CRIT_GID, 20); + printf("cfg_findPasswdBy %p GID 20 User=%s %u:%u\n", u, AIT_GET_STR(&u->usr_name), + AIT_GET_U32(&u->usr_uid), AIT_GET_U32(&u->usr_gid)); + u = (struct tagUser *) cfg_findPasswdBy(&db, PWD_CRIT_GID, 99999); + printf("cfg_findPasswdBy %p GID 99999\n", u); + + u = (struct tagUser *) cfg_findPasswdBy(&db, PWD_CRIT_NAME, "user_l"); + printf("cfg_findPasswdBy %p NAME user_l User=%s %u:%u\n", u, AIT_GET_STR(&u->usr_name), + AIT_GET_U32(&u->usr_uid), AIT_GET_U32(&u->usr_gid)); + u = (struct tagUser *) cfg_findPasswdBy(&db, PWD_CRIT_NAME, "aa"); + printf("cfg_findPasswdBy %p NAME aa User=%s %u:%u\n", u, AIT_GET_STR(&u->usr_name), + AIT_GET_U32(&u->usr_uid), AIT_GET_U32(&u->usr_gid)); + u = (struct tagUser *) cfg_findPasswdBy(&db, PWD_CRIT_NAME, NULL); + printf("cfg_findPasswdBy %p NAME NULL\n", u); + u = (struct tagUser *) cfg_findPasswdBy(&db, PWD_CRIT_NAME, ""); + printf("cfg_findPasswdBy %p NAME \"\"\n", u); + + /* get */ + u = (struct tagUser *) cfg_getPasswd(&db, PWD_CRIT_UID, 0); + printf("cfg_getPasswd %p UID 0 User=%s %u:%u\n", u, AIT_GET_STR(&u->usr_name), + AIT_GET_U32(&u->usr_uid), AIT_GET_U32(&u->usr_gid)); + u = (struct tagUser *) cfg_getPasswd(&db, PWD_CRIT_UID, 444); + printf("cfg_getPasswd %p UID 444 User=%s %u:%u\n", u, AIT_GET_STR(&u->usr_name), + AIT_GET_U32(&u->usr_uid), AIT_GET_U32(&u->usr_gid)); + u = (struct tagUser *) cfg_getPasswd(&db, PWD_CRIT_UID, 99999); + printf("cfg_getPasswd %p UID 99999\n", u); + + u = (struct tagUser *) cfg_getPasswd(&db, PWD_CRIT_NAME, "user_l"); + printf("cfg_getPasswd %p NAME user_l User=%s %u:%u\n", u, AIT_GET_STR(&u->usr_name), + AIT_GET_U32(&u->usr_uid), AIT_GET_U32(&u->usr_gid)); + u = (struct tagUser *) cfg_getPasswd(&db, PWD_CRIT_NAME, "aa"); + printf("cfg_getPasswd %p NAME aa User=%s %u:%u\n", u, AIT_GET_STR(&u->usr_name), + AIT_GET_U32(&u->usr_uid), AIT_GET_U32(&u->usr_gid)); + u = (struct tagUser *) cfg_getPasswd(&db, PWD_CRIT_NAME, NULL); + printf("cfg_getPasswd %p NAME NULL\n", u); + u = (struct tagUser *) cfg_getPasswd(&db, PWD_CRIT_NAME, ""); + printf("cfg_getPasswd %p NAME \"\"\n", u); + + printf("cfg_setPasswd %p\n", cfg_setPasswd(&db, 3, "use", "alabala", 101, 0, + NULL, 0, 0, NULL, NULL, NULL)); + printf("cfg_setPasswd %p\n", cfg_setPasswd(&db, 4, "use", "alabala", 101, 0, + NULL, 0, 0, NULL, NULL, NULL)); + +#if 0 /* 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)); @@ -96,6 +135,6 @@ int main() } #endif - UnloadPasswd(&db); + cfgUnloadPasswd(&db); return 0; }