《权限管理接口》主要内容包括:
●用户与组
●信任
●数据库安全
|
|
///*Security Function
#include "hdKingAPI.h" #include "error_code.h" #include <stdio.h> #include <string.h>
int32 main() { int32 nRet = RD_SUCCESS; HD3Connection conn; HD3SecUser secUser; HD3SecGroup secGroup; HD3SecItem secItem; HD3_SC_ITEM_TYPE nSecurityItemType = HD3_SC_ITEM_TYPE_MIN; int32 i = 0;
HD3HANDLE hIter = NULL; const int32 USER_COUNT = 3; const int32 GROUP_COUNT = 3; const int32 TRUST_COUNT = 3;
HD3SecUser *pUser = new HD3SecUser[USER_COUNT]; memset(pUser, 0x00, sizeof(HD3SecUser) * USER_COUNT);
HD3SecGroup *pGroup = new HD3SecGroup[GROUP_COUNT]; memset(pGroup, 0x00, sizeof(HD3SecGroup) * GROUP_COUNT);
HD3SecTrust *pTrust = new HD3SecTrust[TRUST_COUNT]; memset(pTrust, 0x00, sizeof(HD3SecTrust) * TRUST_COUNT);
//connect strcpy(conn.szAddress, "127.0.0.1"); conn.nPort = 5673; conn.nTimeout = 3; nRet = nt3_connect(&conn); if (nRet != RD_SUCCESS) { printf("connect to server failed, error code[%d]!\n", nRet); return -1; } printf("connect to server successful!\n");
//login nRet = sc3_login("admin", "admin"); if (nRet != RD_SUCCESS) { printf("login failed, error code[%d]!\n", nRet); return -1; } printf("login successful!\n");
//add users, modify user desc for (i = 0; i < USER_COUNT; i ++) { sprintf(pUser[i].szUserName, "userName_%d", i); sprintf(pUser[i].szPasswd, "passWord", i); sprintf(pUser[i].szUserDesc, "userDesc_%d", i); nRet = sc3_add_user(&pUser[i]); if (nRet != RD_SUCCESS) { printf("add user[name:%s] failed, error code[%d]!\n", pUser[i].szUserName, nRet); return -1; } printf("add user successful!\n");
//modify user desc sprintf(pUser[i].szUserDesc, "userDescModified_%d", i); nRet = sc3_modify_user_desc(pUser[i].szUserName, pUser[i].szUserDesc); if (nRet != RD_SUCCESS) { printf("modify user[name:%s] desc[%s] failed, error code[%d]!\n", pUser[i].szUserName, pUser[i].szUserDesc, nRet); return -1; } printf("modify user desc successful!\n"); }
//query all user nRet = sc3_query_all_users(&hIter); if (nRet != RD_SUCCESS) { printf("query all user failed, error code [%d]!\n", nRet); nt3_disconnect(); return -1; } while (true) { nRet = ut3_get_item_step(hIter, &secUser); if (RD_SUCCESS == nRet) { printf("query user successful, user name is %s!\n", secUser.szUserName); } else if (EC_HD_API_QUERY_END == nRet) { printf("query user complete!\n"); break; } else { printf("query user failed, error code [%d]!\n", nRet); break; } } ut3_free_handle(hIter);
//add trust trust HD3SecTrust hdSecTrust; for (i = 0; i < TRUST_COUNT; i ++) { sprintf(pTrust[i].szStartIP, "%d.%d.%d.%d", i, i, i, i); sprintf(pTrust[i].szEndIP, "%d.%d.%d.%d", i, i, i, i); sprintf(pTrust[i].szTrustName, "%d.%d.%d.%d", i, i, i, i); strcpy(pTrust[i].szUserName, "admin"); nRet = sc3_add_trust(pTrust + i); if (nRet != RD_SUCCESS) { printf("add trust[name:%s] failed, start ip[%s] end ip[%s] user name[%s], error code[%d]!\n", pTrust[i].szTrustName, pTrust[i].szStartIP, pTrust[i].szEndIP, pTrust[i].szUserName, nRet); return -1; } printf("add trust successful successful!\n"); }
//query all trust nRet = sc3_query_all_trusts(&hIter); if (nRet != RD_SUCCESS) { printf("query all trust failed, error code [%d]!\n", nRet); nt3_disconnect(); return -1; } while (true) { nRet = ut3_get_item_step(hIter, &hdSecTrust); if (RD_SUCCESS == nRet) { printf("query trust successful, trust name[%s] start ip[%s] end ip[%s] user name[%s]!\n", hdSecTrust.szTrustName, hdSecTrust.szStartIP, hdSecTrust.szEndIP, hdSecTrust.szUserName); } else if (EC_HD_API_QUERY_END == nRet) { printf("query trusts complete!\n"); break; } else { printf("query trust failed, error code [%d]!\n", nRet); break; } } ut3_free_handle(hIter);
//add group , modify group desc for (i = 0; i < GROUP_COUNT; i ++) { //add group sprintf(pGroup[i].szGroupName, "groupName_%d", i); sprintf(pGroup[i].szGroupDesc, "groupDesc_%d", i); nRet = sc3_add_group(&pGroup[i]); if (nRet != RD_SUCCESS) { printf("add group[name:%s] failed, error code[%d]!\n", pGroup[i].szGroupName, nRet); return -1; } printf("add group successful!\n");
//modify group desc sprintf(pGroup[i].szGroupDesc, "groupDescModified_%d", i); nRet = sc3_modify_group_desc(pGroup[i].szGroupName, pGroup[i].szGroupDesc); if (nRet != RD_SUCCESS) { printf("modify group[name:%s] desc[%s] failed, error code[%d]!\n", pGroup[i].szGroupName, pGroup[i].szGroupDesc, nRet); return -1; } printf("modify group desc successful!\n"); }
//query all group nRet = sc3_query_all_groups(&hIter); if (nRet != RD_SUCCESS) { printf("query all group failed, error code [%d]!\n", nRet); nt3_disconnect(); return -1; } while (true) { nRet = ut3_get_item_step(hIter, &secGroup); if (RD_SUCCESS == nRet) { printf("query group successful, group name is %s!\n", secGroup.szGroupName); } else if (EC_HD_API_QUERY_END == nRet) { printf("query group complete!\n"); break; } else { printf("query group failed, error code [%d]!\n", nRet); break; } } ut3_free_handle(hIter);
//add users to group for (i = 0; i < USER_COUNT; i ++) { nRet = sc3_add_user_to_group(pUser[i].szUserName, pGroup[i].szGroupName); if (nRet != RD_SUCCESS) { printf("add user to group failed, error code[%d]!\n", nRet); return -1; } printf("add user to group successful!\n"); }
//query all members of group nRet = sc3_query_members_of_group(pGroup[0].szGroupName, &hIter); if (nRet != RD_SUCCESS) { printf("query user of group[name:%s] failed, error code[%d]!\n", pGroup[0].szGroupName, nRet); return -1; }
while (true) { nRet = ut3_get_item_step(hIter, &secUser); if (RD_SUCCESS == nRet) { printf("query user[name:%s] of group[name:%s] succeed!\n", secUser.szUserName, pGroup[0].szGroupName); } else if (EC_HD_API_QUERY_END == nRet) { printf("query member of group[name:%s] complete!\n", pGroup[0].szGroupName); break; } else { printf("query member of group[name:%s] failed, error code[%d]!\n", pGroup[0].szGroupName, nRet); break; } } ut3_free_handle(hIter);
//query all group of user nRet = sc3_query_groups_of_user(pUser[0].szUserName, &hIter); if (nRet != RD_SUCCESS) { printf("query groups of user[name:%s] failed, error code[%d]!\n", pUser[0].szUserName, nRet); return -1; }
while (true) { nRet = ut3_get_item_step(hIter, &secGroup); if (RD_SUCCESS == nRet) { printf("query group[name:%s] of user[name:%s] succeed!\n", secGroup.szGroupName, pUser[0].szUserName); } else if (EC_HD_API_QUERY_END == nRet) { printf("query group of user[name:%s] complete!\n", pUser[0].szUserName); break; } else { printf("query group of user[name:%s] failed, error code[%d]!\n", pUser[0].szUserName, nRet); break; } } ut3_free_handle(hIter);
//query tag manage security nSecurityItemType = HD3_SC_ITEM_TYPE_TAG; nRet = sc3_query_manage_security(nSecurityItemType, &secItem); if (nRet != RD_SUCCESS) { printf("query tag manage security failed, error code[%d]!\n", nRet); nt3_disconnect(); return -1; } printf("query tag security item successfully, own group[name:%s], operate group[name:%s]!\n", secItem.szOwnGroupName, secItem.szOperateGroupName);
//query group manage security nSecurityItemType = HD3_SC_ITEM_TYPE_GROUP; nRet = sc3_query_manage_security(nSecurityItemType, &secItem); if (nRet != RD_SUCCESS) { printf("query group manage security failed, error code[%d]!\n", nRet); nt3_disconnect(); return -1; } printf("query group security item successfully, own group[name:%s], operate group[name:%s]!\n", secItem.szOwnGroupName, secItem.szOperateGroupName);
//modify tag manage security nSecurityItemType = HD3_SC_ITEM_TYPE_TAG; strcpy(secItem.szOwnGroupName, pGroup[0].szGroupName); strcpy(secItem.szOperateGroupName, pGroup[0].szGroupName); secItem.nSecurity = 53; nRet = sc3_modify_manage_security(nSecurityItemType, &secItem); if (nRet != RD_SUCCESS) { printf("modify tag manage security failed, error code[%d]!\n", nRet); nt3_disconnect(); return -1; } printf("modify Tag security item successfully!\n");
//modify group manage security nSecurityItemType = HD3_SC_ITEM_TYPE_GROUP; strcpy(secItem.szOwnGroupName, pGroup[0].szGroupName); strcpy(secItem.szOperateGroupName, pGroup[0].szGroupName); secItem.nSecurity = 53; nRet = sc3_modify_manage_security(nSecurityItemType, &secItem); if (nRet != RD_SUCCESS) { printf("modify group manage security failed, error code[%d]!\n", nRet); nt3_disconnect(); return -1; } printf("modify Group security item successfully!\n");
// delete user from group for (i = 0; i < USER_COUNT; i ++) { nRet = sc3_delete_user_from_group(pUser[i].szUserName, pGroup[i].szGroupName); if (nRet != RD_SUCCESS) { printf("delete user[name:%s] from group[name:%s] failed, error code[%d]!\n", pUser[i].szUserName, pGroup[i].szGroupName, nRet); return -1; } printf("delete user[name:%s] from group[name:%s] successful!\n", pUser[i].szUserName, pGroup[i].szGroupName); }
//delete user for (i = 0; i < USER_COUNT; i ++) { nRet = sc3_delete_user(pUser[i].szUserName); if (nRet != RD_SUCCESS) { printf("delete user[name:%s] failed, error code[%d]!\n", pUser[i].szUserName, nRet); return -1; } printf("delete user[name:%s] successful!\n", pUser[i].szUserName); }
//delete group for (i = 0; i < GROUP_COUNT; i ++) { nRet = sc3_delete_group(pGroup[i].szGroupName); if (nRet != RD_SUCCESS) { printf("delete group[name:%s] failed, error code[%d]!\n", pGroup[i].szGroupName, nRet); return -1; } printf("delete group[name:%s] successful!\n", pGroup[i].szGroupName); }
//delete trust for (i = 0; i < TRUST_COUNT; i ++) { nRet = sc3_delete_trust(pTrust[i].szTrustName); if (nRet != RD_SUCCESS) { printf("delete trust[name:%s] failed, error code[%d]!\n", pTrust[i].szTrustName, nRet); return -1; } printf("delete trust[name:%s] successful!\n", pTrust[i].szTrustName); }
//get current user name char szCurrentUserName[HD3_LEN_USER_NAME]; nRet = sc3_query_current_user_name(HD3_LEN_USER_NAME, szCurrentUserName); if (nRet != RD_SUCCESS) { printf("query current user name failed, error code[%d]!\n", nRet); return -1; } printf("query current user name successful, current uer name :%s!\n", szCurrentUserName);
//modify pass word nRet = sc3_modify_password("admin", "admin", "szNewPassWord"); if (nRet != RD_SUCCESS) { printf("modify user[name:admin] password failed, error code[%d]!\n", nRet); return -1; } printf("modify user[name:admin] password successful!\n");
//reset password nRet = sc3_reset_password("admin", "admin"); if (nRet != RD_SUCCESS) { printf("reset user[name:admin] password failed, error code[%d]!\n", nRet); return -1; } printf("reset user[name:admin] password successful!\n");
//disconnect nt3_disconnect(); return 0; }
//*/ |
©2015. All Rights Reserved.