X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fcitserver.c;h=761947375d2fb08dfa1463b92e779a0e3d74b662;hb=cbefcb9d9b85519fd1b098f622255ea318e78fd7;hp=f0a2d343555395dacac35e0765de2f62cbe9bd5d;hpb=1428e60c50b70d910e8c6d1180208fad2dde48f7;p=citadel.git diff --git a/citadel/citserver.c b/citadel/citserver.c index f0a2d3435..761947375 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -4,18 +4,12 @@ * Copyright (c) 1987-2011 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License, version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "sysdep.h" @@ -71,11 +65,6 @@ #include "euidindex.h" #include "context.h" #include "svn_revision.h" - -#ifndef HAVE_SNPRINTF -#include "snprintf.h" -#endif - #include "ctdl_module.h" char *unique_session_numbers; @@ -169,6 +158,7 @@ void master_startup(void) { syslog(LOG_DEBUG, "master_startup() started\n"); time(&server_startup_time); + get_config(); syslog(LOG_INFO, "Opening databases\n"); open_databases(); @@ -196,6 +186,9 @@ void master_startup(void) { urandom = fopen("/dev/urandom", "r"); if (urandom != NULL) { rv = fread(&seed, sizeof seed, 1, urandom); + if (rv == -1) + syslog(LOG_EMERG, "failed to read random seed: %s\n", + strerror(errno)); fclose(urandom); } else { @@ -205,9 +198,6 @@ void master_startup(void) { srand(seed); srandom(seed); - syslog(LOG_INFO, "Initializing ipgm secret\n"); - get_config(); - config.c_ipgm_secret = rand(); put_config(); syslog(LOG_DEBUG, "master_startup() finished\n"); @@ -221,7 +211,7 @@ void master_cleanup(int exitcode) { struct CleanupFunctionHook *fcn; static int already_cleaning_up = 0; - if (already_cleaning_up) while(1) sleep(1); + if (already_cleaning_up) while(1) usleep(1000000); already_cleaning_up = 1; /* Run any cleanup routines registered by loadable modules */ @@ -343,9 +333,9 @@ void cmd_time(char *argbuf) /* timezone and daylight global variables are not portable. */ #ifdef HAVE_STRUCT_TM_TM_GMTOFF - cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst); + cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst, server_startup_time); #else - cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst); + cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst, server_startup_time); #endif } @@ -430,7 +420,7 @@ int is_public_client(void) } } } - fclose(fp); + if (fp != NULL) fclose(fp); pc_timestamp = time(NULL); end_critical_section(S_PUBLIC_CLIENTS); } @@ -689,14 +679,14 @@ int CtdlAccessCheck(int required_level) { if (CC->user.axlevel >= AxAideU) return(0); if (required_level >= ac_aide) { - cprintf("%d This command requires Aide access.\n", + cprintf("%d This command requires Admin access.\n", ERROR + HIGHER_ACCESS_REQUIRED); return(-1); } if (is_room_aide()) return(0); if (required_level >= ac_room_aide) { - cprintf("%d This command requires Aide or Room Aide access.\n", + cprintf("%d This command requires Admin or Room Admin access.\n", ERROR + HIGHER_ACCESS_REQUIRED); return(-1); } @@ -756,36 +746,6 @@ void cmd_echo(char *etext) } -/* - * Perform privilege escalation for an internal program - */ -void cmd_ipgm(char *argbuf) -{ - int secret; - - secret = extract_int(argbuf, 0); - - /* For security reasons, we do NOT allow this command to run - * over the network. Local sockets only. - */ - if (!CC->is_local_socket) { - sleep(5); - cprintf("%d Authentication failed.\n", ERROR + PASSWORD_REQUIRED); - } - else if (secret == config.c_ipgm_secret) { - CC->internal_pgm = 1; - strcpy(CC->curr_user, ""); - CC->cs_flags = CC->cs_flags|CS_STEALTH; - cprintf("%d Authenticated as an internal program.\n", CIT_OK); - } - else { - sleep(5); - cprintf("%d Authentication failed.\n", ERROR + PASSWORD_REQUIRED); - syslog(LOG_ERR, "Warning: ipgm authentication failed.\n"); - CC->kill_me = KILLME_AUTHFAILED; - } -} - /* * Shut down the server @@ -887,9 +847,6 @@ void cmd_asyn(char *argbuf) */ void begin_session(CitContext *con) { - socklen_t len; - struct sockaddr_in sin; - /* * Initialize some variables specific to our context. */ @@ -914,7 +871,6 @@ void begin_session(CitContext *con) safestrncpy(con->cs_addr, "", sizeof con->cs_addr); con->cs_UDSclientUID = -1; con->cs_host[sizeof con->cs_host - 1] = 0; - len = sizeof sin; if (!CC->is_local_socket) { locate_host(con->cs_host, sizeof con->cs_host, con->cs_addr, sizeof con->cs_addr, @@ -994,6 +950,12 @@ void citproto_begin_session() { } +void citproto_begin_admin_session() { + CC->internal_pgm = 1; + cprintf("%d %s Citadel server ADMIN CONNECTION ready.\n", CIT_OK, config.c_nodename); +} + + void cmd_noop(char *argbuf) { cprintf("%d%cok\n", CIT_OK, CtdlCheckExpress() ); @@ -1108,7 +1070,6 @@ CTDL_MODULE_INIT(citserver) CtdlRegisterProtoHook(cmd_echo, "ECHO", "echo text back to the client"); CtdlRegisterProtoHook(cmd_more, "MORE", "fetch the paginator prompt"); CtdlRegisterProtoHook(cmd_iden, "IDEN", "identify the client software and location"); - CtdlRegisterProtoHook(cmd_ipgm, "IPGM", "perform privilege escalation for internal programs"); CtdlRegisterProtoHook(cmd_term, "TERM", "terminate another running session"); CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown"); CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");