summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-09-25 00:42:13 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-09-25 00:42:13 +0200
commit1d74b4d24a3863e6ee8c80a208944e539017ebe6 (patch)
treed8884a7dbec51f1bbe1c943e5f21bc2ebee14a3f /database
parent78a4ff98774ef8487080fc4180e8fc77f187c293 (diff)
downloadeurephia-1d74b4d24a3863e6ee8c80a208944e539017ebe6.tar.gz
eurephia-1d74b4d24a3863e6ee8c80a208944e539017ebe6.tar.xz
eurephia-1d74b4d24a3863e6ee8c80a208944e539017ebe6.zip
Fixed some issues with the useracc_list() function
Diffstat (limited to 'database')
-rw-r--r--database/sqlite/administration/useraccount.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/database/sqlite/administration/useraccount.c b/database/sqlite/administration/useraccount.c
index 62000f5..0908a51 100644
--- a/database/sqlite/administration/useraccount.c
+++ b/database/sqlite/administration/useraccount.c
@@ -89,13 +89,13 @@ static inline int xml_set_flag(xmlNode *node, char *flagname, int flagged) {
*/
static xmlDoc *useracc_view(eurephiaCTX *ctx, unsigned int infoType, eDBfieldMap *uinfo_map) {
dbresult *uinf = NULL, *qres = NULL;
- unsigned int flag = 0, uid = 0, i = 0;
+ unsigned int flag = 0, uid = 0, recid = 0;
char *username = NULL;
xmlDoc *doc = NULL;
xmlNode *root_n = NULL, *info_n = NULL;
DEBUG(ctx, 20, "Function call: eDBadminGetUserUserInfo(ctx, %i, {xmlDoc})", infoType);
- assert( (ctx != NULL) && (uinfo_map != NULL) );
+ assert( ctx != NULL );
if( (ctx->context_type != ECTX_ADMIN_CONSOLE) && (ctx->context_type != ECTX_ADMIN_WEB) ) {
eurephia_log(ctx, LOG_CRITICAL, 0,
@@ -126,40 +126,39 @@ static xmlDoc *useracc_view(eurephiaCTX *ctx, unsigned int infoType, eDBfieldMap
eurephia_log(ctx, LOG_ERROR, 0, "Error querying the database for a user");
return 0;
}
- eDBfreeMapping(uinfo_map);
eurephiaXML_CreateDoc(ctx, 1, "UserAccount", &doc, &root_n);
xmlNewProp(root_n, (xmlChar *) "mode", (xmlChar *) "view");
- for( i = 0; i < sqlite_get_numtuples(uinf); i++ ) {
- xmlNode *user_n = xmlNewChild(root_n, NULL, (xmlChar *) "UserAccount", NULL);
+ for( recid = 0; recid < sqlite_get_numtuples(uinf); recid++ ) {
+ xmlNode *user_n = xmlNewChild(root_n, NULL, (xmlChar *) "Account", NULL);
assert( user_n != NULL );
- sqlite_xml_value(user_n, XML_ATTR, "uid", uinf, 0, 4);
- sqlite_xml_value(root_n, XML_NODE, "username", uinf, 0, 0);
+ sqlite_xml_value(user_n, XML_ATTR, "uid", uinf, recid, 4);
+ sqlite_xml_value(user_n, XML_NODE, "username", uinf, recid, 0);
- uid = atoi_nullsafe(sqlite_get_value(uinf, 0, 4));
- username = sqlite_get_value(uinf, 0, 0);
+ uid = atoi_nullsafe(sqlite_get_value(uinf, recid, 4));
+ username = sqlite_get_value(uinf, recid, 0);
if( infoType & USERINFO_user ) {
info_n = xmlNewChild(user_n, NULL, (xmlChar *) "flags", NULL);
assert( info_n != NULL );
// set DEACTIVATED flag, if deactivated field is not NULL
- xml_set_flag(info_n, "DEACTIVATED", (sqlite_get_value(uinf, 0, 2) != NULL));
+ xml_set_flag(info_n, "DEACTIVATED", (sqlite_get_value(uinf, recid, 2) != NULL));
// set BLACKLISTED flag, if username is found in blacklist table
- xml_set_flag(info_n, "BLACKLISTED", (atoi_nullsafe(sqlite_get_value(uinf, 0, 5))==1));
+ xml_set_flag(info_n, "BLACKLISTED", (atoi_nullsafe(sqlite_get_value(uinf, recid, 5))==1));
// set OPENSESSION flag, if user has a lastlog entry with sessionstatus == 2
- xml_set_flag(info_n, "OPENSESSION", (atoi_nullsafe(sqlite_get_value(uinf, 0, 6))==1));
+ xml_set_flag(info_n, "OPENSESSION", (atoi_nullsafe(sqlite_get_value(uinf, recid, 6))==1));
// set ERRATTEMPT flag, if user has an entry in attempts log with attemtps > 0
- xml_set_flag(info_n, "ERRATTEMPT", (atoi_nullsafe(sqlite_get_value(uinf, 0, 8))==1));
+ xml_set_flag(info_n, "ERRATTEMPT", (atoi_nullsafe(sqlite_get_value(uinf, recid, 8))==1));
// set NEVERUSED flag, if login count == 0 and last_accessed == NULL
flag = xml_set_flag(info_n, "NEVERUSED", ((atoi_nullsafe(sqlite_get_value(uinf,0, 7))==0)
- && (sqlite_get_value(uinf, 0, 3) == NULL)));
+ && (sqlite_get_value(uinf, recid, 3) == NULL)));
// set RSETLASTUSED flag, if login count == 0 and last_accessed == NULL
xml_set_flag(info_n, "RSETLASTUSED", !flag && (sqlite_get_value(uinf,0,3)) == NULL);
@@ -168,10 +167,10 @@ static xmlDoc *useracc_view(eurephiaCTX *ctx, unsigned int infoType, eDBfieldMap
xml_set_flag(info_n, "RSETLOGINCNT", ((atoi_nullsafe(sqlite_get_value(uinf,0, 7))==0)
&& (sqlite_get_value(uinf,0,3)) != NULL));
- sqlite_xml_value(user_n, XML_NODE, "activated", uinf, 0, 1);
- sqlite_xml_value(user_n, XML_NODE, "deactivated", uinf, 0, 2);
- info_n = sqlite_xml_value(user_n, XML_NODE, "last_accessed", uinf, 0, 3);
- sqlite_xml_value(user_n, XML_ATTR, "logincount", uinf, 0, 7);
+ sqlite_xml_value(user_n, XML_NODE, "activated", uinf, recid, 1);
+ sqlite_xml_value(user_n, XML_NODE, "deactivated", uinf, recid, 2);
+ info_n = sqlite_xml_value(user_n, XML_NODE, "last_accessed", uinf, recid, 3);
+ sqlite_xml_value(user_n, XML_ATTR, "logincount", uinf, recid, 7);
}
if( infoType & USERINFO_certs ) {
@@ -398,7 +397,6 @@ static xmlDoc *useracc_add(eurephiaCTX *ctx, eDBfieldMap *usrinf_map) {
xmlFreeNode(info_n);
}
sqlite_free_results(res);
- eDBfreeMapping(usrinf_map);
return res_d;
}
@@ -514,34 +512,33 @@ xmlDoc *eDBadminUserAccount(eurephiaCTX *ctx, xmlDoc *qryxml) {
if( (ctx->context_type != ECTX_ADMIN_CONSOLE) && (ctx->context_type != ECTX_ADMIN_WEB) ) {
eurephia_log(ctx, LOG_CRITICAL, 0,
"eurephia admin function call attempted with wrong context type");
- return 0;
+ return NULL;
}
- qry_n = eurephiaXML_getRoot(ctx, qryxml, "admin_access", 1);
+ qry_n = eurephiaXML_getRoot(ctx, qryxml, "UserAccount", 1);
if( qry_n == NULL ) {
- eurephia_log(ctx, LOG_ERROR, 0, "Could not find a valid XML for the user-certs link request");
- return 0;
+ eurephia_log(ctx, LOG_ERROR, 0, "Could not find a valid XML for the user account request");
+ return NULL;
}
mode = xmlGetAttrValue(qry_n->properties, "mode");
if( mode == NULL ) {
- eurephia_log(ctx, LOG_ERROR, 0, "Invalid edit admin access request (1).");
- return 0;
+ eurephia_log(ctx, LOG_ERROR, 0, "Invalid user account request (1).");
+ return NULL;
}
fmap_n = xmlFindNode(qry_n, "fieldMapping");
if( fmap_n == NULL ) {
- eurephia_log(ctx, LOG_ERROR, 0, "Invalid edit admin access request (2).");
- return 0;
+ eurephia_log(ctx, LOG_ERROR, 0, "Invalid user account request (2).");
+ return NULL;
}
+ fmap_m = eDBxmlMapping(ctx, tbl_sqlite_users, NULL, fmap_n);
+ assert(fmap_m != NULL);
// Extract the value of the uid attribute in the UserAccount tag. If not found, set value to -1.
uid = atoi_nullsafe(defaultValue(xmlGetAttrValue(qry_n->properties, "uid"), "-1"));
- fmap_m = eDBxmlMapping(ctx, tbl_sqlite_users, NULL, fmap_n);
- assert(fmap_m != NULL);
-
if( strcmp(mode, "view") == 0 ) {
- unsigned int flags = atoi_nullsafe(defaultValue(xmlGetNodeContent(qry_n,"extractFlag"),"0"));
+ unsigned int flags = atoi_nullsafe(defaultValue(xmlGetNodeContent(qry_n,"extractFlags"),"0"));
res_d = useracc_view(ctx, flags, fmap_m);
} else if( strcmp(mode, "add") == 0 ) {
res_d = useracc_add(ctx, fmap_m);
@@ -622,7 +619,6 @@ xmlDoc *adminacclvl_Get(eurephiaCTX *ctx, eDBfieldMap *fmap) {
tmp_n = sqlite_xml_value(acl_n, XML_NODE, "access", res, i, 3);
sqlite_xml_value(tmp_n, XML_ATTR, "interface", res, i, 2);
}
-
sqlite_free_results(res);
return doc;
}