hardcoded size arguments with 'sizeof' based arguments.
* Moved the CitContext destruction into the housekeeper thread and out of the
thread being cancelled. Didn't fix it, though (to see what happens, link
the server against ElectricFence and watch what happens when a session ends).
$Log$
+Revision 1.394 1999/10/26 03:21:16 ajc
+* Changed a lot of strncpy() calls to safestrncpy() and replaced most of their
+ hardcoded size arguments with 'sizeof' based arguments.
+* Moved the CitContext destruction into the housekeeper thread and out of the
+ thread being cancelled. Didn't fix it, though (to see what happens, link
+ the server against ElectricFence and watch what happens when a session ends).
+
Revision 1.393 1999/10/24 19:22:51 nbryant
* Makefile.in, configure.in: added --enable-icq flag; made checks for
authentication libraries more intelligent.
Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
* Initial CVS import
-
*/
void cleanup_stuff(void *arg)
{
+ char buf[256];
lprintf(9, "cleanup_stuff() called\n");
/* Deallocate any user-data attached to this session */
deallocate_user_data(CC);
- /* Now get rid of the session and context */
- lprintf(7, "cleanup_stuff() calling RemoveContext(%d)\n", CC->cs_pid);
- RemoveContext(CC);
+ /* Tell the housekeeping thread to remove the session and context.
+ * This can't be done inline because the context data gets destroyed
+ * halfway through, and the context being destroyed can't be the one
+ * doing the work.
+ */
+ lprintf(7, "Scheduling housekeeper REMOVE_CONTEXT(%d)\n", CC->cs_pid);
+ sprintf(buf, "REMOVE_CONTEXT|%d", CC->cs_pid);
+ enter_housekeeping_cmd(buf);
- /* Wake up the housekeeping thread */
+ /* Tell the housekeeping thread to check to see if this is the time
+ * to initiate a scheduled shutdown event.
+ */
enter_housekeeping_cmd("SCHED_SHUTDOWN");
}
void cmd_rchg(char *argbuf)
{
- char newroomname[256]; /* set to 256 to prevent buffer overruns <dme>*/
+ char newroomname[ROOMNAMELEN];
extract(newroomname, argbuf, 0);
newroomname[ROOMNAMELEN] = 0;
if (strlen(newroomname) > 0) {
- strncpy(CC->fake_roomname, newroomname, ROOMNAMELEN);
+ safestrncpy(CC->fake_roomname, newroomname,
+ sizeof(CC->fake_roomname) );
CC->fake_roomname[ROOMNAMELEN - 1] = 0;
}
else {
if ((newhostname) && (newhostname[0]))
{
memset(CC->fake_hostname, 0, 25);
- strncpy(CC->fake_hostname, newhostname, 24);
+ safestrncpy(CC->fake_hostname, newhostname, sizeof(CC->fake_hostname));
}
else
strcpy(CC->fake_hostname, "");
CC->cs_flags &= ~CS_STEALTH;
memset(CC->fake_username, 0, 32);
if (strncasecmp(newusername, CC->curr_user, strlen(CC->curr_user)))
- strncpy(CC->fake_username, newusername, 31);
+ safestrncpy(CC->fake_username, newusername, sizeof(CC->fake_username));
}
else
{
rev_level = extract_int(argbuf,2);
extract(desc,argbuf,3);
- strncpy(from_host,config.c_fqdn,sizeof from_host);
+ 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);
CC->cs_clientdev = dev_code;
CC->cs_clienttyp = cli_code;
CC->cs_clientver = rev_level;
- strncpy(CC->cs_clientname,desc,31);
+ safestrncpy(CC->cs_clientname, desc, sizeof CC->cs_clientname);
CC->cs_clientname[31] = 0;
lprintf(9, "Looking up hostname\n");
if (inet_aton(from_host, &addr))
locate_host(CC->cs_host, &addr);
else {
- strncpy(CC->cs_host,from_host,24);
+ safestrncpy(CC->cs_host, from_host, sizeof CC->cs_host);
CC->cs_host[24] = 0;
}
}
strcpy(CC->curr_user,"(not logged in)");
strcpy(CC->net_node,"");
snprintf(CC->temp, sizeof CC->temp, tmpnam(NULL));
- strncpy(CC->cs_host, config.c_fqdn, sizeof CC->cs_host);
+ safestrncpy(CC->cs_host, config.c_fqdn, sizeof CC->cs_host);
CC->cs_host[sizeof CC->cs_host - 1] = 0;
len = sizeof sin;
if (!getpeername(CC->client_socket, (struct sockaddr *) &sin, &len))
&& (strncasecmp(cmdbuf, "PEXP", 4))
&& (strncasecmp(cmdbuf, "GEXP", 4)) ) {
strcpy(CC->lastcmdname, " ");
- strncpy(CC->lastcmdname, cmdbuf, 4);
+ safestrncpy(CC->lastcmdname, cmdbuf,
+ sizeof(CC->lastcmdname) );
time(&CC->lastidle);
}
a = 0;
while (client_gets(buf), strcmp(buf, "000")) {
switch(a) {
- case 0: strncpy(config.c_nodename, buf, 16);
+ case 0: safestrncpy(config.c_nodename, buf,
+ sizeof config.c_nodename);
break;
- case 1: strncpy(config.c_fqdn, buf, 64);
+ case 1: safestrncpy(config.c_fqdn, buf,
+ sizeof config.c_fqdn);
break;
- case 2: strncpy(config.c_humannode, buf, 21);
+ case 2: safestrncpy(config.c_humannode, buf,
+ sizeof config.c_humannode);
break;
- case 3: strncpy(config.c_phonenum, buf, 16);
+ case 3: safestrncpy(config.c_phonenum, buf,
+ sizeof config.c_phonenum);
break;
case 4: config.c_creataide = atoi(buf);
break;
if (config.c_twitdetect != 0)
config.c_twitdetect = 1;
break;
- case 9: strncpy(config.c_twitroom,
- buf, ROOMNAMELEN);
+ case 9: safestrncpy(config.c_twitroom, buf,
+ sizeof config.c_twitroom);
break;
- case 10: strncpy(config.c_moreprompt, buf, 80);
+ case 10: safestrncpy(config.c_moreprompt, buf,
+ sizeof config.c_moreprompt);
break;
case 11: config.c_restrict = atoi(buf);
if (config.c_restrict != 0)
config.c_restrict = 1;
break;
- case 12: strncpy(config.c_bbs_city, buf, 32);
+ case 12: safestrncpy(config.c_bbs_city, buf,
+ sizeof config.c_bbs_city);
break;
- case 13: strncpy(config.c_sysadm, buf, 26);
+ case 13: safestrncpy(config.c_sysadm, buf,
+ sizeof config.c_sysadm);
break;
case 14: config.c_maxsessions = atoi(buf);
if (config.c_maxsessions < 1)
config.c_maxsessions = 1;
break;
- case 15: strncpy(config.c_net_password, buf, 20);
+ case 15: safestrncpy(config.c_net_password, buf,
+ sizeof config.c_net_password);
break;
case 16: config.c_userpurge = atoi(buf);
break;
case 17: config.c_roompurge = atoi(buf);
break;
- case 18: strncpy(config.c_logpages,
- buf, ROOMNAMELEN);
+ case 18: safestrncpy(config.c_logpages, buf,
+ sizeof config.c_logpages);
break;
case 19: config.c_createax = atoi(buf);
if (config.c_createax < 1)
exit(1);
}
while ((dptr = readdir(dir)) != NULL) {
- if (dptr->d_name[0] == '.')
+ if (strlen(dptr->d_name) < 4)
+ continue;
+ if (strcasecmp(&dptr->d_name[strlen(dptr->d_name)-3], ".so"))
continue;
snprintf(pathbuf, PATH_MAX, "%s/%s", pathname, dptr->d_name);
fd_set readfds;
int did_something;
char house_cmd[256]; /* Housekeep cmds are always 256 bytes long */
+ char cmd[256];
if (pipe(housepipe) != 0) {
lprintf(1, "FATAL ERROR: can't create housekeeping pipe: %s\n",
strcpy(house_cmd, "MINUTE");
}
+ extract(cmd, house_cmd, 0);
/* Do whatever this cmd requires */
- if (!strcmp(house_cmd, "MINUTE")) {
+
+ /* Once-every-minute housekeeper */
+ if (!strcmp(cmd, "MINUTE")) {
terminate_idle_sessions();
}
- else if (!strcmp(house_cmd, "SCHED_SHUTDOWN")) {
+ /* Scheduled shutdown housekeeper */
+ else if (!strcmp(cmd, "SCHED_SHUTDOWN")) {
check_sched_shutdown();
}
+ /* Remove a context (session ending) */
+ else if (!strcmp(cmd, "REMOVE_CONTEXT")) {
+ RemoveContext( extract_int(house_cmd, 1) );
+ }
+
+ /* Unknown */
else {
lprintf(7, "Unknown housekeeping command\n");
}
buf[strlen(buf) - 1] = 0;
if ((!strncasecmp(buf, flnm, strlen(flnm)))
&& (buf[strlen(flnm)] == ' '))
- strncpy(comment,
- &buf[strlen(flnm) + 1], 255);
+ safestrncpy(comment,
+ &buf[strlen(flnm) + 1],
+ sizeof comment);
}
cprintf("%s|%ld|%s\n", flnm, statbuf.st_size, comment);
}
strcpy(old_name, CC->quickroom.QRname);
extract(buf, args, 0);
buf[ROOMNAMELEN] = 0;
- strncpy(CC->quickroom.QRname, buf, ROOMNAMELEN - 1);
+ safestrncpy(CC->quickroom.QRname, buf, sizeof CC->quickroom.QRname);
extract(buf, args, 1);
buf[10] = 0;
- strncpy(CC->quickroom.QRpasswd, buf, 9);
+ safestrncpy(CC->quickroom.QRpasswd, buf, sizeof CC->quickroom.QRpasswd);
extract(buf, args, 2);
buf[15] = 0;
- strncpy(CC->quickroom.QRdirname, buf, 19);
+ safestrncpy(CC->quickroom.QRdirname, buf,
+ sizeof CC->quickroom.QRdirname);
CC->quickroom.QRflags = (extract_int(args, 3) | QR_INUSE);
if (num_parms(args) >= 7)
CC->quickroom.QRorder = (char) new_order;
return (0); /* already exists */
memset(&qrbuf, 0, sizeof(struct quickroom));
- strncpy(qrbuf.QRname, new_room_name, ROOMNAMELEN);
- strncpy(qrbuf.QRpasswd, new_room_pass, 9);
+ safestrncpy(qrbuf.QRname, new_room_name, sizeof qrbuf.QRname);
+ safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd);
qrbuf.QRflags = QR_INUSE;
qrbuf.QRnumber = get_new_room_number();
if (new_room_type > 0)
new_room_type, new_room_pass, new_room_floor);
/* post a message in Aide> describing the new room */
- strncpy(aaa, new_room_name, 255);
+ safestrncpy(aaa, new_room_name, sizeof aaa);
strcat(aaa, "> created by ");
strcat(aaa, CC->usersupp.fullname);
if (newflags & QR_MAILBOX)
lgetfloor(&flbuf, free_slot);
flbuf.f_flags = F_INUSE;
flbuf.f_ref_count = 0;
- strncpy(flbuf.f_name, new_floor_name, 255);
+ safestrncpy(flbuf.f_name, new_floor_name, sizeof flbuf.f_name);
lputfloor(&flbuf, free_slot);
cprintf("%d %d\n", OK, free_slot);
}
time(&now);
clnew->next = NULL;
clnew->chat_time = now;
- strncpy(clnew->chat_room, roomname, sizeof clnew->chat_room);
+ safestrncpy(clnew->chat_room, roomname, sizeof clnew->chat_room);
clnew->chat_room[sizeof clnew->chat_room - 1] = 0;
if (username) {
- strncpy(clnew->chat_username, username,
+ safestrncpy(clnew->chat_username, username,
sizeof clnew->chat_username);
clnew->chat_username[sizeof clnew->chat_username - 1] = 0;
} else
pthread_key_t MyConKey; /* TSD key for MyContext() */
int msock; /* master listening socket */
-int verbosity = 3; /* Logging level */
+int verbosity = 9; /* Logging level */
struct CitContext masterCC;
/*
* Remove a context from the context list.
*/
-void RemoveContext(struct CitContext *con)
+void RemoveContext(int con)
{
- struct CitContext *ptr;
+ struct CitContext *ptr = NULL;
+ struct CitContext *ToFree = NULL;
lprintf(7, "Starting RemoveContext()\n");
- if (con==NULL) {
- lprintf(7, "WARNING: RemoveContext() called with null!\n");
+ if (con==0) {
+ lprintf(7, "WARNING: RemoveContext() called with 0!\n");
return;
}
* so do not call it from within this loop.
*/
begin_critical_section(S_SESSION_TABLE);
- lprintf(7, "Closing socket %d\n", con->client_socket);
- close(con->client_socket);
- if (ContextList==con) {
+ if (ContextList->client_socket == con) {
+ ToFree = ContextList;
ContextList = ContextList->next;
}
else {
for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
- if (ptr->next == con) {
- ptr->next = con->next;
+ if (ptr->next->client_socket == con) {
+ ToFree = ptr->next;
+ ptr->next = ptr->next->next;
}
}
}
- phree(con);
+
+ lprintf(7, "Closing socket %d\n", ToFree->client_socket);
+ close(ToFree->client_socket);
+ phree(ToFree);
+
end_critical_section(S_SESSION_TABLE);
lprintf(7, "Done with RemoveContext\n");
}
struct CitContext *MyContext (void);
struct CitContext *CreateNewContext (void);
void InitMyContext (struct CitContext *con);
-void RemoveContext (struct CitContext *con);
+void RemoveContext (int con);
int session_count (void);
void client_write (char *buf, int nbytes);
void cprintf (const char *format, ...);