New exciting 'list user' functionality!
This commit is contained in:
+4
-1
@@ -36,8 +36,10 @@ EXPORT BOOL MsgAuthVerifyPassword(const char *user, const char *password);
|
||||
EXPORT int MsgAuthChangePassword(const char *user, const char *oldpassword, const char *newpassword);
|
||||
EXPORT int MsgAuthSetPassword(const char *user, const char *password);
|
||||
EXPORT int MsgAuthGetUserStore(const char *user, struct sockaddr_in *store);
|
||||
EXPORT int MsgAuthInitDB(void);
|
||||
EXPORT int MsgAuthInitDB(void);
|
||||
EXPORT int MsgAuthAddUser(const char *user);
|
||||
EXPORT int MsgAuthUserList(char **list[]);
|
||||
EXPORT void MsgAuthUserListFree(char **list[]);
|
||||
|
||||
// Auth / cookie functions
|
||||
|
||||
@@ -123,6 +125,7 @@ int MsgSQLBindString(MsgSQLStatement *stmt, int var, const char *str, BOOL nulli
|
||||
int MsgSQLExecute(MsgSQLHandle *handle, MsgSQLStatement *_stmt);
|
||||
int MsgSQLResults(MsgSQLHandle *handle, MsgSQLStatement *_stmt);
|
||||
void MsgSQLFinalize(MsgSQLStatement *stmt);
|
||||
int MsgSQLStatementStep(MsgSQLHandle *handle, MsgSQLStatement *_stmt);
|
||||
|
||||
|
||||
// Misc. util functions
|
||||
|
||||
+34
-23
@@ -504,7 +504,18 @@ UserAdd(const char *username)
|
||||
void
|
||||
UserList(void)
|
||||
{
|
||||
// TODO
|
||||
char **userlist;
|
||||
int result;
|
||||
|
||||
result = MsgAuthUserList(&userlist);
|
||||
if (result) {
|
||||
int i;
|
||||
|
||||
for (i = 0; userlist[i] != 0; i++) {
|
||||
XplConsolePrintf("%s\n", userlist[i]);
|
||||
}
|
||||
MsgAuthUserListFree(&userlist);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -549,8 +560,8 @@ main(int argc, char *argv[]) {
|
||||
BongoAgent configtool;
|
||||
config.verbose = 0;
|
||||
|
||||
/* this just clears up a warning. we don't need this here */
|
||||
GlobalConfig[0].type = BONGO_JSON_NULL;
|
||||
/* this just clears up a warning. we don't need this here */
|
||||
GlobalConfig[0].type = BONGO_JSON_NULL;
|
||||
|
||||
if (!MemoryManagerOpen("bongo-config")) {
|
||||
XplConsolePrintf("ERROR: Failed to initialize memory manager\n");
|
||||
@@ -643,20 +654,28 @@ main(int argc, char *argv[]) {
|
||||
XplConsolePrintf(_("Couldn't initialise auth subsystem\n"));
|
||||
return 3;
|
||||
}
|
||||
if ((next_arg + 1) >= argc) {
|
||||
XplConsolePrintf(_("USAGE : user [add|password] <username>\n"));
|
||||
if (next_arg >= argc) {
|
||||
XplConsolePrintf(_("USAGE : user [add|password|list] [<username>]\n"));
|
||||
} else {
|
||||
char *command = argv[next_arg++];
|
||||
char *username = argv[next_arg];
|
||||
|
||||
if (! strncmp(command, "add", 3)) {
|
||||
UserAdd(username);
|
||||
} else if (!strncmp(command, "password", 8)) {
|
||||
UserPassword(username);
|
||||
} else if (!strncmp(command, "list", 4)) {
|
||||
if (!strncmp(command, "list", 4)) {
|
||||
UserList();
|
||||
} else {
|
||||
XplConsolePrintf(_("ERROR: Unknown command '%s' on user\n"), command);
|
||||
char *username;
|
||||
if (next_arg >= argc) {
|
||||
XplConsolePrintf(_("USAGE : user %s <username\n"), command);
|
||||
break;
|
||||
}
|
||||
username = argv[next_arg];
|
||||
|
||||
if (! strncmp(command, "add", 3)) {
|
||||
UserAdd(username);
|
||||
} else if (!strncmp(command, "password", 8)) {
|
||||
UserPassword(username);
|
||||
} else {
|
||||
XplConsolePrintf(_("ERROR: Unknown command '%s'\n"), command);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -664,17 +683,9 @@ main(int argc, char *argv[]) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (config.ip) {
|
||||
MemFree(config.ip);
|
||||
}
|
||||
|
||||
if (config.dns) {
|
||||
MemFree(config.dns);
|
||||
}
|
||||
|
||||
if (config.domains) {
|
||||
BongoJsonNodeFree(config.domains);
|
||||
}
|
||||
if (config.ip) MemFree(config.ip);
|
||||
if (config.dns) MemFree(config.dns);
|
||||
if (config.domains) BongoJsonNodeFree(config.domains);
|
||||
|
||||
MemoryManagerClose("bongo-config");
|
||||
exit(0);
|
||||
|
||||
@@ -18,6 +18,7 @@ typedef struct {
|
||||
MsgSQLStatement find_user;
|
||||
MsgSQLStatement auth_user;
|
||||
MsgSQLStatement add_user;
|
||||
MsgSQLStatement list_user;
|
||||
MsgSQLStatement set_password;
|
||||
} MsgAuthStatements;
|
||||
|
||||
@@ -267,18 +268,49 @@ AuthSqlite_GetUserStore(const char *user, struct sockaddr_in *store)
|
||||
}
|
||||
|
||||
int
|
||||
AuthSqlite_UserList(BongoArray **list)
|
||||
AuthSqlite_UserList(char **list[])
|
||||
{
|
||||
/* TODO
|
||||
BongoArray *userlist;
|
||||
char **userlist;
|
||||
MsgSQLStatement *stmt;
|
||||
char path[XPL_MAX_PATH + 1];
|
||||
MsgSQLHandle *handle;
|
||||
int users = 0;
|
||||
int alloc = 10;
|
||||
|
||||
userlist = BongoArrayNew(sizeof (char *), 0);
|
||||
AuthSqlite_GetDbPath(path, XPL_MAX_PATH);
|
||||
handle = MsgSQLOpen(path, NULL, 1000);
|
||||
|
||||
char *admin = strdup("admin");
|
||||
BongoArrayAppendValue(userlist, admin);
|
||||
if (NULL == handle) {
|
||||
Log(LOG_ERROR, "Cannot open user db '%s'", path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
stmt = MsgSQLPrepare (handle, "SELECT username FROM users;",
|
||||
&msgauth_stmts.list_user);
|
||||
if (NULL == stmt) {
|
||||
Log(LOG_ERROR, "Unable to prepare SQL statement in ListUser");
|
||||
return 1;
|
||||
}
|
||||
|
||||
userlist = MemMalloc(sizeof(char *) * alloc);
|
||||
{
|
||||
int result;
|
||||
while (1 == (result = MsgSQLStatementStep(handle, stmt))) {
|
||||
userlist[users] = strdup((char *) sqlite3_column_text(stmt->stmt, 0));
|
||||
users++;
|
||||
if (users == alloc) {
|
||||
alloc += 10;
|
||||
userlist = MemRealloc(userlist, sizeof(char *) * alloc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MsgSQLFinalize(stmt);
|
||||
MsgSQLClose(handle);
|
||||
|
||||
userlist[users] = 0;
|
||||
|
||||
*list = userlist;
|
||||
*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,6 @@ int AuthSqlite_VerifyPassword(const char *user, const char *password);
|
||||
int AuthSqlite_AddUser(const char *user);
|
||||
int AuthSqlite_SetPassword(const char *user, const char *password);
|
||||
int AuthSqlite_GetUserStore(const char *user, struct sockaddr_in *store);
|
||||
int AuthSqlite_UserList(BongoArray **list);
|
||||
int AuthSqlite_UserList(char **list[]);
|
||||
int AuthSqlite_InterfaceVersion(void);
|
||||
int AuthODBC_Init(void);
|
||||
|
||||
@@ -264,8 +264,28 @@ MsgAuthGetUserStore(const char *user, struct sockaddr_in *store)
|
||||
* \return Whether this was successful
|
||||
*/
|
||||
int
|
||||
MsgAuthUserList(BongoArray **list)
|
||||
MsgAuthUserList(char **list[])
|
||||
{
|
||||
return -1;
|
||||
MsgAuthAPIFunction *function;
|
||||
AuthPlugin_UserList *f;
|
||||
int result;
|
||||
|
||||
function = &pluginapi[Func_UserList];
|
||||
if (! function->available) return FALSE;
|
||||
|
||||
f = (AuthPlugin_UserList *)&function->func;
|
||||
result = (*f)(list);
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
MsgAuthUserListFree(char **list[])
|
||||
{
|
||||
char **users = *list;
|
||||
int i;
|
||||
|
||||
for (i = 0; users[i] != 0x0; i++) {
|
||||
MemFree(users[i]);
|
||||
}
|
||||
MemFree(users);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ typedef int (* AuthPlugin_VerifyPassword)(const char *user, const char *password
|
||||
typedef int (* AuthPlugin_AddUser)(const char *user);
|
||||
typedef int (* AuthPlugin_ChangePassword)(const char *user, const char *oldpassword, const char *newpassword);
|
||||
typedef int (* AuthPlugin_SetPassword)(const char *user, const char *password);
|
||||
typedef int (* AuthPlugin_UserList)(char **list[]);
|
||||
typedef int (* AuthPlugin_GetUserStore)(const char *user, struct sockaddr_in *store);
|
||||
typedef int (* AuthPlugin_Install)(void);
|
||||
typedef int (* AuthPlugin_Init)(void);
|
||||
@@ -27,7 +28,7 @@ enum {
|
||||
Func_SetPassword = 6,
|
||||
Func_GetUserStore = 7,
|
||||
Func_Install = 8,
|
||||
Func_Init = 9
|
||||
Func_Init = 9
|
||||
};
|
||||
|
||||
static MsgAuthAPIFunction pluginapi[] = {
|
||||
|
||||
@@ -269,6 +269,30 @@ MsgSQLExecute(MsgSQLHandle *handle, MsgSQLStatement *_stmt)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
MsgSQLStatementStep(MsgSQLHandle *handle, MsgSQLStatement *_stmt)
|
||||
{
|
||||
sqlite3_stmt *stmt = _stmt->stmt;
|
||||
int count = 1 + handle->lockTimeoutMs / MSGSQL_STMT_SLEEP_MS;
|
||||
int dbg;
|
||||
while (count--) {
|
||||
switch ((dbg = sqlite3_step(stmt))) {
|
||||
case SQLITE_ROW:
|
||||
return 1;
|
||||
case SQLITE_DONE:
|
||||
return 0;
|
||||
case SQLITE_BUSY:
|
||||
XplDelay(MSGSQL_STMT_SLEEP_MS);
|
||||
continue;
|
||||
default:
|
||||
XplConsolePrintf("Sql: %s", sqlite3_errmsg(handle->db));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
MsgSQLResults(MsgSQLHandle *handle, MsgSQLStatement *_stmt)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user