$Log$
+ Revision 641.32 2005/03/24 22:13:56 ajc
+ * extract_token() now expects to be supplied with the size of the
+ destination string buffer. This, along with the elimination of other
+ unbounded functions like strcpy(), will allow the removal of the
+ "all string buffers are of size SIZ" assumption (a process which I have
+ already begun), which will hopefully reduce stack consumption.
+
Revision 641.31 2005/03/22 21:53:48 ajc
* Oops, forgot to initialize some data structures...
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
+
pprintf(" User Name Num L LastCall Calls Posts\n");
pprintf("------------------------- ----- - ---------- ----- -----\n");
while (strlen(listing) > 0) {
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
if (sigcaught == 0) {
- extract(fl, buf, 0);
+ extract_token(fl, buf, 0, '|', sizeof fl);
if (pattern(fl, patn) >= 0) {
pprintf("%-25s ", fl);
pprintf("%5ld %d ", extract_long(buf, 2),
*/
void load_user_info(char *params)
{
- extract(fullname, params, 0);
+ extract_token(fullname, params, 0, '|', sizeof fullname);
axlevel = extract_int(params, 1);
timescalled = extract_int(params, 2);
posted = extract_int(params, 3);
/* Copy the list into a fixed-record-size array for sorting */
for (i=0; i<rows; ++i) {
memset(buf, 0, SIZ);
- extract_token(buf, listing, i, '\n');
+ extract_token(buf, listing, i, '\n', sizeof buf);
memcpy(&sortbuf[i*SIZ], buf, (size_t)SIZ);
}
int isidle = 0;
/* Get another line */
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
- extract(username, buf, 1);
- extract(roomname, buf, 2);
- extract(fromhost, buf, 3);
- extract(clientsoft, buf, 4);
- extract(flags, buf, 7);
+ extract_token(username, buf, 1, '|', sizeof username);
+ extract_token(roomname, buf, 2, '|', sizeof roomname);
+ extract_token(fromhost, buf, 3, '|', sizeof fromhost);
+ extract_token(clientsoft, buf, 4, '|', sizeof clientsoft);
+ extract_token(flags, buf, 7, '|', sizeof flags);
idletime = timenow - extract_long(buf, 5);
idlehours = idletime / 3600;
}
if (longlist) {
- extract(actual_user, buf, 8);
- extract(actual_room, buf, 9);
- extract(actual_host, buf, 10);
+ extract_token(actual_user, buf, 8, '|', sizeof actual_user);
+ extract_token(actual_room, buf, 9, '|', sizeof actual_room);
+ extract_token(actual_host, buf, 10, '|', sizeof actual_host);
pprintf(" Flags: %s\n", flags);
pprintf("Session: %d\n", extract_int(buf, 0));
while (bbb && strlen(bbb)) {
int a;
- extract_token(aaa, bbb, 0, '\n');
+ extract_token(aaa, bbb, 0, '\n', sizeof aaa);
a = strlen(aaa);
memmove(bbb, bbb + a + 1, strlen(bbb) - a);
mptr = (struct march *) malloc(sizeof (struct march));
if (mptr) {
mptr->next = NULL;
- extract(mptr->march_name, aaa, 0);
+ extract_token(mptr->march_name, aaa, 0, '|', sizeof mptr->march_name);
mptr->march_flags = (unsigned int) extract_int(aaa, 1);
mptr->march_floor = (char) extract_int(aaa, 2);
mptr->march_order = (char) extract_int(aaa, 3);
}
ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
if (ret / 100 == 2) {
- extract(rret[0]->RRname, cret, 0);
+ extract_token(rret[0]->RRname, cret, 0, '|', sizeof rret[0]->RRname);
rret[0]->RRunread = extract_long(cret, 1);
rret[0]->RRtotal = extract_long(cret, 2);
rret[0]->RRinfoupdated = extract_int(cret, 3);
if (!*mret)
return -1;
while (bbb && strlen(bbb)) {
- extract_token(aaa, bbb, 0, '\n');
+ extract_token(aaa, bbb, 0, '\n', sizeof aaa);
remove_token(bbb, 0, '\n');
*mret = (unsigned long *)realloc(*mret, (size_t)((count + 2) *
sizeof (unsigned long)));
char *bbb = NULL;
size_t bbbsize;
int multipart_hunting = 0;
- char multipart_prefix[SIZ];
+ char multipart_prefix[128];
if (!cret) return -1;
if (!mret) return -1;
if (as_mime != 2) {
strcpy(mret[0]->mime_chosen, "1"); /* Default chosen-part is "1" */
while (strlen(bbb) > 4 && bbb[4] == '=') {
- extract_token(aaa, bbb, 0, '\n');
+ extract_token(aaa, bbb, 0, '\n', sizeof aaa);
remove_token(bbb, 0, '\n');
if (!strncasecmp(aaa, "nhdr=yes", 8))
* us to determine which part we want to download.
*/
else if (!strncasecmp(aaa, "pref=", 5)) {
- extract(multipart_prefix, &aaa[5], 1);
+ extract_token(multipart_prefix, &aaa[5], 1, '|', sizeof multipart_prefix);
if (!strcasecmp(multipart_prefix,
"multipart/alternative")) {
++multipart_hunting;
}
}
else if (!strncasecmp(aaa, "suff=", 5)) {
- extract(multipart_prefix, &aaa[5], 1);
+ extract_token(multipart_prefix, &aaa[5], 1, '|', sizeof multipart_prefix);
if (!strcasecmp(multipart_prefix,
"multipart/alternative")) {
++multipart_hunting;
if (ptr) {
/* Fill the buffers for the caller */
- extract(ptr->name, &aaa[5], 0);
- extract(ptr->filename, &aaa[5], 1);
- extract(ptr->number, &aaa[5], 2);
- extract(ptr->disposition, &aaa[5], 3);
- extract(ptr->mimetype, &aaa[5], 4);
+ extract_token(ptr->name, &aaa[5], 0, '|', sizeof ptr->name);
+ extract_token(ptr->filename, &aaa[5], 1, '|', sizeof ptr->filename);
+ extract_token(ptr->number, &aaa[5], 2, '|', sizeof ptr->number);
+ extract_token(ptr->disposition, &aaa[5], 3, '|', sizeof ptr->disposition);
+ extract_token(ptr->mimetype, &aaa[5], 4, '|', sizeof ptr->mimetype);
ptr->length = extract_long(&aaa[5], 5);
if (!mret[0]->attachments)
mret[0]->attachments = ptr;
if (as_mime == 4) {
do {
if (!strncasecmp(bbb, "Content-type: ", 14)) {
- extract_token(mret[0]->content_type, bbb, 0, '\n');
+ extract_token(mret[0]->content_type, bbb, 0, '\n', sizeof mret[0]->content_type);
strcpy(mret[0]->content_type,
&mret[0]->content_type[14]);
striplt(mret[0]->content_type);
int line = 0;
while (*listing && strlen(listing)) {
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
switch (line++) {
case 0: ipc->ServInfo.pid = atoi(buf);
ret = CtdlIPCGenericCommand(ipc, "GETR", NULL, 0, NULL, NULL, cret);
if (ret / 100 == 2) {
- extract(qret[0]->QRname, cret, 0);
- extract(qret[0]->QRpasswd, cret, 1);
- extract(qret[0]->QRdirname, cret, 2);
+ extract_token(qret[0]->QRname, cret, 0, '|', sizeof qret[0]->QRname);
+ extract_token(qret[0]->QRpasswd, cret, 1, '|', sizeof qret[0]->QRpasswd);
+ extract_token(qret[0]->QRdirname, cret, 2, '|', sizeof qret[0]->QRdirname);
qret[0]->QRflags = extract_int(cret, 3);
qret[0]->QRfloor = extract_int(cret, 4);
qret[0]->QRorder = extract_int(cret, 5);
ipc->downloading = 1;
bytes = extract_long(cret, 0);
last_mod = extract_int(cret, 1);
- extract(mimetype, cret, 2);
+ extract_token(mimetype, cret, 2, '|', sizeof mimetype);
ret = CtdlIPCReadDownload(ipc, buf, bytes, resume,
progress_gauge_callback, cret);
ipc->downloading = 1;
bytes = extract_long(cret, 0);
last_mod = extract_int(cret, 1);
- extract(filename, cret, 2);
- extract(mimetype, cret, 3);
+ extract_token(filename, cret, 2, '|', sizeof filename);
+ extract_token(mimetype, cret, 3, '|', sizeof mimetype);
/* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */
ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret);
ret = CtdlIPCEndDownload(ipc, cret);
ipc->downloading = 1;
bytes = extract_long(cret, 0);
last_mod = extract_int(cret, 1);
- extract(mimetype, cret, 2);
+ extract_token(mimetype, cret, 2, '|', sizeof mimetype);
/* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */
ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret);
ret = CtdlIPCEndDownload(ipc, cret);
ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
if (ret / 100 == 2) {
- extract(uret[0]->fullname, cret, 0);
- extract(uret[0]->password, cret, 1);
+ extract_token(uret[0]->fullname, cret, 0, '|', sizeof uret[0]->fullname);
+ extract_token(uret[0]->password, cret, 1, '|', sizeof uret[0]->password);
uret[0]->flags = extract_int(cret, 2);
uret[0]->timescalled = extract_long(cret, 3);
uret[0]->posted = extract_long(cret, 4);
*/
int is_public_client(void)
{
- char buf[SIZ];
- char addrbuf[SIZ];
+ char buf[1024];
+ char addrbuf[1024];
FILE *fp;
int i;
struct stat statbuf;
lprintf(CTDL_DEBUG, "Checking whether %s is a local or public client\n",
CC->cs_addr);
for (i=0; i<num_parms(public_clients); ++i) {
- extract(addrbuf, public_clients, i);
+ extract_token(addrbuf, public_clients, i, '|', sizeof addrbuf);
if (!strcasecmp(CC->cs_addr, addrbuf)) {
lprintf(CTDL_DEBUG, "... yes it is.\n");
return(1);
int dev_code;
int cli_code;
int rev_level;
- char desc[SIZ];
- char from_host[SIZ];
+ char desc[128];
+ char from_host[128];
struct in_addr addr;
int do_lookup = 0;
dev_code = extract_int(argbuf,0);
cli_code = extract_int(argbuf,1);
rev_level = extract_int(argbuf,2);
- extract(desc,argbuf,3);
+ extract_token(desc, argbuf, 3, '|', sizeof desc);
safestrncpy(from_host, config.c_fqdn, sizeof from_host);
from_host[sizeof from_host - 1] = 0;
- if (num_parms(argbuf)>=5) extract(from_host,argbuf,4);
+ if (num_parms(argbuf)>=5) extract_token(from_host, argbuf, 4, '|', sizeof from_host);
CC->cs_clientdev = dev_code;
CC->cs_clienttyp = cli_code;
void cmd_mesg(char *mname)
{
FILE *mfp;
- char targ[SIZ];
- char buf[SIZ];
- char buf2[SIZ];
+ char targ[256];
+ char buf[256];
+ char buf2[256];
char *dirs[2];
- extract(buf,mname,0);
+ extract_token(buf, mname, 0, '|', sizeof buf);
dirs[0]=malloc(64);
dirs[1]=malloc(64);
strcpy(dirs[0],"messages");
strcpy(dirs[1],"help");
snprintf(buf2, sizeof buf2, "%s.%d.%d", buf, CC->cs_clientdev, CC->cs_clienttyp);
- mesg_locate(targ,sizeof targ,buf2,2,(const char **)dirs);
+ mesg_locate(targ, sizeof targ, buf2, 2, (const char **)dirs);
if (strlen(targ) == 0) {
snprintf(buf2, sizeof buf2, "%s.%d", buf, CC->cs_clientdev);
- mesg_locate(targ,sizeof targ,buf2,2,(const char **)dirs);
+ mesg_locate(targ, sizeof targ, buf2, 2, (const char **)dirs);
if (strlen(targ) == 0) {
- mesg_locate(targ,sizeof targ,buf,2,(const char **)dirs);
+ mesg_locate(targ, sizeof targ, buf, 2, (const char **)dirs);
}
}
free(dirs[0]);
void cmd_emsg(char *mname)
{
FILE *mfp;
- char targ[SIZ];
- char buf[SIZ];
+ char targ[256];
+ char buf[256];
char *dirs[2];
int a;
if (CtdlAccessCheck(ac_aide)) return;
- extract(buf,mname,0);
+ extract_token(buf, mname, 0, '|', sizeof buf);
for (a=0; a<strlen(buf); ++a) { /* security measure */
if (buf[a] == '/') buf[a] = '.';
}
- dirs[0]=malloc(64);
- dirs[1]=malloc(64);
- strcpy(dirs[0],"messages");
- strcpy(dirs[1],"help");
- mesg_locate(targ,sizeof targ,buf,2,(const char**)dirs);
+ dirs[0] = strdup("messages");
+ dirs[1] = strdup("help");
+ mesg_locate(targ, sizeof targ, buf, 2, (const char**)dirs);
free(dirs[0]);
free(dirs[1]);
return;
}
if (num_parms(buf) >= 2) {
- extract(c_user, buf, 0);
- extract(c_text, buf, 1);
+ extract_token(c_user, buf, 0, '|', sizeof c_user);
+ extract_token(c_text, buf, 1, '|', sizeof c_text);
if (num_parms(buf) > 2) {
- extract(c_room, buf, 2);
+ extract_token(c_room, buf, 2, '|', sizeof c_room);
scr_printf("Got room %s\n", c_room);
}
if (strcasecmp(c_text, "NOOP")) {
FILE *fp;
char buf[SIZ];
char buf64[SIZ];
- char hostbuf[SIZ], portbuf[SIZ], ubuf[SIZ], pbuf[SIZ];
+ char hostbuf[256], portbuf[256], ubuf[256], pbuf[256];
strcpy(username, "");
strcpy(password, "");
if (fp == NULL) return;
while (fgets(buf64, sizeof buf64, fp) != NULL) {
CtdlDecodeBase64(buf, buf64, sizeof(buf64));
- extract(hostbuf, buf, 0);
- extract(portbuf, buf, 1);
- extract(ubuf, buf, 2);
- extract(pbuf, buf, 3);
+ extract_token(hostbuf, buf, 0, '|', sizeof hostbuf);
+ extract_token(portbuf, buf, 1, '|', sizeof portbuf);
+ extract_token(ubuf, buf, 2, '|', sizeof ubuf);
+ extract_token(pbuf, buf, 3, '|', sizeof pbuf);
if (!strcasecmp(hostbuf, host)) {
if (!strcasecmp(portbuf, port)) {
FILE *fp, *oldfp;
char buf[SIZ];
char buf64[SIZ];
- char hostbuf[SIZ], portbuf[SIZ], ubuf[SIZ], pbuf[SIZ];
+ char hostbuf[256], portbuf[256], ubuf[256], pbuf[256];
determine_pwfilename(pwfile, sizeof pwfile);
if (strlen(pwfile)==0) return;
if (fp == NULL) fp = fopen("/dev/null", "w");
while (fgets(buf64, sizeof buf64, oldfp) != NULL) {
CtdlDecodeBase64(buf, buf64, sizeof(buf64));
- extract(hostbuf, buf, 0);
- extract(portbuf, buf, 1);
- extract(ubuf, buf, 2);
- extract(pbuf, buf, 3);
+ extract_token(hostbuf, buf, 0, '|', sizeof hostbuf);
+ extract_token(portbuf, buf, 1, '|', sizeof portbuf);
+ extract_token(ubuf, buf, 2, '|', sizeof ubuf);
+ extract_token(pbuf, buf, 3, '|', sizeof pbuf);
if ( (strcasecmp(hostbuf, host))
|| (strcasecmp(portbuf, port)) ) {
instant_msgs = extract_int(buf, 0);
timestamp = extract_long(buf, 1);
flags = extract_int(buf, 2);
- extract(sender, buf, 3);
- extract(node, buf, 4);
+ extract_token(sender, buf, 3, '|', sizeof sender);
+ extract_token(node, buf, 4, '|', sizeof node);
strcpy(last_paged, sender);
localtime_r(×tamp, &stamp);
}
else {
for (i=0; i<choices; ++i) {
- extract(buf, menustring, i);
+ extract_token(buf, menustring, i, '|', sizeof buf);
keyopt(buf);
scr_printf(" ");
}
scr_printf("\rOne of... ");
scr_printf(" \n");
for (i=0; i<choices; ++i) {
- extract(buf, menustring, i);
+ extract_token(buf, menustring, i, '|', sizeof buf);
scr_printf(" ");
keyopt(buf);
scr_printf("\n");
}
for (i=0; i<choices; ++i) {
- extract(buf, menustring, i);
+ extract_token(buf, menustring, i, '|', sizeof buf);
for (c=1; c<strlen(buf); ++c) {
if ( (ch == tolower(buf[c]))
&& (buf[c-1]=='<')
*/
void cmd_conf(char *argbuf)
{
- char cmd[SIZ];
- char buf[SIZ];
+ char cmd[16];
+ char buf[256];
int a;
char *confptr;
- char confname[SIZ];
+ char confname[128];
if (CtdlAccessCheck(ac_aide)) return;
- extract(cmd, argbuf, 0);
+ extract_token(cmd, argbuf, 0, '|', sizeof cmd);
if (!strcasecmp(cmd, "GET")) {
cprintf("%d Configuration...\n", LISTING_FOLLOWS);
cprintf("%s\n", config.c_nodename);
}
else if (!strcasecmp(cmd, "GETSYS")) {
- extract(confname, argbuf, 1);
+ extract_token(confname, argbuf, 1, '|', sizeof confname);
confptr = CtdlGetSysConfig(confname);
if (confptr != NULL) {
cprintf("%d %s\n", LISTING_FOLLOWS, confname);
}
else if (!strcasecmp(cmd, "PUTSYS")) {
- extract(confname, argbuf, 1);
+ extract_token(confname, argbuf, 1, '|', sizeof confname);
unbuffer_output();
cprintf("%d %s\n", SEND_LISTING, confname);
confptr = CtdlReadMessageBody("000",
int get_hosts(char *mxbuf, char *rectype) {
int config_lines;
int i;
- char buf[SIZ];
- char host[SIZ], type[SIZ];
+ char buf[256];
+ char host[256], type[256];
int total_smarthosts = 0;
if (inetcfg == NULL) return(0);
config_lines = num_tokens(inetcfg, '\n');
for (i=0; i<config_lines; ++i) {
- extract_token(buf, inetcfg, i, '\n');
- extract_token(host, buf, 0, '|');
- extract_token(type, buf, 1, '|');
+ extract_token(buf, inetcfg, i, '\n', sizeof buf);
+ extract_token(host, buf, 0, '|', sizeof host);
+ extract_token(type, buf, 1, '|', sizeof type);
if (!strcasecmp(type, rectype)) {
strcat(mxbuf, host);
if (ptr == NULL) break;
strcpy(ptr, "");
for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
- extract(buf, nttlist, i);
+ extract_token(buf, nttlist, i, '|', sizeof buf);
if ( (strlen(buf) > 0)
&& (strcasecmp(buf, nodename)) ) {
strcat(ptr, buf);
if (nttlist == NULL) break;
if (strlen(nttlist) == 0) break;
for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
- extract(buf, nttlist, i);
+ extract_token(buf, nttlist, i, '|', sizeof buf);
if (!strcasecmp(buf, nodename)) ++retval;
}
break;
*/
void cmd_movf(char *cmdbuf)
{
- char filename[SIZ];
- char pathname[SIZ];
- char newpath[SIZ];
- char newroom[SIZ];
- char buf[SIZ];
+ char filename[PATH_MAX];
+ char pathname[PATH_MAX];
+ char newpath[PATH_MAX];
+ char newroom[ROOMNAMELEN];
+ char buf[PATH_MAX];
int a;
struct ctdlroom qrbuf;
- extract(filename, cmdbuf, 0);
- extract(newroom, cmdbuf, 1);
+ extract_token(filename, cmdbuf, 0, '|', sizeof filename);
+ extract_token(newroom, cmdbuf, 1, '|', sizeof newroom);
if (CtdlAccessCheck(ac_room_aide)) return;
*/
void cmd_netf(char *cmdbuf)
{
- char pathname[SIZ], filename[SIZ], destsys[SIZ], buf[SIZ];
- char outfile[SIZ];
+ char pathname[256], filename[256], destsys[256], buf[256];
+ char outfile[256];
int a, e;
time_t now;
FILE *ofp;
static int seq = 1;
- extract(filename, cmdbuf, 0);
- extract(destsys, cmdbuf, 1);
+ extract_token(filename, cmdbuf, 0, '|', sizeof filename);
+ extract_token(destsys, cmdbuf, 1, '|', sizeof destsys);
if (CtdlAccessCheck(ac_room_aide)) return;
*/
void cmd_open(char *cmdbuf)
{
- char filename[SIZ];
- char pathname[SIZ];
+ char filename[256];
+ char pathname[PATH_MAX];
int a;
- extract(filename, cmdbuf, 0);
+ extract_token(filename, cmdbuf, 0, '|', sizeof filename);
if (CtdlAccessCheck(ac_logged_in)) return;
*/
void cmd_oimg(char *cmdbuf)
{
- char filename[SIZ];
- char pathname[SIZ];
+ char filename[256];
+ char pathname[PATH_MAX];
struct ctdluser usbuf;
char which_user[USERNAME_SIZE];
int which_floor;
int a;
- extract(filename, cmdbuf, 0);
+ extract_token(filename, cmdbuf, 0, '|', sizeof filename);
if (strlen(filename) == 0) {
cprintf("%d You must specify a file name.\n",
}
if (!strcasecmp(filename, "_userpic_")) {
- extract(which_user, cmdbuf, 1);
+ extract_token(which_user, cmdbuf, 1, '|', sizeof which_user);
if (getuser(&usbuf, which_user) != 0) {
cprintf("%d No such user.\n",
ERROR + NO_SUCH_USER);
{
int a;
- extract(CC->upl_file, cmdbuf, 0);
- extract(CC->upl_comment, cmdbuf, 1);
+ extract_token(CC->upl_file, cmdbuf, 0, '|', sizeof CC->upl_file);
+ extract_token(CC->upl_comment, cmdbuf, 1, '|', sizeof CC->upl_comment);
if (CtdlAccessCheck(ac_logged_in)) return;
void cmd_uimg(char *cmdbuf)
{
int is_this_for_real;
- char basenm[SIZ];
+ char basenm[256];
int which_floor;
int a;
}
is_this_for_real = extract_int(cmdbuf, 0);
- extract(basenm, cmdbuf, 1);
+ extract_token(basenm, cmdbuf, 1, '|', sizeof basenm);
if (CC->upload_fp != NULL) {
cprintf("%d You already have an upload file open.\n",
ERROR + RESOURCE_BUSY);
*/
void cmd_clos(void)
{
- char buf[SIZ];
+ char buf[256];
if (CC->download_fp == NULL) {
cprintf("%d You don't have a download file open.\n",
long start_pos;
size_t bytes;
size_t actual_bytes;
- char buf[4096];
+ char *buf = NULL;
start_pos = extract_long(cmdbuf, 0);
bytes = extract_int(cmdbuf, 1);
return;
}
- if (bytes > 4096) bytes = 4096;
+ if (bytes > 100000) bytes = 100000;
+ buf = malloc(bytes + 1);
fseek(CC->download_fp, start_pos, 0);
actual_bytes = fread(buf, 1, bytes, CC->download_fp);
cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes);
client_write(buf, actual_bytes);
+ free(buf);
}
void cmd_writ(char *cmdbuf)
{
int bytes;
- char buf[4096];
+ char *buf;
unbuffer_output();
return;
}
- if (bytes > 4096) {
- cprintf("%d You may not write more than 4096 bytes.\n",
+ if (bytes > 100000) {
+ cprintf("%d You may not write more than 100000 bytes.\n",
ERROR + TOO_BIG);
return;
}
cprintf("%d %d\n", SEND_BINARY, bytes);
+ buf = malloc(bytes + 1);
client_read(buf, bytes);
fwrite(buf, bytes, 1, CC->upload_fp);
+ free(buf);
}
*/
void cmd_ndop(char *cmdbuf)
{
- char pathname[SIZ];
+ char pathname[256];
struct stat statbuf;
if (strlen(CC->net_node) == 0) {
* fields. But we can use it for "To" and possibly others.
*/
void imap_output_envelope_addr(char *addr) {
- char individual_addr[SIZ];
+ char individual_addr[256];
int num_addrs;
int i;
- char user[SIZ];
- char node[SIZ];
- char name[SIZ];
+ char user[256];
+ char node[256];
+ char name[256];
if (addr == NULL) {
cprintf("NIL ");
/* Output them one by one. */
for (i=0; i<num_addrs; ++i) {
- extract_token(individual_addr, addr, i, ',');
+ extract_token(individual_addr, addr, i, ',', sizeof individual_addr);
striplt(individual_addr);
process_rfc822_addr(individual_addr, user, node, name);
cprintf("(");
void *cbuserdata
) {
- char subtype[SIZ];
+ char subtype[128];
cprintf(" ");
/* disposition */
- extract_token(subtype, cbtype, 1, '/');
+ extract_token(subtype, cbtype, 1, '/', sizeof subtype);
imap_strout(subtype);
/* body language */
int have_encoding = 0;
int lines = 0;
size_t i;
- char cbmaintype[SIZ];
- char cbsubtype[SIZ];
+ char cbmaintype[128];
+ char cbsubtype[128];
if (cbtype != NULL) if (strlen(cbtype)>0) have_cbtype = 1;
if (have_cbtype) {
- extract_token(cbmaintype, cbtype, 0, '/');
- extract_token(cbsubtype, cbtype, 1, '/');
+ extract_token(cbmaintype, cbtype, 0, '/', sizeof cbmaintype);
+ extract_token(cbsubtype, cbtype, 1, '/', sizeof cbsubtype);
}
else {
strcpy(cbmaintype, "TEXT");
*/
num_sets = num_tokens(actual_range, ',');
for (s=0; s<num_sets; ++s) {
- extract_token(setstr, actual_range, s, ',');
+ extract_token(setstr, actual_range, s, ',', sizeof setstr);
- extract_token(lostr, setstr, 0, ':');
+ extract_token(lostr, setstr, 0, ':', sizeof lostr);
if (num_tokens(setstr, ':') >= 2) {
- extract_token(histr, setstr, 1, ':');
+ extract_token(histr, setstr, 1, ':', sizeof histr);
if (!strcmp(histr, "*")) snprintf(histr, sizeof histr, "%ld", LONG_MAX);
}
else {
- strcpy(histr, lostr);
+ safestrncpy(histr, lostr, sizeof histr);
}
lo = atol(lostr);
hi = atol(histr);
safestrncpy(flags, new_message_flags, sizeof flags);
for (i=0; i<num_tokens(flags, ' '); ++i) {
- extract_token(this_flag, flags, i, ' ');
+ extract_token(this_flag, flags, i, ' ', sizeof this_flag);
if (this_flag[0] == '\\') strcpy(this_flag, &this_flag[1]);
if (!strcasecmp(this_flag, "Seen")) {
CtdlSetSeen(new_msgnum, 1, ctdlsetseen_seen);
int i, j;
unsigned int bits_to_twiddle = 0;
char *oper;
- char flag[SIZ];
- char whichflags[SIZ];
+ char flag[32];
+ char whichflags[256];
char num_flags;
if (num_items < 2) return;
for (i=1; i<num_items; ++i) {
strcpy(whichflags, itemlist[i]);
- if (whichflags[0]=='(') strcpy(whichflags, &whichflags[1]);
+ if (whichflags[0]=='(') safestrncpy(whichflags, &whichflags[1], sizeof whichflags);
if (whichflags[strlen(whichflags)-1]==')') {
whichflags[strlen(whichflags)-1]=0;
}
*/
num_flags = num_tokens(whichflags, ' ');
for (j=0; j<num_flags; ++j) {
- extract_token(flag, whichflags, j, ' ');
+ extract_token(flag, whichflags, j, ' ', sizeof flag);
if ((!strcasecmp(flag, "\\Deleted"))
|| (!strcasecmp(flag, "Deleted"))) {
int imap_roomname(char *rbuf, int bufsize, char *foldername)
{
int levels;
- char floorname[SIZ];
- char roomname[SIZ];
+ char floorname[256];
+ char roomname[ROOMNAMELEN];
int i;
struct floor *fl;
int ret = (-1);
{
/* Extract the main room name. */
- extract_token(floorname, rbuf, 0, FDELIM);
+ extract_token(floorname, rbuf, 0, FDELIM, sizeof floorname);
strcpy(roomname, &rbuf[strlen(floorname)+1]);
/* Try and find it on any floor. */
{
/* Got it! */
- strcpy(rbuf, roomname);
+ safestrncpy(rbuf, roomname, bufsize);
ret = i;
goto exit;
}
* a Unix timestamp.
*/
int imap_datecmp(char *datestr, time_t msgtime) {
- char daystr[SIZ];
- char monthstr[SIZ];
- char yearstr[SIZ];
+ char daystr[256];
+ char monthstr[256];
+ char yearstr[256];
int i;
int day, month, year;
int msgday, msgmonth, msgyear;
if (datestr == NULL) return(0);
/* Expecting a date in the form dd-Mmm-yyyy */
- extract_token(daystr, datestr, 0, '-');
- extract_token(monthstr, datestr, 1, '-');
- extract_token(yearstr, datestr, 2, '-');
+ extract_token(daystr, datestr, 0, '-', sizeof daystr);
+ extract_token(monthstr, datestr, 1, '-', sizeof monthstr);
+ extract_token(yearstr, datestr, 2, '-', sizeof yearstr);
day = atoi(daystr);
year = atoi(yearstr);
int CtdlHostAlias(char *fqdn) {
int config_lines;
int i;
- char buf[SIZ];
- char host[SIZ], type[SIZ];
+ char buf[256];
+ char host[256], type[256];
if (fqdn == NULL) return(hostalias_nomatch);
if (strlen(fqdn) == 0) return(hostalias_nomatch);
config_lines = num_tokens(inetcfg, '\n');
for (i=0; i<config_lines; ++i) {
- extract_token(buf, inetcfg, i, '\n');
- extract_token(host, buf, 0, '|');
- extract_token(type, buf, 1, '|');
+ extract_token(buf, inetcfg, i, '\n', sizeof buf);
+ extract_token(host, buf, 0, '|', sizeof host);
+ extract_token(type, buf, 1, '|', sizeof type);
if ( (!strcasecmp(type, "localhost"))
&& (!strcasecmp(fqdn, host)))
* the directory
*/
int IsDirectory(char *addr) {
- char domain[SIZ];
+ char domain[256];
int h;
- extract_token(domain, addr, 1, '@');
+ extract_token(domain, addr, 1, '@', sizeof domain);
striplt(domain);
h = CtdlHostAlias(domain);
- lprintf(CTDL_DEBUG, "IsDirectory(%s)\n", domain);
if ( (h == hostalias_localhost) || (h == hostalias_directory) ) {
- lprintf(CTDL_DEBUG, " ...yes\n");
return(1);
}
else {
- lprintf(CTDL_DEBUG, " ...no\n");
return(0);
}
}
{
const char *i;
int a1, a2, a3, a4;
- char tbuf[SIZ];
+ char tbuf[256];
int rbl;
int num_rbl;
char rbl_domains[SIZ];
snprintf(tbuf, sizeof tbuf,
"%d.%d.%d.%d.",
a4, a3, a2, a1);
- extract(&tbuf[strlen(tbuf)], rbl_domains, rbl);
+ extract_token(&tbuf[strlen(tbuf)], rbl_domains, rbl, '|', (sizeof tbuf - strlen(tbuf)));
if (gethostbyname(tbuf) != NULL) {
strcpy(message_to_spammer,
- "5.7.1 Message rejected due to "
- "known spammer source IP address"
+ "5.7.1 Message rejected due to known spammer source IP address"
);
return(1);
}
if (r / 100 != 2) {
scr_printf("%s\n", cmd);
} else {
- extract(filename, cmd, 2);
+ extract_token(filename, cmd, 2, '|', sizeof filename);
/*
* Part 1 won't have a filename; use the
* subject of the message instead. IO
while (transcript && strlen(transcript)) {
lines_printed = 1;
- extract_token(buf, transcript, 0, '\n');
+ extract_token(buf, transcript, 0, '\n', sizeof buf);
remove_token(transcript, 0, '\n');
pprintf("%s\n", buf);
}
char *ignetcfg = NULL;
char *ignetmap = NULL;
int at = 0;
- char node[SIZ];
- char testnode[SIZ];
+ char node[64];
+ char testnode[64];
char buf[SIZ];
striplt(name);
remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
/* figure out the delivery mode */
- extract_token(node, name, 1, '@');
+ extract_token(node, name, 1, '@', sizeof node);
/* If there are one or more dots in the nodename, we assume that it
* is an FQDN and will attempt SMTP delivery to the Internet.
*/
ignetcfg = CtdlGetSysConfig(IGNETCFG);
for (i=0; i<num_tokens(ignetcfg, '\n'); ++i) {
- extract_token(buf, ignetcfg, i, '\n');
- extract_token(testnode, buf, 0, '|');
+ extract_token(buf, ignetcfg, i, '\n', sizeof buf);
+ extract_token(testnode, buf, 0, '|', sizeof testnode);
if (!strcasecmp(node, testnode)) {
free(ignetcfg);
return(MES_IGNET);
*/
ignetmap = CtdlGetSysConfig(IGNETMAP);
for (i=0; i<num_tokens(ignetmap, '\n'); ++i) {
- extract_token(buf, ignetmap, i, '\n');
- extract_token(testnode, buf, 0, '|');
+ extract_token(buf, ignetmap, i, '\n', sizeof buf);
+ extract_token(testnode, buf, 0, '|', sizeof testnode);
if (!strcasecmp(node, testnode)) {
free(ignetmap);
return(MES_IGNET);
int with_template = 0;
struct CtdlMessage *template = NULL;
- extract(which, cmdbuf, 0);
+ extract_token(which, cmdbuf, 0, '|', sizeof which);
cm_ref = extract_int(cmdbuf, 1);
with_template = extract_int(cmdbuf, 2);
malloc(sizeof(struct CtdlMessage));
memset(template, 0, sizeof(struct CtdlMessage));
while(client_getln(buf, sizeof buf), strcmp(buf,"000")) {
- extract(tfield, buf, 0);
- extract(tvalue, buf, 1);
+ extract_token(tfield, buf, 0, '|', sizeof tfield);
+ extract_token(tvalue, buf, 1, '|', sizeof tvalue);
for (i='A'; i<='Z'; ++i) if (msgkeys[i]!=NULL) {
if (!strcasecmp(tfield, msgkeys[i])) {
template->cm_fields[i] =
void *content, char *cbtype, size_t length, char *encoding,
void *cbuserdata)
{
- char buf[SIZ];
+ char buf[1024];
int i;
struct ma_info *ma;
if (ma->is_ma > 0) {
for (i=0; i<num_tokens(CC->preferred_formats, '|'); ++i) {
- extract(buf, CC->preferred_formats, i);
+ extract_token(buf, CC->preferred_formats, i, '|', sizeof buf);
if (!strcasecmp(buf, cbtype)) {
strcpy(ma->chosen_part, partnum);
}
* list, we can simply output it verbatim.
*/
for (i=0; i<num_tokens(CC->preferred_formats, '|'); ++i) {
- extract(buf, CC->preferred_formats, i);
+ extract_token(buf, CC->preferred_formats, i, '|', sizeof buf);
if (!strcasecmp(buf, cbtype)) {
/* Yeah! Go! W00t!! */
void cmd_opna(char *cmdbuf)
{
long msgid;
- char desired_section[SIZ];
+ char desired_section[128];
msgid = extract_long(cmdbuf, 0);
- extract(desired_section, cmdbuf, 1);
+ extract_token(desired_section, cmdbuf, 1, '|', sizeof desired_section);
safestrncpy(CC->download_desired_section, desired_section, sizeof CC->download_desired_section);
-
CtdlOutputMsg(msgid, MT_DOWNLOAD, 0, 1, 1);
}
if (recps != NULL)
if (recps->num_room > 0)
for (i=0; i<num_tokens(recps->recp_room, '|'); ++i) {
- extract(recipient, recps->recp_room, i);
+ extract_token(recipient, recps->recp_room, i, '|', sizeof recipient);
lprintf(CTDL_DEBUG, "Delivering to local room <%s>\n", recipient);
CtdlSaveMsgPointerInRoom(recipient, newmsgid, 0);
}
if (recps != NULL)
if (recps->num_local > 0)
for (i=0; i<num_tokens(recps->recp_local, '|'); ++i) {
- extract(recipient, recps->recp_local, i);
+ extract_token(recipient, recps->recp_local, i, '|', sizeof recipient);
lprintf(CTDL_DEBUG, "Delivering private local mail to <%s>\n",
recipient);
if (getuser(&userbuf, recipient) == 0) {
if (recps != NULL)
if (recps->num_ignet > 0)
for (i=0; i<num_tokens(recps->recp_ignet, '|'); ++i) {
- extract(recipient, recps->recp_ignet, i);
+ extract_token(recipient, recps->recp_ignet, i, '|', sizeof recipient);
hold_R = msg->cm_fields['R'];
hold_D = msg->cm_fields['D'];
msg->cm_fields['R'] = malloc(SIZ);
- msg->cm_fields['D'] = malloc(SIZ);
- extract_token(msg->cm_fields['R'], recipient, 0, '@');
- extract_token(msg->cm_fields['D'], recipient, 1, '@');
+ msg->cm_fields['D'] = malloc(128);
+ extract_token(msg->cm_fields['R'], recipient, 0, '@', SIZ);
+ extract_token(msg->cm_fields['D'], recipient, 1, '@', 128);
serialize_message(&smr, msg);
if (smr.len > 0) {
for (i=0; i<num_tokens(recps->recp_internet, '|'); ++i) {
size_t tmp = strlen(instr);
- extract(recipient, recps->recp_internet, i);
+ extract_token(recipient, recps->recp_internet, i, '|', sizeof recipient);
snprintf(&instr[tmp], SIZ * 2 - tmp,
"remote|%s|0||\n", recipient);
}
}
if (num_recps > 0) for (i=0; i<num_recps; ++i) {
- extract_token(this_recp, recipients, i, ',');
+ extract_token(this_recp, recipients, i, ',', sizeof this_recp);
striplt(this_recp);
lprintf(CTDL_DEBUG, "Evaluating recipient #%d <%s>\n", i, this_recp);
mailtype = alias(this_recp);
unbuffer_output();
post = extract_int(entargs, 0);
- extract(recp, entargs, 1);
+ extract_token(recp, entargs, 1, '|', sizeof recp);
anon_flag = extract_int(entargs, 2);
format_type = extract_int(entargs, 3);
- extract(subject, entargs, 4);
+ extract_token(subject, entargs, 4, '|', sizeof subject);
do_confirm = extract_int(entargs, 6);
/* first check to make sure the request is valid. */
ERROR + HIGHER_ACCESS_REQUIRED);
return;
}
- extract(newusername, entargs, 5);
+ extract_token(newusername, entargs, 5, '|', sizeof newusername);
memset(CC->fake_postname, 0, sizeof(CC->fake_postname) );
safestrncpy(CC->fake_postname, newusername,
sizeof(CC->fake_postname) );
void cmd_move(char *args)
{
long num;
- char targ[SIZ];
+ char targ[ROOMNAMELEN];
struct ctdlroom qtemp;
int err;
int is_copy = 0;
int permit = 0;
num = extract_long(args, 0);
- extract(targ, args, 1);
+ extract_token(targ, args, 1, '|', sizeof targ);
targ[ROOMNAMELEN - 1] = 0;
is_copy = extract_int(args, 2);
getroom(&CC->room, hold_rm);
if (conf != NULL) do {
- extract_token(buf, conf, 0, '\n');
+ extract_token(buf, conf, 0, '\n', sizeof buf);
strcpy(conf, &conf[strlen(buf)+1]);
} while ( (strlen(conf)>0) && (strlen(buf)>0) );
/*
* Determine whether a given Internet address belongs to the current user
*/
-int CtdlIsMe(char *addr) {
+int CtdlIsMe(char *addr, int addr_buf_len)
+{
struct recptypes *recp;
int i;
}
for (i=0; i<recp->num_local; ++i) {
- extract(addr, recp->recp_local, i);
+ extract_token(addr, recp->recp_local, i, '|', addr_buf_len);
if (!strcasecmp(addr, CC->user.fullname)) {
free(recp);
return(1);
* Citadel protocol command to do the same
*/
void cmd_isme(char *argbuf) {
- char addr[SIZ];
+ char addr[256];
if (CtdlAccessCheck(ac_logged_in)) return;
- extract(addr, argbuf, 0);
+ extract_token(addr, argbuf, 0, '|', sizeof addr);
- if (CtdlIsMe(addr)) {
+ if (CtdlIsMe(addr, sizeof addr)) {
cprintf("%d %s\n", CIT_OK, addr);
}
else {
char *preformatted_text /* ...or NULL to read text from client */
);
int CtdlCheckInternetMailPermission(struct ctdluser *who);
-int CtdlIsMe(char *addr);
+int CtdlIsMe(char *addr, int addr_buf_len);
void cmd_gpex(char *argbuf) {
struct ExpirePolicy exp;
struct floor *fl;
- char which[SIZ];
+ char which[128];
- extract(which, argbuf, 0);
+ extract_token(which, argbuf, 0, '|', sizeof which);
if (!strcasecmp(which, "room")) {
memcpy(&exp, &CC->room.QRep, sizeof(struct ExpirePolicy));
}
void cmd_spex(char *argbuf) {
struct ExpirePolicy exp;
struct floor flbuf;
- char which[SIZ];
+ char which[128];
memset(&exp, 0, sizeof(struct ExpirePolicy));
- extract(which, argbuf, 0);
+ extract_token(which, argbuf, 0, '|', sizeof which);
exp.expire_mode = extract_int(argbuf, 1);
exp.expire_value = extract_int(argbuf, 2);
int c;
int ok = 0;
int ra;
- char augmented_roomname[SIZ];
- char towhere[SIZ];
- char password[SIZ];
+ char augmented_roomname[ROOMNAMELEN];
+ char towhere[ROOMNAMELEN];
+ char password[32];
int transiently = 0;
if (CtdlAccessCheck(ac_logged_in)) return;
- extract(towhere, gargs, 0);
- extract(password, gargs, 1);
+ extract_token(towhere, gargs, 0, '|', sizeof towhere);
+ extract_token(password, gargs, 1, '|', sizeof password);
transiently = extract_int(gargs, 2);
getuser(&CC->user, CC->curr_user);
if (!strcasecmp(towhere, "_BASEROOM_"))
- strcpy(towhere, config.c_baseroom);
+ safestrncpy(towhere, config.c_baseroom, sizeof towhere);
if (!strcasecmp(towhere, "_MAIL_"))
- strcpy(towhere, MAILROOM);
+ safestrncpy(towhere, MAILROOM, sizeof towhere);
if (!strcasecmp(towhere, "_BITBUCKET_"))
- strcpy(towhere, config.c_twitroom);
+ safestrncpy(towhere, config.c_twitroom, sizeof towhere);
/* First try a regular match */
&CC->user, towhere);
c = getroom(&QRscratch, augmented_roomname);
if (c == 0)
- strcpy(towhere, augmented_roomname);
+ safestrncpy(towhere, augmented_roomname, sizeof towhere);
}
/* And if the room was found... */
*/
void cmd_setr(char *args)
{
- char buf[SIZ];
+ char buf[256];
int new_order = 0;
int r;
int new_floor;
} else {
strcpy(new_name, "");
}
- extract(&new_name[strlen(new_name)], args, 0);
+ extract_token(&new_name[strlen(new_name)], args, 0, '|', (sizeof new_name - strlen(new_name)));
r = CtdlRenameRoom(CC->room.QRname, new_name, new_floor);
lgetroom(&CC->room, CC->room.QRname);
/* Directory room */
- extract(buf, args, 2);
+ extract_token(buf, args, 2, '|', sizeof buf);
buf[15] = 0;
safestrncpy(CC->room.QRdirname, buf,
sizeof CC->room.QRdirname);
if (num_parms(args) >= 7)
CC->room.QRorder = (char) new_order;
/* Room password */
- extract(buf, args, 1);
+ extract_token(buf, args, 1, '|', sizeof buf);
buf[10] = 0;
safestrncpy(CC->room.QRpasswd, buf,
sizeof CC->room.QRpasswd);
/* Create a room directory if necessary */
if (CC->room.QRflags & QR_DIRECTORY) {
- snprintf(buf, sizeof buf, "./files/%s",
- CC->room.QRdirname);
+ snprintf(buf, sizeof buf, "./files/%s", CC->room.QRdirname);
mkdir(buf, 0755);
}
snprintf(buf, sizeof buf, "%s> edited by %s\n", CC->room.QRname, CC->curr_user);
void cmd_cre8(char *args)
{
int cre8_ok;
- char new_room_name[SIZ];
+ char new_room_name[ROOMNAMELEN];
int new_room_type;
- char new_room_pass[SIZ];
+ char new_room_pass[32];
int new_room_floor;
int new_room_view;
- char aaa[SIZ];
+ char *notification_message = NULL;
unsigned newflags;
struct floor *fl;
int avoid_access = 0;
cre8_ok = extract_int(args, 0);
- extract(new_room_name, args, 1);
+ extract_token(new_room_name, args, 1, '|', sizeof new_room_name);
new_room_name[ROOMNAMELEN - 1] = 0;
new_room_type = extract_int(args, 2);
- extract(new_room_pass, args, 3);
+ extract_token(new_room_pass, args, 3, '|', sizeof new_room_pass);
avoid_access = extract_int(args, 5);
new_room_view = extract_int(args, 6);
new_room_pass[9] = 0;
new_room_view);
/* post a message in Aide> describing the new room */
- safestrncpy(aaa, new_room_name, sizeof aaa);
- strcat(aaa, "> created by ");
- strcat(aaa, CC->user.fullname);
- if (newflags & QR_MAILBOX)
- strcat(aaa, " [personal]");
- else if (newflags & QR_PRIVATE)
- strcat(aaa, " [private]");
- if (newflags & QR_GUESSNAME)
- strcat(aaa, "[guessname] ");
- if (newflags & QR_PASSWORDED) {
- strcat(aaa, "\n Password: ");
- strcat(aaa, new_room_pass);
- }
- strcat(aaa, "\n");
- aide_message(aaa);
+ notification_message = malloc(1024);
+ snprintf(notification_message, 1024,
+ "%s> created by %s%s%s%s%s%s\n",
+ new_room_name,
+ CC->user.fullname,
+ ((newflags & QR_MAILBOX) ? " [personal]" : ""),
+ ((newflags & QR_PRIVATE) ? " [private]" : ""),
+ ((newflags & QR_GUESSNAME) ? " [hidden]" : ""),
+ ((newflags & QR_PASSWORDED) ? " Password: " : ""),
+ ((newflags & QR_PASSWORDED) ? new_room_pass : "")
+ );
+ aide_message(notification_message);
+ free(notification_message);
cprintf("%d '%s' has been created.\n", CIT_OK, new_room_name);
}
*/
void cmd_cflr(char *argbuf)
{
- char new_floor_name[SIZ];
+ char new_floor_name[256];
struct floor flbuf;
int cflr_ok;
int free_slot = (-1);
int a;
- extract(new_floor_name, argbuf, 0);
+ extract_token(new_floor_name, argbuf, 0, '|', sizeof new_floor_name);
cflr_ok = extract_int(argbuf, 1);
if (CtdlAccessCheck(ac_aide)) return;
return;
}
if (np >= 2)
- extract(flbuf.f_name, argbuf, 1);
+ extract_token(flbuf.f_name, argbuf, 1, '|', sizeof flbuf.f_name);
lputfloor(&flbuf, floor_num);
cprintf("%d Ok\n", CIT_OK);
return;
}
while (*listing && strlen(listing)) {
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
- extract(floorlist[extract_int(buf, 0)], buf, 1);
+ extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
}
free(listing);
}
*/
void roomdir(CtdlIPC *ipc)
{
- char flnm[SIZ];
+ char flnm[256];
char flsz[32];
- char comment[SIZ];
- char buf[SIZ];
+ char comment[256];
+ char buf[256];
char *listing = NULL; /* Returned directory listing */
int r;
return;
}
- extract(comment, buf, 0);
- extract(flnm, buf, 1);
+ extract_token(comment, buf, 0, '|', sizeof comment);
+ extract_token(flnm, buf, 1, '|', sizeof flnm);
pprintf("\nDirectory of %s on %s\n", flnm, comment);
pprintf("-----------------------\n");
while (*listing && strlen(listing)) {
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
- extract(flnm, buf, 0);
- extract(flsz, buf, 1);
- extract(comment, buf, 2);
+ extract_token(flnm, buf, 0, '|', sizeof flnm);
+ extract_token(flsz, buf, 1, '|', sizeof flsz);
+ extract_token(comment, buf, 2, '|', sizeof comment);
if (strlen(flnm) <= 14)
pprintf("%-14s %8s %s\n", flnm, flsz, comment);
else
*/
void whoknows(CtdlIPC *ipc)
{
- char buf[SIZ];
+ char buf[256];
char *listing = NULL;
int r;
return;
}
while (strlen(listing) > 0) {
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
if (sigcaught == 0)
pprintf("%s\n", buf);
{ /* register with name and address */
char buf[SIZ];
- char tmpname[SIZ];
- char tmpaddr[SIZ];
- char tmpcity[SIZ];
- char tmpstate[SIZ];
- char tmpzip[SIZ];
- char tmpphone[SIZ];
+ char tmpname[30];
+ char tmpaddr[25];
+ char tmpcity[15];
+ char tmpstate[3];
+ char tmpzip[11];
+ char tmpphone[15];
char tmpemail[SIZ];
- char tmpcountry[SIZ];
- char diruser[SIZ];
- char dirnode[SIZ];
+ char tmpcountry[32];
+ char diruser[256];
+ char dirnode[256];
char holdemail[SIZ];
char *reg = NULL;
int ok = 0;
while (reg && strlen(reg) > 0) {
- extract_token(buf, reg, 0, '\n');
+ extract_token(buf, reg, 0, '\n', sizeof buf);
remove_token(reg, 0, '\n');
if (a == 2)
- strcpy(tmpname, buf);
+ safestrncpy(tmpname, buf, sizeof tmpname);
else if (a == 3)
- strcpy(tmpaddr, buf);
+ safestrncpy(tmpaddr, buf, sizeof tmpaddr);
else if (a == 4)
- strcpy(tmpcity, buf);
+ safestrncpy(tmpcity, buf, sizeof tmpcity);
else if (a == 5)
- strcpy(tmpstate, buf);
+ safestrncpy(tmpstate, buf, sizeof tmpstate);
else if (a == 6)
- strcpy(tmpzip, buf);
+ safestrncpy(tmpzip, buf, sizeof tmpzip);
else if (a == 7)
- strcpy(tmpphone, buf);
+ safestrncpy(tmpphone, buf, sizeof tmpphone);
else if (a == 9)
- strcpy(tmpemail, buf);
+ safestrncpy(tmpemail, buf, sizeof tmpemail);
else if (a == 10)
- strcpy(tmpcountry, buf);
+ safestrncpy(tmpcountry, buf, sizeof tmpcountry);
++a;
}
}
do {
ok = 1;
- strcpy(holdemail, tmpemail);
+ safestrncpy(holdemail, tmpemail, sizeof holdemail);
strprompt("Email address", tmpemail, 31);
r = CtdlIPCDirectoryLookup(ipc, tmpemail, buf);
if (r / 100 == 2) {
- extract_token(diruser, buf, 0, '@');
- extract_token(dirnode, buf, 1, '@');
+ extract_token(diruser, buf, 0, '@', sizeof diruser);
+ extract_token(dirnode, buf, 1, '@', sizeof dirnode);
striplt(diruser);
striplt(dirnode);
if ((strcasecmp(diruser, fullname))
"It is already in use by %s @ %s.\n",
diruser, dirnode);
ok = 0;
- strcpy(tmpemail, holdemail);
+ safestrncpy(tmpemail, holdemail, sizeof tmpemail);
}
}
} while (ok == 0);
/* now send the registration info back to the server */
- reg = (char *)realloc(reg, 4096); /* Overkill? */
+ reg = (char *)realloc(reg, SIZ);
if (reg) {
sprintf(reg, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
tmpname, tmpaddr, tmpcity, tmpstate,
if (haschar(tbuf, '/'))
extract_token(tbuf, flnm,
num_tokens(tbuf, '/') - 1,
- '/'
+ '/', sizeof tbuf
);
/* filename.1, filename.2, etc */
if (a > 0) {
if (r / 100 == 1) {
a = 0;
do {
- extract_token(buf, resp, 0, '\n');
+ extract_token(buf, resp, 0, '\n', sizeof buf);
remove_token(resp, 0, '\n');
++a;
if (a == 1)
if (r / 100 == 2)
scr_printf("%s\n", cmd);
if (r / 100 == 3) {
- extract(buf, cmd, 0);
+ extract_token(buf, cmd, 0, '|', sizeof buf);
if (val_user(ipc, buf, 1) != 0) finished = 1;
}
} while (finished == 0);
return;
}
while (strlen(resp)) {
- extract_token(buf, resp, 0, '\n');
+ extract_token(buf, resp, 0, '\n', sizeof buf);
remove_token(resp, 0, '\n');
if ((pos + strlen(buf) + 5) > screenwidth) {
pprintf("\n");
return;
}
while (strlen(resp)) {
- extract_token(buf, resp, 0, '\n');
+ extract_token(buf, resp, 0, '\n', sizeof buf);
remove_token(resp, 0, '\n');
pprintf("%s\n", buf);
}
if (r / 100 == 1) {
a = 0;
while (strlen(resp)) {
- extract_token(buf, resp, 0, '\n');
+ extract_token(buf, resp, 0, '\n', sizeof buf);
remove_token(resp, 0, '\n');
if (a < NUM_CONFIGS) {
strcpy(&sc[a][0], buf);
r = CtdlIPCGetSystemConfigByType(ipc, INTERNETCFG, &resp, buf);
if (r / 100 == 1) {
while (strlen(resp)) {
- extract_token(buf, resp, 0, '\n');
+ extract_token(buf, resp, 0, '\n', sizeof buf);
remove_token(resp, 0, '\n');
++num_recs;
if (num_recs == 1) recs = malloc(sizeof(char *));
for (i=0; i<num_recs; ++i) {
color(DIM_WHITE);
scr_printf("%3d ", i+1);
- extract(buf, recs[i], 0);
+ extract_token(buf, recs[i], 0, '|', sizeof buf);
color(BRIGHT_CYAN);
scr_printf("%-50s ", buf);
- extract(buf, recs[i], 1);
+ extract_token(buf, recs[i], 1, '|', sizeof buf);
color(BRIGHT_MAGENTA);
scr_printf("%-20s\n", buf);
color(DIM_WHITE);
r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
if (r / 100 == 1) {
while(listing && strlen(listing)) {
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
- extract(instr, buf, 0);
+ extract_token(instr, buf, 0, '|', sizeof instr);
if (!strcasecmp(instr, entrytype)) {
tokens = num_tokens(buf, '|');
for (i=1; i<tokens; ++i) {
- extract(addr, buf, i);
+ extract_token(addr, buf, i, '|', sizeof addr);
fprintf(tempfp, "%s", addr);
if (i < (tokens-1)) {
fprintf(tempfp, "|");
r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
if (r / 100 == 1) {
while(listing && strlen(listing)) {
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
- extract(instr, buf, 0);
+ extract_token(instr, buf, 0, '|', sizeof instr);
if (strcasecmp(instr, entrytype)) {
fprintf(changefp, "%s\n", buf);
}
r = CtdlIPCGetSystemConfigByType(ipc, IGNETCFG, &listing, buf);
if (r / 100 == 1) while (*listing && strlen(listing)) {
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
++num_recs;
for (i=0; i<num_recs; ++i) {
color(DIM_WHITE);
scr_printf("%3d ", i+1);
- extract(buf, recs[i], 0);
+ extract_token(buf, recs[i], 0, '|', sizeof buf);
color(BRIGHT_CYAN);
scr_printf("%-16s ", buf);
- extract(buf, recs[i], 1);
+ extract_token(buf, recs[i], 1, '|', sizeof buf);
color(BRIGHT_MAGENTA);
scr_printf("%-18s ", buf);
- extract(buf, recs[i], 2);
+ extract_token(buf, recs[i], 2, '|', sizeof buf);
color(BRIGHT_CYAN);
scr_printf("%-32s ", buf);
- extract(buf, recs[i], 3);
+ extract_token(buf, recs[i], 3, '|', sizeof buf);
color(BRIGHT_MAGENTA);
scr_printf("%-3s\n", buf);
color(DIM_WHITE);
r = CtdlIPCGetSystemConfigByType(ipc, FILTERLIST, &listing, buf);
if (r / 100 == 1) while (*listing && strlen(listing)) {
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
++num_recs;
for (i=0; i<num_recs; ++i) {
color(DIM_WHITE);
scr_printf("%3d ", i+1);
- extract(buf, recs[i], 0);
+ extract_token(buf, recs[i], 0, '|', sizeof buf);
color(BRIGHT_CYAN);
scr_printf("%-28s ", buf);
- extract(buf, recs[i], 1);
+ extract_token(buf, recs[i], 1, '|', sizeof buf);
color(BRIGHT_MAGENTA);
scr_printf("%-28s ", buf);
- extract(buf, recs[i], 2);
+ extract_token(buf, recs[i], 2, '|', sizeof buf);
color(BRIGHT_CYAN);
scr_printf("%-16s\n", buf);
- extract(buf, recs[i], 3);
+ extract_token(buf, recs[i], 3, '|', sizeof buf);
color(DIM_WHITE);
}
void cmd_rbio(char *cmdbuf)
{
struct ctdluser ruser;
- char buf[SIZ];
+ char buf[256];
FILE *fp;
- extract(buf,cmdbuf,0);
- if (getuser(&ruser,buf)!=0) {
+ extract_token(buf, cmdbuf, 0, '|', sizeof buf);
+ if (getuser(&ruser, buf) != 0) {
cprintf("%d No such user.\n",ERROR + NO_SUCH_USER);
return;
}
if (fp == NULL)
cprintf("%s has no bio on file.\n", ruser.fullname);
else {
- while (fgets(buf,256,fp)!=NULL) cprintf("%s",buf);
+ while (fgets(buf, sizeof buf, fp) != NULL) cprintf("%s",buf);
fclose(fp);
}
cprintf("000\n");
* list of users who have entered bios
*/
void cmd_lbio(char *cmdbuf) {
- char buf[SIZ];
+ char buf[256];
FILE *ls;
struct ctdluser usbuf;
- ls=popen("cd ./bio; ls","r");
- if (ls==NULL) {
- cprintf("%d Cannot open listing.\n",ERROR + FILE_NOT_FOUND);
+ ls = popen("cd ./bio; ls", "r");
+ if (ls == NULL) {
+ cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
return;
}
- cprintf("%d\n",LISTING_FOLLOWS);
- while (fgets(buf,sizeof buf,ls)!=NULL)
+ cprintf("%d\n", LISTING_FOLLOWS);
+ while (fgets(buf, sizeof buf, ls)!=NULL)
if (getuserbynumber(&usbuf,atol(buf))==0)
- cprintf("%s\n",usbuf.fullname);
+ cprintf("%s\n", usbuf.fullname);
pclose(ls);
cprintf("000\n");
}
icalcomponent *fb = NULL;
int found_user = (-1);
struct recptypes *recp = NULL;
- char buf[SIZ];
- char host[SIZ];
- char type[SIZ];
+ char buf[256];
+ char host[256];
+ char type[256];
int i = 0;
int config_lines = 0;
if (found_user != 0) {
config_lines = num_tokens(inetcfg, '\n');
for (i=0; ((i < config_lines) && (found_user != 0)); ++i) {
- extract_token(buf, inetcfg, i, '\n');
- extract_token(host, buf, 0, '|');
- extract_token(type, buf, 1, '|');
+ extract_token(buf, inetcfg, i, '\n', sizeof buf);
+ extract_token(host, buf, 0, '|', sizeof host);
+ extract_token(type, buf, 1, '|', sizeof type);
if ( (!strcasecmp(type, "localhost"))
|| (!strcasecmp(type, "directory")) ) {
*/
void cmd_ical(char *argbuf)
{
- char subcmd[SIZ];
+ char subcmd[64];
long msgnum;
- char partnum[SIZ];
- char action[SIZ];
- char who[SIZ];
+ char partnum[256];
+ char action[256];
+ char who[256];
- extract(subcmd, argbuf, 0);
+ extract_token(subcmd, argbuf, 0, '|', sizeof subcmd);
/* Allow "test" and "freebusy" subcommands without logging in. */
}
if (!strcasecmp(subcmd, "freebusy")) {
- extract(who, argbuf, 1);
+ extract_token(who, argbuf, 1, '|', sizeof who);
ical_freebusy(who);
return;
}
if (!strcasecmp(subcmd, "respond")) {
msgnum = extract_long(argbuf, 1);
- extract(partnum, argbuf, 2);
- extract(action, argbuf, 3);
+ extract_token(partnum, argbuf, 2, '|', sizeof partnum);
+ extract_token(action, argbuf, 3, '|', sizeof action);
ical_respond(msgnum, partnum, action);
return;
}
if (!strcasecmp(subcmd, "handle_rsvp")) {
msgnum = extract_long(argbuf, 1);
- extract(partnum, argbuf, 2);
- extract(action, argbuf, 3);
+ extract_token(partnum, argbuf, 2, '|', sizeof partnum);
+ extract_token(action, argbuf, 3, '|', sizeof action);
ical_handle_rsvp(msgnum, partnum, action);
return;
}
if (!strcasecmp(subcmd, "conflicts")) {
msgnum = extract_long(argbuf, 1);
- extract(partnum, argbuf, 2);
+ extract_token(partnum, argbuf, 2, '|', sizeof partnum);
ical_conflicts(msgnum, partnum);
return;
}
struct recptypes *valid = NULL;
char attendees_string[SIZ];
int num_attendees = 0;
- char this_attendee[SIZ];
+ char this_attendee[256];
icalproperty *attendee = NULL;
char summary_string[SIZ];
icalproperty *summary = NULL;
strcpy(attendees_string, "");
for (attendee = icalcomponent_get_first_property(the_request, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(the_request, ICAL_ATTENDEE_PROPERTY)) {
if (icalproperty_get_attendee(attendee)) {
- strcpy(this_attendee, icalproperty_get_attendee(attendee) );
+ safestrncpy(this_attendee, icalproperty_get_attendee(attendee), sizeof this_attendee);
if (!strncasecmp(this_attendee, "MAILTO:", 7)) {
strcpy(this_attendee, &this_attendee[7]);
- if (!CtdlIsMe(this_attendee)) { /* don't send an invitation to myself! */
+ if (!CtdlIsMe(this_attendee, sizeof this_attendee)) { /* don't send an invitation to myself! */
snprintf(&attendees_string[strlen(attendees_string)],
sizeof(attendees_string) - strlen(attendees_string),
"%s, ",
* If the user saving the event is listed as the
* organizer, then send out invitations.
*/
- if (CtdlIsMe(organizer_string)) {
+ if (CtdlIsMe(organizer_string, sizeof organizer_string)) {
ical_send_out_invitations(cal);
}
}
void cmd_sexp(char *argbuf)
{
int message_sent = 0;
- char x_user[SIZ];
- char x_msg[SIZ];
+ char x_user[USERNAME_SIZE];
+ char x_msg[1024];
char *lun; /* <bc> */
char *x_big_msgbuf = NULL;
else
lun = CC->user.fullname;
- extract(x_user, argbuf, 0);
-
- extract(x_msg, argbuf, 1);
+ extract_token(x_user, argbuf, 0, '|', sizeof x_user);
+ extract_token(x_msg, argbuf, 1, '|', sizeof x_msg);
if (!x_user[0]) {
cprintf("%d You were not previously paged.\n", ERROR + NO_SUCH_USER);
if (conf != NULL) {
do {
- extract_token(buf, conf, 0, '\n');
+ extract_token(buf, conf, 0, '\n', sizeof buf);
strcpy(conf, &conf[strlen(buf)+1]);
} while ( (strlen(conf)>0) && (strlen(buf)>0) );
n = num_tokens(conf, '\n');
for (i=0; i<n; ++i) {
- extract_token(buf, conf, i, '\n');
+ extract_token(buf, conf, i, '\n', sizeof buf);
sptr = malloc(sizeof(struct spamstrings_t));
sptr->string = strdup(buf);
sptr->next = spamstrings;
int have_addr = 0;
int have_cn = 0;
- char givenname[SIZ];
- char sn[SIZ];
- char uid[SIZ];
- char street[SIZ];
- char city[SIZ];
- char state[SIZ];
- char zipcode[SIZ];
- char calFBURL[SIZ];
+ char givenname[128];
+ char sn[128];
+ char uid[256];
+ char street[256];
+ char city[128];
+ char state[3];
+ char zipcode[10];
+ char calFBURL[256];
if (dirserver == NULL) return;
if (msg == NULL) return;
if (v->numprops) for (i=0; i<(v->numprops); ++i) if (striplt(v->prop[i].value), strlen(v->prop[i].value) > 0) {
if (!strcasecmp(v->prop[i].name, "n")) {
- extract_token(sn, v->prop[i].value, 0, ';');
- extract_token(givenname, v->prop[i].value, 1, ';');
+ extract_token(sn, v->prop[i].value, 0, ';', sizeof sn);
+ extract_token(givenname, v->prop[i].value, 1, ';', sizeof givenname);
}
if (!strcasecmp(v->prop[i].name, "fn")) {
have_addr = 1;
strcpy(street, "");
extract_token(&street[strlen(street)],
- v->prop[i].value, 0, ';'); /* po box */
+ v->prop[i].value, 0, ';', (sizeof street - strlen(street))); /* po box */
strcat(street, " ");
extract_token(&street[strlen(street)],
- v->prop[i].value, 1, ';'); /* extend addr */
+ v->prop[i].value, 1, ';', (sizeof street - strlen(street))); /* extend addr */
strcat(street, " ");
extract_token(&street[strlen(street)],
- v->prop[i].value, 2, ';'); /* street */
+ v->prop[i].value, 2, ';', (sizeof street - strlen(street))); /* street */
striplt(street);
- extract_token(city, v->prop[i].value, 3, ';');
- extract_token(state, v->prop[i].value, 4, ';');
- extract_token(zipcode, v->prop[i].value, 5, ';');
+ extract_token(city, v->prop[i].value, 3, ';', sizeof city);
+ extract_token(state, v->prop[i].value, 4, ';', sizeof state);
+ extract_token(zipcode, v->prop[i].value, 5, ';', sizeof zipcode);
attrs = realloc(attrs, (sizeof(LDAPMod *) * ++num_attrs) );
attrs[num_attrs-1] = malloc(sizeof(LDAPMod));
void do_subscribe(char *room, char *email, char *subtype, char *webpage) {
struct ctdlroom qrbuf;
FILE *ncfp;
- char filename[SIZ];
- char token[SIZ];
- char confirmation_request[SIZ];
- char buf[SIZ];
- char urlroom[SIZ];
- char scancmd[SIZ];
- char scanemail[SIZ];
+ char filename[256];
+ char token[256];
+ char confirmation_request[512];
+ char buf[512];
+ char urlroom[ROOMNAMELEN];
+ char scancmd[64];
+ char scanemail[256];
int found_sub = 0;
if (getroom(&qrbuf, room) != 0) {
if (ncfp != NULL) {
while (fgets(buf, sizeof buf, ncfp) != NULL) {
buf[strlen(buf)-1] = 0;
- extract(scancmd, buf, 0);
- extract(scanemail, buf, 1);
+ extract_token(scancmd, buf, 0, '|', sizeof scancmd);
+ extract_token(scanemail, buf, 1, '|', sizeof scanemail);
if ((!strcasecmp(scancmd, "listrecp"))
|| (!strcasecmp(scancmd, "digestrecp"))) {
if (!strcasecmp(scanemail, email)) {
void do_unsubscribe(char *room, char *email, char *webpage) {
struct ctdlroom qrbuf;
FILE *ncfp;
- char filename[SIZ];
- char token[SIZ];
- char buf[SIZ];
- char confirmation_request[SIZ];
- char urlroom[SIZ];
- char scancmd[SIZ];
- char scanemail[SIZ];
+ char filename[256];
+ char token[256];
+ char buf[512];
+ char confirmation_request[512];
+ char urlroom[ROOMNAMELEN];
+ char scancmd[256];
+ char scanemail[256];
int found_sub = 0;
if (getroom(&qrbuf, room) != 0) {
if (ncfp != NULL) {
while (fgets(buf, sizeof buf, ncfp) != NULL) {
buf[strlen(buf)-1] = 0;
- extract(scancmd, buf, 0);
- extract(scanemail, buf, 1);
+ extract_token(scancmd, buf, 0, '|', sizeof scancmd);
+ extract_token(scanemail, buf, 1, '|', sizeof scanemail);
if ((!strcasecmp(scancmd, "listrecp"))
|| (!strcasecmp(scancmd, "digestrecp"))) {
if (!strcasecmp(scanemail, email)) {
void do_confirm(char *room, char *token) {
struct ctdlroom qrbuf;
FILE *ncfp;
- char filename[SIZ];
- char line_token[SIZ];
+ char filename[256];
+ char line_token[256];
long line_offset;
int line_length;
- char buf[SIZ];
- char cmd[SIZ];
- char email[SIZ];
- char subtype[SIZ];
+ char buf[512];
+ char cmd[256];
+ char email[256];
+ char subtype[128];
int success = 0;
- char address_to_unsubscribe[SIZ];
- char scancmd[SIZ];
- char scanemail[SIZ];
+ char address_to_unsubscribe[256];
+ char scancmd[256];
+ char scanemail[256];
char *holdbuf = NULL;
int linelen = 0;
int buflen = 0;
(fgets(buf, sizeof buf, ncfp) != NULL) ) {
buf[strlen(buf)-1] = 0;
line_length = strlen(buf);
- extract(cmd, buf, 0);
+ extract_token(cmd, buf, 0, '|', sizeof cmd);
if (!strcasecmp(cmd, "subpending")) {
- extract(email, buf, 1);
- extract(subtype, buf, 2);
- extract(line_token, buf, 3);
+ extract_token(email, buf, 1, '|', sizeof email);
+ extract_token(subtype, buf, 2, '|', sizeof subtype);
+ extract_token(line_token, buf, 3, '|', sizeof line_token);
if (!strcasecmp(token, line_token)) {
if (!strcasecmp(subtype, "digest")) {
- strcpy(buf, "digestrecp|");
+ safestrncpy(buf, "digestrecp|", sizeof buf);
}
else {
- strcpy(buf, "listrecp|");
+ safestrncpy(buf, "listrecp|", sizeof buf);
}
strcat(buf, email);
strcat(buf, "|");
}
}
if (!strcasecmp(cmd, "unsubpending")) {
- extract(line_token, buf, 2);
+ extract_token(line_token, buf, 2, '|', sizeof line_token);
if (!strcasecmp(token, line_token)) {
- extract(address_to_unsubscribe, buf, 1);
+ extract_token(address_to_unsubscribe, buf, 1, '|',
+ sizeof address_to_unsubscribe);
}
}
}
while (line_offset = ftell(ncfp),
(fgets(buf, sizeof buf, ncfp) != NULL) ) {
buf[strlen(buf)-1]=0;
- extract(scancmd, buf, 0);
- extract(scanemail, buf, 1);
+ extract_token(scancmd, buf, 0, '|', sizeof scancmd);
+ extract_token(scanemail, buf, 1, '|', sizeof scanemail);
if ( (!strcasecmp(scancmd, "listrecp"))
&& (!strcasecmp(scanemail,
address_to_unsubscribe)) ) {
*/
void cmd_subs(char *cmdbuf) {
- char opr[SIZ];
- char room[SIZ];
- char email[SIZ];
- char subtype[SIZ];
- char token[SIZ];
- char webpage[SIZ];
+ char opr[256];
+ char room[ROOMNAMELEN];
+ char email[256];
+ char subtype[256];
+ char token[256];
+ char webpage[256];
- extract(opr, cmdbuf, 0);
+ extract_token(opr, cmdbuf, 0, '|', sizeof opr);
if (!strcasecmp(opr, "subscribe")) {
- extract(subtype, cmdbuf, 3);
+ extract_token(subtype, cmdbuf, 3, '|', sizeof subtype);
if ( (strcasecmp(subtype, "list"))
&& (strcasecmp(subtype, "digest")) ) {
cprintf("%d Invalid subscription type '%s'\n",
ERROR + ILLEGAL_VALUE, subtype);
}
else {
- extract(room, cmdbuf, 1);
- extract(email, cmdbuf, 2);
- extract(webpage, cmdbuf, 4);
+ extract_token(room, cmdbuf, 1, '|', sizeof room);
+ extract_token(email, cmdbuf, 2, '|', sizeof email);
+ extract_token(webpage, cmdbuf, 4, '|', sizeof webpage);
do_subscribe(room, email, subtype, webpage);
}
}
else if (!strcasecmp(opr, "unsubscribe")) {
- extract(room, cmdbuf, 1);
- extract(email, cmdbuf, 2);
- extract(webpage, cmdbuf, 3);
+ extract_token(room, cmdbuf, 1, '|', sizeof room);
+ extract_token(email, cmdbuf, 2, '|', sizeof email);
+ extract_token(webpage, cmdbuf, 3, '|', sizeof webpage);
do_unsubscribe(room, email, webpage);
}
else if (!strcasecmp(opr, "confirm")) {
- extract(room, cmdbuf, 1);
- extract(token, cmdbuf, 2);
+ extract_token(room, cmdbuf, 1, '|', sizeof room);
+ extract_token(token, cmdbuf, 2, '|', sizeof token);
do_confirm(room, token);
}
else {
* Fetch data for MRTG
*/
void cmd_mrtg(char *argbuf) {
- char which[SIZ];
+ char which[32];
- extract(which, argbuf, 0);
+ extract_token(which, argbuf, 0, '|', sizeof which);
if (!strcasecmp(which, "users")) {
mrtg_users();
/* Use the string tokenizer to grab one line at a time */
for (i=0; i<num_tokens(serialized_list, '\n'); ++i) {
- extract_token(buf, serialized_list, i, '\n');
+ extract_token(buf, serialized_list, i, '\n', sizeof buf);
nptr = (struct FilterList *) malloc(sizeof(struct FilterList));
- extract(nptr->fl_user, buf, 0);
+ extract_token(nptr->fl_user, buf, 0, '|', sizeof nptr->fl_user);
striplt(nptr->fl_user);
- extract(nptr->fl_room, buf, 1);
+ extract_token(nptr->fl_room, buf, 1, '|', sizeof nptr->fl_room);
striplt(nptr->fl_room);
- extract(nptr->fl_node, buf, 2);
+ extract_token(nptr->fl_node, buf, 2, '|', sizeof nptr->fl_node);
striplt(nptr->fl_node);
/* Cowardly refuse to add an any/any/any entry that would
/* Use the string tokenizer to grab one line at a time */
for (i=0; i<num_tokens(serialized_map, '\n'); ++i) {
- extract_token(buf, serialized_map, i, '\n');
+ extract_token(buf, serialized_map, i, '\n', sizeof buf);
nmptr = (struct NetMap *) malloc(sizeof(struct NetMap));
- extract(nmptr->nodename, buf, 0);
+ extract_token(nmptr->nodename, buf, 0, '|', sizeof nmptr->nodename);
nmptr->lastcontact = extract_long(buf, 1);
- extract(nmptr->nexthop, buf, 2);
+ extract_token(nmptr->nexthop, buf, 2, '|', sizeof nmptr->nexthop);
nmptr->next = the_netmap;
the_netmap = nmptr;
}
/* Use the string tokenizer to grab one line at a time */
for (i=0; i<num_tokens(working_ignetcfg, '\n'); ++i) {
- extract_token(linebuf, working_ignetcfg, i, '\n');
- extract(buf, linebuf, 0);
+ extract_token(linebuf, working_ignetcfg, i, '\n', sizeof linebuf);
+ extract_token(buf, linebuf, 0, '|', sizeof buf);
if (!strcasecmp(buf, node)) {
if (nexthop != NULL) {
strcpy(nexthop, "");
}
if (secret != NULL) {
- extract(secret, linebuf, 1);
+ extract_token(secret, linebuf, 1, '|', 256);
}
retval = 0;
}
bang = num_tokens(msg->cm_fields['P'], '!');
if (bang > 1) for (i=0; i<(bang-1); ++i) {
extract_token(buf, msg->cm_fields['P'],
- i, '!');
+ i, '!', sizeof buf);
if (!strcasecmp(buf, mptr->remote_nodename)) {
send = 0;
}
char filename[SIZ];
char buf[SIZ];
char instr[SIZ];
- char nodename[SIZ];
- char roomname[SIZ];
- char nexthop[SIZ];
+ char nodename[256];
+ char roomname[ROOMNAMELEN];
+ char nexthop[256];
FILE *fp;
struct SpoolControl sc;
struct namelist *nptr = NULL;
while (fgets(buf, sizeof buf, fp) != NULL) {
buf[strlen(buf)-1] = 0;
- extract(instr, buf, 0);
+ extract_token(instr, buf, 0, '|', sizeof instr);
if (!strcasecmp(instr, "lastsent")) {
sc.lastsent = extract_long(buf, 1);
}
nptr = (struct namelist *)
malloc(sizeof(struct namelist));
nptr->next = sc.listrecps;
- extract(nptr->name, buf, 1);
+ extract_token(nptr->name, buf, 1, '|', sizeof nptr->name);
sc.listrecps = nptr;
}
else if (!strcasecmp(instr, "participate")) {
nptr = (struct namelist *)
malloc(sizeof(struct namelist));
nptr->next = sc.participates;
- extract(nptr->name, buf, 1);
+ extract_token(nptr->name, buf, 1, '|', sizeof nptr->name);
sc.participates = nptr;
}
else if (!strcasecmp(instr, "digestrecp")) {
nptr = (struct namelist *)
malloc(sizeof(struct namelist));
nptr->next = sc.digestrecps;
- extract(nptr->name, buf, 1);
+ extract_token(nptr->name, buf, 1, '|', sizeof nptr->name);
sc.digestrecps = nptr;
}
else if (!strcasecmp(instr, "ignet_push_share")) {
* purge nodes which do not exist from room network
* configurations at this time.
*/
- extract(nodename, buf, 1);
- extract(roomname, buf, 2);
+ extract_token(nodename, buf, 1, '|', sizeof nodename);
+ extract_token(roomname, buf, 2, '|', sizeof roomname);
strcpy(nexthop, "xxx");
if (is_valid_node(nexthop, NULL, nodename) == 0) {
if (strlen(nexthop) == 0) {
struct SpoolControl sc;
int num_spooled = 0;
int found_node = 0;
- char buf[SIZ];
- char sc_type[SIZ];
- char sc_node[SIZ];
- char sc_room[SIZ];
- char filename[SIZ];
+ char buf[256];
+ char sc_type[256];
+ char sc_node[256];
+ char sc_room[256];
+ char filename[256];
FILE *fp;
/* Grab the configuration line we're looking for */
}
while (fgets(buf, sizeof buf, fp) != NULL) {
buf[strlen(buf)-1] = 0;
- extract(sc_type, buf, 0);
- extract(sc_node, buf, 1);
- extract(sc_room, buf, 2);
+ extract_token(sc_type, buf, 0, '|', sizeof sc_type);
+ extract_token(sc_node, buf, 1, '|', sizeof sc_node);
+ extract_token(sc_room, buf, 2, '|', sizeof sc_room);
if ( (!strcasecmp(sc_type, "ignet_push_share"))
&& (!strcasecmp(sc_node, target_node)) ) {
found_node = 1;
*/
void cmd_nsyn(char *argbuf) {
int num_spooled;
- char target_node[SIZ];
+ char target_node[256];
if (CtdlAccessCheck(ac_aide)) return;
- extract(target_node, argbuf, 0);
+ extract_token(target_node, argbuf, 0, '|', sizeof target_node);
num_spooled = network_sync_to(target_node);
if (num_spooled >= 0) {
cprintf("%d Spooled %d messages.\n", CIT_OK, num_spooled);
* Learn topology from path fields
*/
void network_learn_topology(char *node, char *path) {
- char nexthop[SIZ];
+ char nexthop[256];
struct NetMap *nmptr;
strcpy(nexthop, "");
if (num_tokens(path, '!') < 3) return;
for (nmptr = the_netmap; nmptr != NULL; nmptr = nmptr->next) {
if (!strcasecmp(nmptr->nodename, node)) {
- extract_token(nmptr->nexthop, path, 0, '!');
+ extract_token(nmptr->nexthop, path, 0, '!', sizeof nmptr->nexthop);
nmptr->lastcontact = time(NULL);
return;
}
nmptr = (struct NetMap *) malloc(sizeof (struct NetMap));
strcpy(nmptr->nodename, node);
nmptr->lastcontact = time(NULL);
- extract_token(nmptr->nexthop, path, 0, '!');
+ extract_token(nmptr->nexthop, path, 0, '!', sizeof nmptr->nexthop);
nmptr->next = the_netmap;
the_netmap = nmptr;
}
*/
void network_poll_other_citadel_nodes(int full_poll) {
int i;
- char linebuf[SIZ];
+ char linebuf[256];
char node[SIZ];
- char host[SIZ];
- char port[SIZ];
- char secret[SIZ];
+ char host[256];
+ char port[256];
+ char secret[256];
int poll = 0;
- char spoolfile[SIZ];
+ char spoolfile[256];
if (working_ignetcfg == NULL) {
lprintf(CTDL_DEBUG, "No nodes defined - not polling\n");
/* Use the string tokenizer to grab one line at a time */
for (i=0; i<num_tokens(working_ignetcfg, '\n'); ++i) {
- extract_token(linebuf, working_ignetcfg, i, '\n');
- extract(node, linebuf, 0);
- extract(secret, linebuf, 1);
- extract(host, linebuf, 2);
- extract(port, linebuf, 3);
+ extract_token(linebuf, working_ignetcfg, i, '\n', sizeof linebuf);
+ extract_token(node, linebuf, 0, '|', sizeof node);
+ extract_token(secret, linebuf, 1, '|', sizeof secret);
+ extract_token(host, linebuf, 2, '|', sizeof host);
+ extract_token(port, linebuf, 3, '|', sizeof port);
if ( (strlen(node) > 0) && (strlen(secret) > 0)
&& (strlen(host) > 0) && strlen(port) > 0) {
poll = full_poll;
if (poll == 0) {
- sprintf(spoolfile, "./network/spoolout/%s",
- node);
+ snprintf(spoolfile, sizeof spoolfile,
+ "./network/spoolout/%s", node);
if (access(spoolfile, R_OK) == 0) {
poll = 1;
}
*/
void cmd_netp(char *cmdbuf)
{
- char node[SIZ];
- char pass[SIZ];
+ char node[256];
+ char pass[256];
int v;
- char secret[SIZ];
- char nexthop[SIZ];
+ char secret[256];
+ char nexthop[256];
/* Authenticate */
- extract(node, cmdbuf, 0);
- extract(pass, cmdbuf, 1);
+ extract_token(node, cmdbuf, 0, '|', sizeof node);
+ extract_token(pass, cmdbuf, 1, '|', sizeof pass);
if (doing_queue) {
lprintf(CTDL_WARNING, "Network node <%s> refused - spooling", node);
void cmd_pas2(char *argbuf)
{
- char pw[SIZ];
+ char pw[256];
char hexstring[MD5_HEXSTRING_SIZE];
return;
}
- extract(pw, argbuf, 0);
+ extract_token(pw, argbuf, 0, '|', sizeof pw);
if (getuser(&CC->user, CC->curr_user))
{
*/
void cmd_rchg(char *argbuf)
{
- char newroomname[SIZ];
+ char newroomname[ROOMNAMELEN];
- extract(newroomname, argbuf, 0);
+ extract_token(newroomname, argbuf, 0, '|', sizeof newroomname);
newroomname[ROOMNAMELEN-1] = 0;
if (strlen(newroomname) > 0) {
safestrncpy(CC->fake_roomname, newroomname,
sizeof(CC->fake_roomname) );
- }
+ }
else {
- strcpy(CC->fake_roomname, "");
- }
+ safestrncpy(CC->fake_roomname, "", sizeof CC->fake_roomname);
+ }
cprintf("%d OK\n", CIT_OK);
}
*/
void cmd_hchg(char *argbuf)
{
- char newhostname[SIZ];
+ char newhostname[64];
- extract(newhostname, argbuf, 0);
+ extract_token(newhostname, argbuf, 0, '|', sizeof newhostname);
if (strlen(newhostname) > 0) {
safestrncpy(CC->fake_hostname, newhostname,
sizeof(CC->fake_hostname) );
- }
+ }
else {
- strcpy(CC->fake_hostname, "");
- }
+ safestrncpy(CC->fake_hostname, "", sizeof CC->fake_hostname);
+ }
cprintf("%d OK\n", CIT_OK);
}
void cmd_uchg(char *argbuf)
{
- char newusername[SIZ];
+ char newusername[USERNAME_SIZE];
- extract(newusername, argbuf, 0);
+ extract_token(newusername, argbuf, 0, '|', sizeof newusername);
if (CtdlAccessCheck(ac_aide)) return;
*
*/
void smtp_auth(char *argbuf) {
- char buf[SIZ];
- char method[SIZ];
- char encoded_authstring[SIZ];
- char decoded_authstring[SIZ];
- char ident[SIZ];
- char user[SIZ];
- char pass[SIZ];
+ char username_prompt[64];
+ char method[64];
+ char encoded_authstring[1024];
+ char decoded_authstring[1024];
+ char ident[256];
+ char user[256];
+ char pass[256];
if (CC->logged_in) {
cprintf("504 5.7.4 Already logged in.\r\n");
return;
}
- extract_token(method, argbuf, 0, ' ');
+ extract_token(method, argbuf, 0, ' ', sizeof method);
if (!strncasecmp(method, "login", 5) ) {
if (strlen(argbuf) >= 7) {
smtp_get_user(&argbuf[6]);
}
else {
- CtdlEncodeBase64(buf, "Username:", 9);
- cprintf("334 %s\r\n", buf);
+ CtdlEncodeBase64(username_prompt, "Username:", 9);
+ cprintf("334 %s\r\n", username_prompt);
SMTP->command_state = smtp_user;
}
return;
}
if (!strncasecmp(method, "plain", 5) ) {
- extract_token(encoded_authstring, argbuf, 1, ' ');
+ extract_token(encoded_authstring, argbuf, 1, ' ', sizeof encoded_authstring);
CtdlDecodeBase64(decoded_authstring,
encoded_authstring,
strlen(encoded_authstring) );
- strcpy(ident, decoded_authstring);
- strcpy(user, &decoded_authstring[strlen(ident) + 1] );
- strcpy(pass, &decoded_authstring[strlen(ident) + strlen(user) + 2] );
+ safestrncpy(ident, decoded_authstring, sizeof ident);
+ safestrncpy(user, &decoded_authstring[strlen(ident) + 1], sizeof user);
+ safestrncpy(pass, &decoded_authstring[strlen(ident) + strlen(user) + 2], sizeof pass);
if (CtdlLoginExistingUser(user) == login_ok) {
if (CtdlTryPassword(pass) == pass_ok) {
sock = (-1);
for (mx=0; (mx<num_mxhosts && sock < 0); ++mx) {
- extract(buf, mxhosts, mx);
+ extract_token(buf, mxhosts, mx, '|', sizeof buf);
lprintf(CTDL_DEBUG, "Trying <%s>\n", buf);
sock = sock_connect(buf, "25", "tcp");
snprintf(dsn, SIZ, "Could not connect: %s", strerror(errno));
/* See if it's time to give up on delivery of this message */
for (i=0; i<lines; ++i) {
- extract_token(buf, instr, i, '\n');
- extract(key, buf, 0);
- extract(addr, buf, 1);
+ extract_token(buf, instr, i, '\n', sizeof buf);
+ extract_token(key, buf, 0, '|', sizeof key);
+ extract_token(addr, buf, 1, '|', sizeof addr);
if (!strcasecmp(key, "submitted")) {
submitted = atol(addr);
}
* Now go through the instructions checking for stuff.
*/
for (i=0; i<lines; ++i) {
- extract_token(buf, instr, i, '\n');
- extract(key, buf, 0);
- extract(addr, buf, 1);
+ extract_token(buf, instr, i, '\n', sizeof buf);
+ extract_token(key, buf, 0, '|', sizeof key);
+ extract_token(addr, buf, 1, '|', sizeof addr);
status = extract_int(buf, 2);
- extract(dsn, buf, 3);
+ extract_token(dsn, buf, 3, '|', sizeof dsn);
bounce_this = 0;
lprintf(CTDL_DEBUG, "key=<%s> addr=<%s> status=%d dsn=<%s>\n",
lines = num_tokens(instr, '\n');
for (i=0; i<lines; ++i) {
- extract_token(buf, instr, i, '\n');
- extract(key, buf, 0);
- extract(addr, buf, 1);
+ extract_token(buf, instr, i, '\n', sizeof buf);
+ extract_token(key, buf, 0, '|', sizeof key);
+ extract_token(addr, buf, 1, '|', sizeof addr);
status = extract_int(buf, 2);
- extract(dsn, buf, 3);
+ extract_token(dsn, buf, 3, '|', sizeof dsn);
completed = 0;
/* Strip out the headers amd any other non-instruction line */
lines = num_tokens(instr, '\n');
for (i=0; i<lines; ++i) {
- extract_token(buf, instr, i, '\n');
+ extract_token(buf, instr, i, '\n', sizeof buf);
if (num_tokens(buf, '|') < 2) {
remove_token(instr, i, '\n');
--lines;
/* Learn the message ID and find out about recent delivery attempts */
lines = num_tokens(instr, '\n');
for (i=0; i<lines; ++i) {
- extract_token(buf, instr, i, '\n');
- extract(key, buf, 0);
+ extract_token(buf, instr, i, '\n', sizeof buf);
+ extract_token(key, buf, 0, '|', sizeof key);
if (!strcasecmp(key, "msgid")) {
text_msgid = extract_long(buf, 1);
}
*/
lines = num_tokens(instr, '\n');
for (i=0; i<lines; ++i) {
- extract_token(buf, instr, i, '\n');
- extract(key, buf, 0);
- extract(addr, buf, 1);
+ extract_token(buf, instr, i, '\n', sizeof buf);
+ extract_token(key, buf, 0, '|', sizeof key);
+ extract_token(addr, buf, 1, '|', sizeof addr);
status = extract_int(buf, 2);
- extract(dsn, buf, 3);
+ extract_token(dsn, buf, 3, '|', sizeof dsn);
if ( (!strcasecmp(key, "remote"))
&& ((status==0)||(status==3)||(status==4)) ) {
/*****************************************************************************/
void cmd_smtp(char *argbuf) {
- char cmd[SIZ];
- char node[SIZ];
- char buf[SIZ];
+ char cmd[64];
+ char node[256];
+ char buf[1024];
int i;
int num_mxhosts;
if (CtdlAccessCheck(ac_aide)) return;
- extract(cmd, argbuf, 0);
+ extract_token(cmd, argbuf, 0, '|', sizeof cmd);
if (!strcasecmp(cmd, "mx")) {
- extract(node, argbuf, 1);
+ extract_token(node, argbuf, 1, '|', sizeof node);
num_mxhosts = getmx(buf, node);
cprintf("%d %d MX hosts listed for %s\n",
LISTING_FOLLOWS, num_mxhosts, node);
for (i=0; i<num_mxhosts; ++i) {
- extract(node, buf, i);
+ extract_token(node, buf, i, '|', sizeof node);
cprintf("%s\n", node);
}
cprintf("000\n");
/* Try them one by one until we get a working one */
for (sa=0; sa<num_sahosts; ++sa) {
- extract(buf, sahosts, sa);
+ extract_token(buf, sahosts, sa, '|', sizeof buf);
lprintf(CTDL_INFO, "Connecting to SpamAssassin at <%s>\n", buf);
sock = sock_connect(buf, SPAMASSASSIN_PORT, "tcp");
if (sock >= 0) lprintf(CTDL_DEBUG, "Connected!\n");
void cmd_artv(char *cmdbuf) {
- char cmd[SIZ];
+ char cmd[32];
static int is_running = 0;
if (CtdlAccessCheck(ac_internal)) return;
strcpy(artv_tempfilename1, tmpnam(NULL));
strcpy(artv_tempfilename2, tmpnam(NULL));
- extract(cmd, cmdbuf, 0);
+ extract_token(cmd, cmdbuf, 0, '|', sizeof cmd);
if (!strcasecmp(cmd, "export")) artv_do_export();
else if (!strcasecmp(cmd, "import")) artv_do_import();
else cprintf("%d illegal command\n", ERROR + ILLEGAL_VALUE);
struct ctdluser usbuf;
struct vCard *v;
char *s;
- char who[SIZ];
- char adr[SIZ];
- char buf[SIZ];
+ char who[USERNAME_SIZE];
+ char adr[256];
+ char buf[256];
- extract(who, argbuf, 0);
+ extract_token(who, argbuf, 0, '|', sizeof who);
if (!(CC->logged_in)) {
cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
s = vcard_get_prop(v, "adr", 0, 0, 0);
snprintf(adr, sizeof adr, "%s", s ? s : " ");/* address... */
- extract_token(buf, adr, 2, ';');
+ extract_token(buf, adr, 2, ';', sizeof buf);
cprintf("%s\n", buf); /* street */
- extract_token(buf, adr, 3, ';');
+ extract_token(buf, adr, 3, ';', sizeof buf);
cprintf("%s\n", buf); /* city */
- extract_token(buf, adr, 4, ';');
+ extract_token(buf, adr, 4, ';', sizeof buf);
cprintf("%s\n", buf); /* state */
- extract_token(buf, adr, 5, ';');
+ extract_token(buf, adr, 5, ';', sizeof buf);
cprintf("%s\n", buf); /* zip */
s = vcard_get_prop(v, "tel;home", 0, 0, 0);
s = vcard_get_prop(v, "adr", 0, 0, 0);
snprintf(adr, sizeof adr, "%s", s ? s : " ");/* address... */
- extract_token(buf, adr, 6, ';');
+ extract_token(buf, adr, 6, ';', sizeof buf);
cprintf("%s\n", buf); /* country */
cprintf("000\n");
}
* When a user is being created, create his/her vCard.
*/
void vcard_newuser(struct ctdluser *usbuf) {
- char buf[SIZ];
- char vname[SIZ];
+ char buf[256];
+ char vname[256];
- char lastname[SIZ];
- char firstname[SIZ];
- char middlename[SIZ];
- char honorific_prefixes[SIZ];
- char honorific_suffixes[SIZ];
+ char lastname[256];
+ char firstname[256];
+ char middlename[256];
+ char honorific_prefixes[256];
+ char honorific_suffixes[256];
struct vCard *v;
int i;
* fully expanded vCard name based on the number of
* words in the name
*/
- strcpy(lastname, "");
- strcpy(firstname, "");
- strcpy(middlename, "");
- strcpy(honorific_prefixes, "");
- strcpy(honorific_suffixes, "");
+ safestrncpy(lastname, "", sizeof lastname);
+ safestrncpy(firstname, "", sizeof firstname);
+ safestrncpy(middlename, "", sizeof middlename);
+ safestrncpy(honorific_prefixes, "", sizeof honorific_prefixes);
+ safestrncpy(honorific_suffixes, "", sizeof honorific_suffixes);
- strcpy(buf, usbuf->fullname);
+ safestrncpy(buf, usbuf->fullname, sizeof buf);
/* Honorific suffixes */
if (num_tokens(buf, ',') > 1) {
- extract_token(honorific_suffixes, buf, (num_tokens(buf, ' ') - 1), ',');
+ extract_token(honorific_suffixes, buf, (num_tokens(buf, ' ') - 1), ',',
+ sizeof honorific_suffixes);
remove_token(buf, (num_tokens(buf, ',') - 1), ',');
}
/* Find a last name */
- extract_token(lastname, buf, (num_tokens(buf, ' ') - 1), ' ');
+ extract_token(lastname, buf, (num_tokens(buf, ' ') - 1), ' ', sizeof lastname);
remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
/* Find honorific prefixes */
if (num_tokens(buf, ' ') > 2) {
- extract_token(honorific_prefixes, buf, 0, ' ');
+ extract_token(honorific_prefixes, buf, 0, ' ', sizeof honorific_prefixes);
remove_token(buf, 0, ' ');
}
/* Find a middle name */
if (num_tokens(buf, ' ') > 1) {
- extract_token(middlename, buf, (num_tokens(buf, ' ') - 1), ' ');
+ extract_token(middlename, buf, (num_tokens(buf, ' ') - 1), ' ', sizeof middlename);
remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
}
/* Anything left is probably the first name */
- strcpy(firstname, buf);
+ safestrncpy(firstname, buf, sizeof firstname);
striplt(firstname);
/* Compose the structured name */
- sprintf(vname, "%s;%s;%s;%s;%s", lastname, firstname, middlename,
+ snprintf(vname, sizeof vname, "%s;%s;%s;%s;%s", lastname, firstname, middlename,
honorific_prefixes, honorific_suffixes);
lprintf(CTDL_DEBUG, "Converted <%s> to <%s>\n", usbuf->fullname, vname);
* Query Directory
*/
void cmd_qdir(char *argbuf) {
- char citadel_addr[SIZ];
- char internet_addr[SIZ];
+ char citadel_addr[256];
+ char internet_addr[256];
if (CtdlAccessCheck(ac_logged_in)) return;
- extract(internet_addr, argbuf, 0);
+ extract_token(internet_addr, argbuf, 0, '|', sizeof internet_addr);
if (CtdlDirectoryLookup(citadel_addr, internet_addr) != 0) {
cprintf("%d %s was not found.\n",
while(fgets(buf, sizeof buf, fp) != NULL) {
if (num_tokens(buf, ':') == 4) {
- extract_token(entry, buf, 0, ':');
- extract_token(levels, buf, 1, ':');
- extract_token(state, buf, 2, ':');
- extract_token(prog, buf, 3, ':'); /* includes 0x0a LF */
+ extract_token(entry, buf, 0, ':', sizeof entry);
+ extract_token(levels, buf, 1, ':', sizeof levels);
+ extract_token(state, buf, 2, ':', sizeof state);
+ extract_token(prog, buf, 3, ':', sizeof prog); /* includes 0x0a LF */
if (!strcmp(entry, which_entry)) {
strcpy(state, new_state);
} else {
while (fgets(buf, sizeof buf, infp) != NULL) {
buf[strlen(buf) - 1] = 0;
- extract_token(entry, buf, 0, ':');
- extract_token(prog, buf, 3, ':');
+ extract_token(entry, buf, 0, ':', sizeof entry);
+ extract_token(prog, buf, 3, ':', sizeof prog);
if (!strncasecmp(prog, looking_for,
strlen(looking_for))) {
++have_entry;
newtCenteredWindow(76, prompt_window_height, "Question");
form = newtForm(NULL, NULL, 0);
for (i=0; i<num_tokens(question, '\n'); ++i) {
- extract_token(buf, question, i, '\n');
+ extract_token(buf, question, i, '\n', sizeof buf);
newtFormAddComponent(form, newtLabel(1, 1+i, buf));
}
yesbutton = newtButton(10, (prompt_window_height - 4), "Yes");
newtCenteredWindow(76, 10, title);
form = newtForm(NULL, NULL, 0);
for (i=0; i<num_tokens(msgtext, '\n'); ++i) {
- extract_token(buf, msgtext, i, '\n');
+ extract_token(buf, msgtext, i, '\n', sizeof buf);
newtFormAddComponent(form, newtLabel(1, 1+i, buf));
}
newtFormAddComponent(form, newtButton(35, 5, "OK"));
prompt_title);
form = newtForm(NULL, NULL, 0);
for (i=0; i<num_tokens(prompt_text, '\n'); ++i) {
- extract_token(buf, prompt_text, i, '\n');
+ extract_token(buf, prompt_text, i, '\n', sizeof buf);
newtFormAddComponent(form, newtLabel(1, 1+i, buf));
}
newtFormAddComponent(form,
/*
* extract_token() - a string tokenizer
*/
-void extract_token(char *dest, const char *source, int parmnum, char separator)
+void extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen)
{
char *d; /* dest */
const char *s; /* source */
int count = 0;
+ int len = 0;
strcpy(dest, "");
}
if (!s) return; /* Parameter not found */
- for (d = dest; *s && *s != separator; s++, d++) {
+ for (d = dest; *s && *s != separator && ++len<maxlen; s++, d++) {
*d = *s;
}
*d = 0;
*/
int extract_int(const char *source, int parmnum)
{
- char buf[SIZ];
+ char buf[32];
- extract_token(buf, source, parmnum, '|');
+ extract_token(buf, source, parmnum, '|', sizeof buf);
return(atoi(buf));
}
*/
long extract_long(const char *source, int parmnum)
{
- char buf[SIZ];
+ char buf[32];
- extract_token(buf, source, parmnum, '|');
+ extract_token(buf, source, parmnum, '|', sizeof buf);
return(atol(buf));
}
*/
unsigned long extract_unsigned_long(const char *source, int parmnum)
{
- char buf[SIZ];
+ char buf[32];
- extract_token(buf, source, parmnum, '|');
+ extract_token(buf, source, parmnum, '|', sizeof buf);
return strtoul(buf, NULL, 10);
}
*/
num_sets = num_tokens(mset, ',');
for (s=0; s<num_sets; ++s) {
- extract_token(setstr, mset, s, ',');
+ extract_token(setstr, mset, s, ',', sizeof setstr);
- extract_token(lostr, setstr, 0, ':');
+ extract_token(lostr, setstr, 0, ':', sizeof lostr);
if (num_tokens(setstr, ':') >= 2) {
- extract_token(histr, setstr, 1, ':');
+ extract_token(histr, setstr, 1, ':', sizeof histr);
if (!strcmp(histr, "*")) {
snprintf(histr, sizeof histr, "%ld", LONG_MAX);
}
/* $Id$ */
char *safestrncpy(char *dest, const char *src, size_t n);
int num_tokens (const char *source, char tok);
-void extract_token(char *dest, const char *source, int parmnum, char separator);
+void extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
int extract_int (const char *source, int parmnum);
long extract_long (const char *source, int parmnum);
unsigned long extract_unsigned_long(const char *source, int parmnum);
#define strcasecmp(x,y) strncasecmp(x,y,INT_MAX);
#endif
-#define extract(dest,source,parmnum) extract_token(dest,source,parmnum,(char)'|')
#define num_parms(source) num_tokens(source,(char)'|')
void stripout(char *str, char leftboundary, char rightboundary);
void stripallbut(char *str, char leftboundary, char rightboundary);
*/
void cmd_user(char *cmdbuf)
{
- char username[SIZ];
+ char username[256];
int a;
- extract(username, cmdbuf, 0);
+ extract_token(username, cmdbuf, 0, '|', sizeof username);
striplt(username);
a = CtdlLoginExistingUser(username);
void cmd_pass(char *buf)
{
- char password[SIZ];
+ char password[256];
int a;
- extract(password, buf, 0);
+ extract_token(password, buf, 0, '|', sizeof password);
a = CtdlTryPassword(password);
switch (a) {
{
struct ctdluser usbuf;
struct ctdlroom qrbuf;
- char username[SIZ];
+ char username[256];
char mailboxname[ROOMNAMELEN];
uid_t uid;
struct passwd *p = (struct passwd *) getpwnam(username);
if (p != NULL) {
- extract_token(username, p->pw_gecos, 0, ',');
+ extract_token(username, p->pw_gecos, 0, ',', sizeof username);
uid = p->pw_uid;
} else {
uid = (-1);
void cmd_newu(char *cmdbuf)
{
int a;
- char username[SIZ];
+ char username[26];
if (config.c_disable_newu) {
cprintf("%d Self-service user account creation "
ERROR + MAX_SESSIONS_EXCEEDED,
config.c_nodename, config.c_maxsessions);
}
- extract(username, cmdbuf, 0);
+ extract_token(username, cmdbuf, 0, '|', sizeof username);
username[25] = 0;
strproc(username);
void cmd_creu(char *cmdbuf)
{
int a;
- char username[SIZ];
- char password[SIZ];
+ char username[26];
+ char password[32];
struct ctdluser tmp;
if (CtdlAccessCheck(ac_aide)) {
return;
}
- extract(username, cmdbuf, 0);
- extract(password, cmdbuf, 1);
+ extract_token(username, cmdbuf, 0, '|', sizeof username);
+ extract_token(password, cmdbuf, 1, '|', sizeof password);
username[25] = 0;
password[31] = 0;
strproc(username);
*/
void cmd_vali(char *v_args)
{
- char user[SIZ];
+ char user[128];
int newax;
struct ctdluser userbuf;
- extract(user, v_args, 0);
+ extract_token(user, v_args, 0, '|', sizeof user);
newax = extract_int(v_args, 1);
if (CtdlAccessCheck(ac_aide)) {
void cmd_agup(char *cmdbuf)
{
struct ctdluser usbuf;
- char requested_user[SIZ];
+ char requested_user[128];
if (CtdlAccessCheck(ac_aide)) {
return;
}
- extract(requested_user, cmdbuf, 0);
+ extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
if (getuser(&usbuf, requested_user) != 0) {
cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
return;
void cmd_asup(char *cmdbuf)
{
struct ctdluser usbuf;
- char requested_user[SIZ];
+ char requested_user[128];
char notify[SIZ];
int np;
int newax;
if (CtdlAccessCheck(ac_aide))
return;
- extract(requested_user, cmdbuf, 0);
+ extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
if (lgetuser(&usbuf, requested_user) != 0) {
cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
return;
}
np = num_parms(cmdbuf);
if (np > 1)
- extract(usbuf.password, cmdbuf, 1);
+ extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
if (np > 2)
usbuf.flags = extract_int(cmdbuf, 2);
if (np > 3)
printf(" User Name Num L LastCall Calls Posts\n");
printf("------------------------- ----- - ---------- ----- -----\n");
while (strlen(listing) > 0) {
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
- extract(fl,buf,0);
+ extract_token(fl, buf, 0, '|', sizeof fl);
printf("%-25s ",fl);
- printf("%5ld %d ",extract_long(buf,2),
+ printf("%5ld %d ", extract_long(buf,2),
extract_int(buf,1));
lc = extract_long(buf,3);
localtime_r(&lc, &tmbuf);
while (strlen(listing) > 0) {
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
/* Escape some stuff if we're using www mode */
if (www) escapize(buf, sizeof buf);
s_pid = extract_int(buf,0);
- extract(s_user,buf,1);
- extract(s_room,buf,2);
- extract(s_host,buf,3);
- extract(s_client,buf,4);
+ extract_token(s_user, buf, 1, '|', sizeof s_user);
+ extract_token(s_room, buf, 2, '|', sizeof s_room);
+ extract_token(s_host, buf, 3, '|', sizeof s_host);
+ extract_token(s_client, buf, 4, '|', sizeof s_client);
if (s_pid != my_pid) {
if (www) printf("<TR><TD>");