From: Art Cancro Date: Sat, 2 Jan 2016 02:53:16 +0000 (-0500) Subject: Convert netconfigs to configdb entries at startup. X-Git-Tag: Release_902~90 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=54d204b92c87a04aa0952575a1d5e0f17445c967 Convert netconfigs to configdb entries at startup. --- diff --git a/citadel/COPYING b/citadel/COPYING index e9af8ee15..0587b6c23 100644 --- a/citadel/COPYING +++ b/citadel/COPYING @@ -1,5 +1,5 @@ -Copyright: (C) 1987-2015 Citadel development team; GPL V3 +Copyright: (C) 1987-2016 Citadel development team; GPL V3 Copyright for CRC16: (C) 2002-2003 Indigo Systems Corporation; Artistic license + Non advertising clause @@ -9,7 +9,7 @@ Copyright for MD5 implementation: (C) 1993 Colin Plumb; Public Domain Copyright for RFC 2739 openldap schema: (C) 2000 The Internet Society (C) 2004 Martin Konold - (C) 2006 Art Cancro + (C) 2006 Art Cancro * In addition, as a special exception, we hereby declare that our favorite type of software is called "open source" -- NOT "free @@ -18,17 +18,17 @@ Copyright for RFC 2739 openldap schema: Richard Stallman's linguistic fascism. * In addition, as a special exception, the copyright holders give -* permission to link the code of portions of this program with the -* OpenSSL library under certain conditions as described in each -* individual source file, and distribute linked combinations -* including the two. -* You must obey the General Public License in all respects -* for all of the code used other than OpenSSL. If you modify -* file(s) with this exception, you may extend this exception to your -* version of the file(s), but you are not obligated to do so. If you -* do not wish to do so, delete this exception statement from your -* version. If you delete this exception statement from all source -* files in the program, then also delete it here. + permission to link the code of portions of this program with the + OpenSSL library under certain conditions as described in each + individual source file, and distribute linked combinations + including the two. + You must obey the General Public License in all respects + for all of the code used other than OpenSSL. If you modify + file(s) with this exception, you may extend this exception to your + version of the file(s), but you are not obligated to do so. If you + do not wish to do so, delete this exception statement from your + version. If you delete this exception statement from all source + files in the program, then also delete it here. GENERAL PUBLIC LICENSE @@ -41,14 +41,14 @@ Copyright for RFC 2739 openldap schema: The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -General Public License for most of our software; it applies also to +share and change all versions of a program--to make sure it remains open +source for all its users. The Free Software Foundation uses the +General Public License for most of its software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you +price. General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new @@ -70,8 +70,8 @@ know their rights. giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as +that there is no warranty for this open source software. For both users' +and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. @@ -89,9 +89,9 @@ of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. +avoid the special danger that patents applied to an open source program +could make it effectively proprietary. To prevent this, the GPL assures +that patents cannot be used to render the program closed-source. The precise terms and conditions for copying, distribution and modification follow. @@ -163,9 +163,9 @@ produce the work, or an object code interpreter used to run it. the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source +System Libraries, or general-purpose tools or generally available open +source programs which are used unmodified in performing those activities +but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, diff --git a/citadel/netconfig.c b/citadel/netconfig.c index 6dbb94016..1137b2fdf 100644 --- a/citadel/netconfig.c +++ b/citadel/netconfig.c @@ -2,20 +2,22 @@ * This module handles shared rooms, inter-Citadel mail, and outbound * mailing list processing. * - * Copyright (c) 2000-2012 by the citadel.org team + * Copyright (c) 2000-2016 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, version 3. + * This program is open source software; you can redistribute it and/or modify + * 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. + * 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. * */ #include "sysdep.h" #include +#include +#include #ifdef HAVE_SYSCALL_H # include @@ -1188,6 +1190,79 @@ void destroy_network_cfgs(void) DeleteHash(&pCfgTypeHash); } + + + +/* + * Create a config key for a room's netconfig entry + */ +void netcfg_keyname(char *keybuf, long roomnum) +{ + if (!keybuf) return; + sprintf(keybuf, "c_netconfig_%010ld", roomnum); +} + + + + +/* + * Convert any legacy configuration files in the "netconfigs" directory + */ +void convert_legacy_netcfg_files(void) +{ + DIR *dh = NULL; + struct dirent *dit = NULL; + char keyname[25]; + char filename[PATH_MAX]; + long roomnum; + FILE *fp; + long len; + char *v; + + dh = opendir(ctdl_netcfg_dir); + if (!dh) return; + + syslog(LOG_INFO, "Legacy netconfig files exist - converting them!"); + + while (dit = readdir(dh), dit != NULL) { // yes, we use the non-reentrant version; we're not in threaded mode yet + roomnum = atol(dit->d_name); + if (roomnum > 0) { + netcfg_keyname(keyname, roomnum); + snprintf(filename, sizeof filename, "%s/%ld", ctdl_netcfg_dir, roomnum); + fp = fopen(filename, "r"); + if (fp) { + fseek(fp, 0L, SEEK_END); + len = ftell(fp); + v = malloc(len); + if (v) { + rewind(fp); + if (fread(v, len, 1, fp)) { + char *enc = malloc(len * 2); + int enc_len; + if (enc) { + enc_len = CtdlEncodeBase64(enc, v, len, 0); + if ((enc_len > 1) && (enc[enc_len-2] == 13)) enc[enc_len-2] = 0; + if ((enc_len > 0) && (enc[enc_len-1] == 10)) enc[enc_len-1] = 0; + enc[enc_len] = 0; + syslog(LOG_DEBUG, "Writing key '%s' (length=%d)", keyname, enc_len); + CtdlSetConfigStr(keyname, enc); + free(enc); + // unlink(filename); // FIXME uncomment this when ready + fclose(fp); + } + } + free(v); + } + } + } + } + + closedir(dh); + // rmdir(ctdl_netcfg_dir); // FIXME uncomment this when ready +} + + + /* * Module entry point */ @@ -1196,7 +1271,8 @@ CTDL_MODULE_INIT(netconfig) if (!threading) { CtdlRegisterCleanupHook(destroy_network_cfgs); - LoadAllNetConfigs (); + convert_legacy_netcfg_files(); + LoadAllNetConfigs(); CtdlRegisterProtoHook(cmd_gnet, "GNET", "Get network config"); CtdlRegisterProtoHook(cmd_snet, "SNET", "Set network config"); CtdlRegisterProtoHook(cmd_netp, "NETP", "Identify as network poller"); diff --git a/citadel/serv_extensions.h b/citadel/serv_extensions.h index 136be62f1..93c80ab3e 100644 --- a/citadel/serv_extensions.h +++ b/citadel/serv_extensions.h @@ -111,4 +111,6 @@ void CtdlRegisterDebugFlagHook(const char *Name, long len, CtdlDbgFunction F, co void CtdlSetDebugLogFacilities(const char **Str, long n); void CtdlDestroyDebugTable(void); +void netcfg_keyname(char *keybuf, long roomnum); + #endif /* SERV_EXTENSIONS_H */