From: Art Cancro Date: Tue, 18 Aug 1998 03:53:02 +0000 (+0000) Subject: * Implemented a bunch of user account related functions in the X-Git-Tag: v7.86~8390 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=318aa2adec10d6291ca684f3362c70ab89796cc3;p=citadel.git * Implemented a bunch of user account related functions in the CitadelAPI library. --- diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 1fc3c5dd9..e1de90c51 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,3 +1,7 @@ +Mon Aug 17 23:52:13 EDT 1998 Art Cancro + * Implemented a bunch of user account related functions in the + CitadelAPI library. + Mon Aug 17 20:01:18 EDT 1998 Art Cancro * Fixed the crash problem. It wasn't AGUP/ASUP, but rather a buffer overrun in getuser() (thanks, Nathan). Implemented overrun checks diff --git a/citadel/citadelapi.c b/citadel/citadelapi.c index 68bd7f580..4ada1e108 100644 --- a/citadel/citadelapi.c +++ b/citadel/citadelapi.c @@ -7,6 +7,13 @@ #include #include "citadel.h" + +struct CtdlInternalList { + struct CtdlInternalList *next; + char data[256]; + }; + + struct CtdlServerHandle CtdlAppHandle; struct CtdlServInfo CtdlAppServInfo; int CtdlErrno = 0; @@ -17,6 +24,91 @@ void logoff(exitcode) { exit(exitcode); } + + +/* + * CtdlInternalNumParms() - discover number of parameters... + */ +int CtdlInternalNumParms(char *source) +{ + int a; + int count = 1; + + for (a=0; a= n) { + strcpy(dest,""); + return; + } + strcpy(buf,source); + if ( (parmnum == 0) && (n == 1) ) { + strcpy(dest,buf); + for (n=0; n0) && (buf[0]!='|') ); + if (buf[0]=='|') strcpy(buf,&buf[1]); + for (count = 0; count 6) ) { + return(ERROR + ILLEGAL_VALUE); + } + + sprintf(buf, "%d", NewValue); + CtdlErrno = CtdlInternalGetUserParam(buf, 5, WhichUser); + return(CtdlErrno); + } + +long CtdlGetUserNumber(char *WhichUser) { + char buf[256]; + CtdlErrno = CtdlInternalGetUserParam(buf, 6, WhichUser); + return((CtdlErrno == 0) ? atol(buf) : (-1L)); + } + +int CtdlSetUserNumber(long NewValue, char *WhichUser) { + char buf[256]; + sprintf(buf, "%ld", NewValue); + CtdlErrno = CtdlInternalGetUserParam(buf, 6, WhichUser); + return(CtdlErrno); + } + +time_t CtdlGetUserLastCall(char *WhichUser) { + char buf[256]; + CtdlErrno = CtdlInternalGetUserParam(buf, 7, WhichUser); + return((CtdlErrno == 0) ? atol(buf) : (time_t)(-1L)); + } + +int CtdlSetUserLastCall(time_t NewValue, char *WhichUser) { + char buf[256]; + sprintf(buf, "%ld", NewValue); + CtdlErrno = CtdlInternalGetUserParam(buf, 7, WhichUser); + return(CtdlErrno); + } + +int CtdlForEachUser(int (*CallBack)(char *EachUser)) { + struct CtdlInternalList *TheList = NULL; + struct CtdlInternalList *ptr; + char buf[256]; + + serv_puts("LIST"); + serv_gets(buf); + if (buf[0] != '1') return(-1); + + while (serv_gets(buf), strcmp(buf, "000")) { + ptr = (struct CtdlInternalList *) + malloc(sizeof (struct CtdlInternalList)); + if (ptr != NULL) { + CtdlInternalExtract(ptr->data, buf, 0); + ptr->next = TheList; + TheList = ptr; + } + } + + while (TheList != NULL) { + (*CallBack)(TheList->data); + ptr = TheList->next; + free(TheList); + TheList = ptr; + } + + return(0); + } diff --git a/citadel/ipcdef.h b/citadel/ipcdef.h index c7bbcc67e..808d2143a 100644 --- a/citadel/ipcdef.h +++ b/citadel/ipcdef.h @@ -13,6 +13,7 @@ #define INTERNAL_ERROR 10 #define TOO_BIG 11 +#define ILLEGAL_VALUE 12 #define NOT_LOGGED_IN 20 #define CMD_NOT_SUPPORTED 30 #define PASSWORD_REQUIRED 40 diff --git a/citadel/techdoc/api.txt b/citadel/techdoc/api.txt index 421c06f3d..bde1492d8 100644 --- a/citadel/techdoc/api.txt +++ b/citadel/techdoc/api.txt @@ -68,3 +68,67 @@ to facilitate a consistent development experience. int CtdlSendExpressMessage(char *ToUser, char *MsgText) This function sends an express message (page) to the named user. + + + + USER ACCOUNT FUNCTIONS + ---------------------- + The user account functions require administrative or privileged access. They +return -1 in the event of an error. + + + + int CtdlGetUserPassword(char *buf, char *WhichUser) + int CtdlSetUserPassword(char *buf, char *WhichUser) + + Get or set the password for a user account. + + + unsigned int CtdlGetUserFlags(char *WhichUser) + int CtdlSetUserFlags(unsigned int NewFlags, char *WhichUser) + + Get or set the various bits associated with a user account. Be careful with +these flags; it is possible to corrupt a user account by handling them the +wrong way. It is best to call CtdlGetUserFlags() to acquire the current set +of flags, then twiddle the bits you're interested in, then call +CtdlSetUserFlags() to write them back. + + + int CtdlGetUserTimesCalled(char *WhichUser) + int CtdlSetUserTimesCalled(unsigned int NewValue, char *WhichUser) + + Get or set the "number of times called" value for a user. + + + int CtdlGetUserMessagesPosted(char *WhichUser) + int CtdlSetUserMessagesPosted(unsigned int NewValue, char *WhichUser) + + Get or set the "number of messages posted" value for a user. + + + int CtdlGetUserAccessLevel(char *WhichUser) + int CtdlSetUserAccessLevel(unsigned int NewValue, char *WhichUser) + + Get or set a user's access level. + + + long CtdlGetUserNumber(char *WhichUser) + int CtdlSetUserNumber(long NewValue, char *WhichUser) + + Get or set the user number, In general there is never any reason to change +a user's number. If for some reason you need to do this, be sure not to use +a user number which already exists, or which has not yet been assigned. + + + time_t CtdlGetUserLastCall(char *WhichUser) + int CtdlSetUserLastCall(time_t NewValue, char *WhichUser) + + Get or set the timestamp of a user's last call. + + + int CtdlForEachUser(int (*CallBack)(char *EachUser)) + + This allows a user-supplied function to be called once for each user account +on the system; the single argument passed to the function will be the name of +the user being processed. + diff --git a/citadel/user_ops.c b/citadel/user_ops.c index dcd3ddde7..725d41ab8 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -139,7 +139,9 @@ int getuserbynumber(struct usersupp *usbuf, long int number) while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) { bzero(usbuf, sizeof(struct usersupp)); - memcpy(usbuf, cdbus->ptr, cdbus->len); + memcpy(usbuf, cdbus->ptr, + ( (cdbus->len > sizeof(struct usersupp)) ? + sizeof(struct usersupp) : cdbus->len) ); cdb_free(cdbus); if (usbuf->usernum == number) { return(0); @@ -717,7 +719,9 @@ void cmd_gnur(void) { cdb_rewind(CDB_USERSUPP); while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) { bzero(&usbuf, sizeof(struct usersupp)); - memcpy(&usbuf, cdbus->ptr, cdbus->len); + memcpy(&usbuf, cdbus->ptr, + ( (cdbus->len > sizeof(struct usersupp)) ? + sizeof(struct usersupp) : cdbus->len) ); cdb_free(cdbus); if ((usbuf.flags & US_NEEDVALID) &&(usbuf.axlevel > 0)) { @@ -859,7 +863,9 @@ void cmd_list(void) { while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) { bzero(&usbuf, sizeof(struct usersupp)); - memcpy(&usbuf, cdbus->ptr, cdbus->len); + memcpy(&usbuf, cdbus->ptr, + ( (cdbus->len > sizeof(struct usersupp)) ? + sizeof(struct usersupp) : cdbus->len) ); cdb_free(cdbus); if (usbuf.axlevel > 0) {