C/C++ API
HSM Dinamo
Loading...
Looking for...
No entries found
user_add_remove.c

Example of creating and removing users.

See Note on examples.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <dinamo.h> /* header do Dinamo */
#define HOST_ADDR "127.0.0.1"
#define USER_ID "master"
#define USER_PWD "12345678"
#ifndef UNUSED
#define UNUSED(x) (void)(x)
#endif
int AAP_API ListUsersCallback(char *szUserName, void * pParam, BOOL bFinal)
{
UNUSED(pParam);
if (!bFinal)
printf("\t%s\n", szUserName);
return 0;
}
int main()
{
int nRet = 0;
struct AUTH_PWD authPwd;
struct USER_INFO userInfo;
HSESSIONCTX hSession = NULL;
char szUser[] = "UserTest";
//Inicializa as bibliotecas do Dinamo
nRet = DInitialize(0);
if (nRet){
printf("Function failure: DInitialize \nError code: %d\n",nRet);
goto clean;
}
printf("Libraries initialized.\n");
//Inicializa a estrutura para conexão com o HSM
strncpy(authPwd.szAddr, HOST_ADDR, sizeof(authPwd.szAddr));
authPwd.nPort = DEFAULT_PORT;
strncpy(authPwd.szUserId, USER_ID, sizeof(authPwd.szUserId));
strncpy(authPwd.szPassword, USER_PWD, sizeof(authPwd.szPassword));
nRet = DOpenSession(&hSession,
(BYTE *)&authPwd,
sizeof(authPwd),
if (nRet){
printf("Function failure: DOpenSession \nError code: %d\n",nRet);
goto clean;
}
//Incializa a estrutura para criação de um novo usuário
strncpy(userInfo.szUserId, szUser, sizeof(userInfo.szUserId));
strncpy(userInfo.szPassword, "12345678", sizeof(userInfo.szPassword));
//Máscara de autorização
//Cria o usuário no HSM
nRet = DCreateUser(hSession, userInfo);
if (nRet){
printf("Function failure: DCreateUser \nError code: %d\n",nRet);
goto clean;
}
//Lista os usuários do HSM
printf("List of users:\n");
nRet = DListUsers(hSession, ListUsersCallback, NULL);
if (nRet){
printf("Function failure: DListUsers \nError code: %d\n",nRet);
goto clean;
}
//Remove o usuário criado
nRet = DRemoveUser(hSession, szUser);
if (nRet){
printf("Function failed: DRemoveUser \nError code: %d\n",nRet);
goto clean;
}
clean:
if (hSession){
DCloseSession(&hSession, 0);
printf("Session closed.\n");
}
printf("Libraries finished.\n");
return nRet;
}
HSM Application Programming Interface (API) Dinamo.
int BOOL
Definition dinamo.h:49
void * HSESSIONCTX
Definition dinamo.h:68
#define DEFAULT_PORT
Definition dinamo.h:1948
unsigned char BYTE
Definition dinamo.h:45
#define ACL_OBJ_UPDATE
Definition dinamo.h:1543
#define AAP_API
Definition dinamo.h:42
#define ENCRYPTED_CONN
Definition dinamo.h:585
#define SS_USER_PWD
Definition dinamo.h:576
#define ACL_OBJ_CREATE
Definition dinamo.h:1542
#define ACL_OBJ_DEL
Definition dinamo.h:1539
#define ACL_OBJ_READ
Definition dinamo.h:1540
int AAP_API DOpenSession(HSESSIONCTX *phSession, DWORD dwParam, BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
int AAP_API DCloseSession(HSESSIONCTX *phSession, DWORD dwFlags)
int AAP_API DInitialize(DWORD dwReserved)
int AAP_API DFinalize()
int AAP_API DRemoveUser(HSESSIONCTX hSession, char *szUserId)
int AAP_API DCreateUser(HSESSIONCTX hSession, struct USER_INFO userInfo)
int AAP_API DListUsers(HSESSIONCTX hSession, funcListUsersCallback fncallback, void *pParam)
Definition dinamo.h:3089
Definition dinamo.h:3167