New exciting 'list user' functionality!

This commit is contained in:
alexhudson
2008-01-28 17:45:00 +00:00
parent 81d9301e0d
commit 238fa58cdc
7 changed files with 126 additions and 35 deletions
+39 -7
View File
@@ -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;
}
+1 -1
View File
@@ -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);
+22 -2
View File
@@ -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);
}
+2 -1
View File
@@ -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[] = {
+24
View File
@@ -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)
{