-/*
- * system-level password checking for host auth mode
- * by Nathan Bryant, March 1999
- * updated by Trey van Riper, June 2005
- *
- * Copyright (c) 1999-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 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.
- */
-
-#if defined(__linux) || defined(__sun) /* needed for crypt(): */
+// system-level password checking for host auth mode
+// by Nathan Bryant, March 1999
+// updated by Trey van Riper, June 2005
+//
+// Copyright (c) 1999-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 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.
+
+#if defined(__linux) || defined(__sun) // needed for crypt():
#define _XOPEN_SOURCE
#define _XOPEN_SOURCE_EXTENDED 1
#endif
#ifdef HAVE_PAM_START
#include <security/pam_appl.h>
-/*
- * struct appdata: passed to the conversation function
- */
+// struct appdata: passed to the conversation function
struct appdata {
const char *name;
const char *pw;
};
-/*
- * conv(): the PAM conversation function. this assumes that a
- * PAM_PROMPT_ECHO_ON is asking for a username, and a PAM_PROMPT_ECHO_OFF is
- * asking for a password. esoteric authentication modules will fail with this
- * code, but we can't really support them with the existing client protocol
- * anyway. the failure mode should be to deny access, in any case.
- */
-static int conv(int num_msg, const struct pam_message **msg,
- struct pam_response **resp, void *appdata_ptr)
-{
+// conv(): the PAM conversation function. this assumes that a
+// PAM_PROMPT_ECHO_ON is asking for a username, and a PAM_PROMPT_ECHO_OFF is
+// asking for a password. esoteric authentication modules will fail with this
+// code, but we can't really support them with the existing client protocol
+// anyway. the failure mode should be to deny access, in any case.
+static int conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr) {
struct pam_response *temp_resp;
struct appdata *data = appdata_ptr;
*resp = temp_resp;
return PAM_SUCCESS;
}
-#endif /* HAVE_PAM_START */
+#endif // HAVE_PAM_START
-/*
- * check that `pass' is the correct password for `uid'
- * returns zero if no, nonzero if yes
- */
-int validate_password(uid_t uid, const char *pass)
-{
+// check that `pass' is the correct password for `uid'
+// returns zero if no, nonzero if yes
+int validate_password(uid_t uid, const char *pass) {
if (pass == NULL) {
return (0);
}
if (!strcmp(crypt(pass, crypted_pwd), crypted_pwd)) {
retval = -1;
}
-#endif /* HAVE_PAM_START */
+#endif // HAVE_PAM_START
return retval;
}
-/*
- * Across-the-wire migration utility for Citadel
- *
- * Copyright (c) 2009-2021 citadel.org
- *
- * 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.
- */
+// Across-the-wire migration utility for Citadel
+//
+// Copyright (c) 2009-2021 citadel.org
+//
+// 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.
#include <stdlib.h>
#include <unistd.h>
#include "citadel_dirs.h"
-
// yeah, this wouldn't work in a multithreaded program.
static int gmaxlen = 0;
static char *gdeftext = NULL;
+
+// support function for getz()
static int limit_rl(FILE *dummy) {
if (rl_end > gmaxlen) {
return '\b';
}
+// support function for getz()
static int getz_deftext(void) {
if (gdeftext) {
rl_insert_text(gdeftext);
}
-/*
- * Replacement for gets() that doesn't throw a compiler warning.
- * We're only using it for some simple prompts, so we don't need
- * to worry about attackers exploiting it.
- */
+// Replacement for gets() that uses libreadline.
void getz(char *buf, int maxlen, char *default_value, char *prompt) {
rl_startup_hook = getz_deftext;
rl_getc_function = limit_rl;
}
+// Exit from the program while displaying an error code
void ctdlmigrate_exit(int cmdexit) {
printf("\n\n\033[3%dmExit code %d\033[0m\n", (cmdexit ? 1 : 2), cmdexit);
exit(cmdexit);
}
-/*
- * Connect to a Citadel on a remote host using a TCP/IP socket
- */
+// Connect to a Citadel on a remote host using a TCP/IP socket
static int tcp_connectsock(char *host, char *service) {
struct in6_addr serveraddr;
struct addrinfo hints;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
- /*
- * Handle numeric IPv4 and IPv6 addresses
- */
+ // Handle numeric IPv4 and IPv6 addresses
rc = inet_pton(AF_INET, host, &serveraddr);
- if (rc == 1) { /* dotted quad */
+ if (rc == 1) { // dotted quad
hints.ai_family = AF_INET;
hints.ai_flags |= AI_NUMERICHOST;
} else {
rc = inet_pton(AF_INET6, host, &serveraddr);
- if (rc == 1) { /* IPv6 address */
+ if (rc == 1) { // IPv6 address
hints.ai_family = AF_INET6;
hints.ai_flags |= AI_NUMERICHOST;
}
}
- /* Begin the connection process */
-
+ // Begin the connection process
rc = getaddrinfo(host, service, &hints, &res);
if (rc != 0) {
fprintf(stderr, "ctdlmigrate: %s\n", strerror(errno));
return (-1);
}
- /*
- * Try all available addresses until we connect to one or until we run out.
- */
+ // Try all available addresses until we connect to one or until we run out.
for (ai = res; ai != NULL; ai = ai->ai_next) {
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (sock < 0) {
rc = connect(sock, ai->ai_addr, ai->ai_addrlen);
if (rc >= 0) {
- return (sock); /* Connected! */
+ return (sock); // Connected!
}
else {
fprintf(stderr, "ctdlmigrate: %s\n", strerror(errno));
- close(sock); /* Failed. Close the socket to avoid fd leak! */
+ close(sock); // Failed. Close the socket to avoid fd leak!
}
}
return (-1);
}
+// Connect to a Citadel on a remote host using a unix domaion socket
int uds_connectsock(char *sockpath) {
int s;
struct sockaddr_un addr;
}
-/*
- * input binary data from socket
- */
+// input binary data from socket
void serv_read(int serv_sock, char *buf, int bytes) {
- int len, rlen;
+ int len = 0;
+ int rlen = 0;
- len = 0;
while (len < bytes) {
rlen = read(serv_sock, &buf[len], bytes - len);
if (rlen < 1) {
}
-/*
- * send binary to server
- */
+// send binary to server
void serv_write(int serv_sock, char *buf, int nbytes) {
int bytes_written = 0;
int retval;
}
-/*
- * input string from socket - implemented in terms of serv_read()
- */
+// input string from socket - implemented in terms of serv_read()
void serv_gets(int serv_sock, char *buf) {
int i;
- /* Read one character at a time.
- */
+ // Read one character at a time.
for (i = 0;; i++) {
serv_read(serv_sock, &buf[i], 1);
if (buf[i] == '\n' || i == (SIZ-1))
break;
}
- /* If we got a long line, discard characters until the newline.
- */
+ // If we got a long line, discard characters until the newline.
if (i == (SIZ-1)) {
while (buf[i] != '\n') {
serv_read(serv_sock, &buf[i], 1);
}
}
- /* Strip all trailing nonprintables (crlf)
- */
+ // Strip all trailing nonprintables (crlf)
buf[i] = 0;
}
-/*
- * send line to server - implemented in terms of serv_write()
- */
+// send line to server - implemented in terms of serv_write()
void serv_puts(int serv_sock, char *buf) {
serv_write(serv_sock, buf, strlen(buf));
serv_write(serv_sock, "\n", 1);
}
-/*
- * serv_printf() Send formatted printable data to the server
- */
+// send formatted printable data to the server
void serv_printf(int serv_sock, const char *format, ...) {
va_list arg_ptr;
char buf[1024];
}
+// You know what main() does. If you don't, you shouldn't be trying to understand this program.
int main(int argc, char *argv[]) {
char ctdldir[PATH_MAX]=CTDLDIR;
char yesno[2];
int local_admin_socket = (-1);
int progress = 0;
- /* Parse command line */
+ // Parse command line
while ((a = getopt(argc, argv, "h:")) != EOF) {
switch (a) {
case 'h':
"the source system. The target may be a different CPU architecture\n"
"and/or operating system. The source system should be running\n"
"Citadel version \033[33m%d\033[0m or newer, and the target system should be running\n"
- "either the same version or a newer version. You will also need\n"
- "the \033[33mrsync\033[0m utility, and OpenSSH v4 or newer.\n"
+ "either the same version or a newer version.\n"
"\n"
"You must run this utility on the TARGET SYSTEM. Any existing data\n"
"on this system will be ERASED. Your target system will be on this\n"
if (!cmdexit) {
printf( "\033[2J\033[H\n"
- " \033[32m╔═══════════════════════════════════════════════╗\n"
- " ║ ║\n"
- " ║ \033[33mValidate source and target systems\033[32m ║\n"
- " ║ ║\n"
- " ╚═══════════════════════════════════════════════╝\033[0m\n"
+ "\033[32m╔═══════════════════════════════════════════════╗\n"
+ "║ ║\n"
+ "║ \033[33mValidate source and target systems\033[32m ║\n"
+ "║ ║\n"
+ "╚═══════════════════════════════════════════════╝\033[0m\n"
"\n\n");
- printf("First we must validate that the local target system is running and ready to receive data.\n");
+ printf("First we must validate that the local target system is running\n");
+ printf("and ready to receive data.\n");
printf("Checking connectivity to Citadel in %s...\n", ctdldir);
local_admin_socket = uds_connectsock("citadel-admin.socket");
if (local_admin_socket < 0) {
if (!cmdexit) {
printf( "\033[2J\033[H\n"
- " \033[32m╔═══════════════════════════════════════════════════════════════════╗\n"
- " ║ ║\n"
- " ║ \033[33mMigrating from: %-50s\033[32m║\n"
- " ║ ║\n"
- " ╠═══════════════════════════════════════════════════════════════════╣\n"
- " ║ ║\n"
- " ║ Lines received: 0 Percent complete: 0 ║\n"
- " ║ ║\n"
- " ╚═══════════════════════════════════════════════════════════════════╝\033[0m\n"
+ "\033[32m╔═══════════════════════════════════════════════════════════════════╗\n"
+ "║ ║\n"
+ "║ \033[33mMigrating from: %-50s\033[32m║\n"
+ "║ ║\n"
+ "╠═══════════════════════════════════════════════════════════════════╣\n"
+ "║ ║\n"
+ "║ Lines received: 0 Percent complete: 0 ║\n"
+ "║ ║\n"
+ "╚═══════════════════════════════════════════════════════════════════╝\033[0m\n"
"\n", remote_host
);
}
++linecount;
if (!strncasecmp(buf, "<progress>", 10)) {
progress = atoi(&buf[10]);
- printf("\033[8;75H\033[33m%d\033[0m\033[20;0H\n", progress);
+ printf("\033[8;65H\033[33m%d\033[0m\033[12;0H\n", progress);
}
if (time(NULL) != last_update) {
last_update = time(NULL);
- printf("\033[8;29H\033[33m%d\033[0m\033[20;0H\n", linecount);
+ printf("\033[8;19H\033[33m%d\033[0m\033[12;0H\n", linecount);
}
serv_puts(local_admin_socket, buf);
}
ctdlmigrate_exit(86);
}
- // FIXME restart the local server now
+ // FIXME restart the local server here
+ close(remote_server_socket);
+ close(local_admin_socket);
ctdlmigrate_exit(cmdexit);
}
if (TSD->tid != NULL) {
syslog(LOG_ERR, "db: cdb_trunc must not be called in a transaction.");
cdb_abort();
- } else {
+ }
+ else {
bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
retry:
-/*
- * This module dumps and/or loads the Citadel database in XML format.
- *
- * Copyright (c) 1987-2021 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 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.
- */
-
-/*
- * Explanation of <progress> tags:
- *
- * 0% started
- * 2% finished exporting configuration
- * 7% finished exporting users
- * 12% finished exporting openids
- * 17% finished exporting rooms
- * 18% finished exporting floors
- * 25% finished exporting visits
- * 26-99% exporting messages
- * 100% finished exporting messages
- *
- * These tags are inserted into the XML stream to give the reader an approximation of its progress.
- */
+// This module dumps and/or loads the Citadel database in XML format.
+//
+// Copyright (c) 1987-2021 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 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.
+//
+// Explanation of <progress> tags:
+//
+// 0% started
+// 2% finished exporting configuration
+// 7% finished exporting users
+// 12% finished exporting openids
+// 17% finished exporting rooms
+// 18% finished exporting floors
+// 25% finished exporting visits
+// 26-99% exporting messages
+// 100% finished exporting messages
+//
+// These tags are inserted into the XML stream to give the reader an approximation of its progress.
#include "sysdep.h"
#include <stdlib.h>
int total_msgs = 0;
char *ikey = NULL; // If we're importing a config key we store it here.
-/******************************************************************************
- * Code which implements the export appears in this section *
- ******************************************************************************/
+//*****************************************************************************
+//* Code which implements the export appears in this section *
+//*****************************************************************************
-/*
- * Output a string to the client with these characters escaped: & < > " '
- */
+// Output a string to the client with these characters escaped: & < > " '
void xml_strout(char *str) {
char *c = str;
}
-/*
- * Export a user record as XML
- */
+// Export a user record as XML
void migr_export_users_backend(char *username, void *data) {
struct ctdluser u;
cprintf("<msgnum_pic>%ld</msgnum_pic>\n", buf->msgnum_pic);
client_write(HKEY("</room>\n"));
- /* message list goes inside this tag */
+ // message list goes inside this tag
CtdlGetRoom(&CC->room, buf->QRname);
client_write(HKEY("<room_messages>"));
client_write(HKEY("<FRname>"));
fclose(migr_global_message_list);
}
- /*
- * Process the 'global' message list. (Sort it and remove dups.
- * Dups are ok because a message may be in more than one room, but
- * this will be handled by exporting the reference count, not by
- * exporting the message multiple times.)
- */
+ // Process the 'global' message list. (Sort it and remove dups.
+ // Dups are ok because a message may be in more than one room, but
+ // this will be handled by exporting the reference count, not by
+ // exporting the message multiple times.)
snprintf(cmd, sizeof cmd, "sort -n <%s >%s", migr_tempfilename1, migr_tempfilename2);
if (system(cmd) != 0) {
syslog(LOG_ERR, "migrate: error %d", errno);
}
-/*
- * Return nonzero if the supplied string contains only characters which are valid in a sequence set.
- */
+// Return nonzero if the supplied string contains only characters which are valid in a sequence set.
int is_sequence_set(char *s) {
if (!s) return(0);
}
-/*
- * Traverse the visits file...
- */
+// Traverse the visits file...
void migr_export_visits(void) {
visit vbuf;
struct cdbdata *cdbv;
syslog(LOG_ERR, "migrate: export aborted due to client disconnect!");
}
- migr_export_message(-1L); /* This frees the encoding buffer */
+ migr_export_message(-1L); // This frees the encoding buffer
}
cprintf("<version>%d</version>\n", REV_LEVEL);
cprintf("<progress>%d</progress>\n", 0);
- /* export the configuration database */
+ // export the configuration database
migr_export_configs();
cprintf("<progress>%d</progress>\n", 2);
}
-/******************************************************************************
- * Import code *
- * Here's the code that implements the import side. It's going to end up *
- * being one big loop with lots of global variables. I don't care. *
- * You wouldn't run multiple concurrent imports anyway. If this offends your *
- * delicate sensibilities then go rewrite it in Ruby on Rails or something. *
- ******************************************************************************/
+// Import code
+// Here's the code that implements the import side. It's going to end up
+// being one big loop with lots of global variables. I don't care.
+// You wouldn't run multiple concurrent imports anyway. If this offends your
+// delicate sensibilities then go rewrite it in Ruby on Rails or something.
-int citadel_migrate_data = 0; /* Are we inside a <citadel_migrate_data> tag pair? */
+int citadel_migrate_data = 0; // Are we inside a <citadel_migrate_data> tag pair?
StrBuf *migr_chardata = NULL;
StrBuf *migr_MsgData = NULL;
struct ctdluser usbuf;
struct MetaData smi;
long import_msgnum = 0;
-/*
- * This callback stores up the data which appears in between tags.
- */
+// This callback stores up the data which appears in between tags.
void migr_xml_chardata(void *data, const XML_Char *s, int len) {
StrBufAppendBufPlain(migr_chardata, s, len, 0);
}
void migr_xml_start(void *data, const char *el, const char **attr) {
int i;
- /*** GENERAL STUFF ***/
+ // *** GENERAL STUFF ***
- /* Reset chardata_len to zero and init buffer */
+ // Reset chardata_len to zero and init buffer
FlushStrBuf(migr_chardata);
FlushStrBuf(migr_MsgData);
if (!strcasecmp(el, "citadel_migrate_data")) {
++citadel_migrate_data;
- /* As soon as it looks like the input data is a genuine Citadel XML export,
- * whack the existing database on disk to make room for the new one.
- */
+ // As soon as it looks like the input data is a genuine Citadel XML export,
+ // whack the existing database on disk to make room for the new one.
if (citadel_migrate_data == 1) {
+ syslog(LOG_INFO, "migrate: erasing existing databases so we can receive the incoming import");
for (i = 0; i < MAXCDB; ++i) {
cdb_trunc(i);
}
return;
}
- /* When we begin receiving XML for one of these record types, clear out the associated
- * buffer so we don't accidentally carry over any data from a previous record.
- */
+ // When we begin receiving XML for one of these record types, clear out the associated
+ // buffer so we don't accidentally carry over any data from a previous record.
if (!strcasecmp(el, "user")) memset(&usbuf, 0, sizeof (struct ctdluser));
else if (!strcasecmp(el, "openid")) memset(openid_url, 0, sizeof openid_url);
else if (!strcasecmp(el, "room")) memset(&qrbuf, 0, sizeof (struct ctdlroom));
long msgnum = 0L;
long *msglist = NULL;
int msglist_alloc = 0;
- /*** GENERAL STUFF ***/
+ // *** GENERAL STUFF ***
if (!strcasecmp(el, "citadel_migrate_data")) {
--citadel_migrate_data;
// syslog(LOG_DEBUG, "END TAG: <%s> DATA: <%s>\n", el, (migr_chardata_len ? migr_chardata : ""));
- /*** CONFIG ***/
+ // *** CONFIG ***
if (!strcasecmp(el, "config")) {
syslog(LOG_DEBUG, "migrate: imported config key=%s", ikey);
}
}
- /*** USER ***/
+ // *** USER ***
else if ((!strncasecmp(el, HKEY("u_"))) &&
migr_userrecord(data, el))
; /* Nothing to do anymore */
syslog(LOG_INFO, "migrate: imported user: %s", usbuf.fullname);
}
- /*** OPENID ***/
+ // *** OPENID ***
else if (!strcasecmp(el, "oid_url")) safestrncpy(openid_url, ChrPtr(migr_chardata), sizeof openid_url);
else if (!strcasecmp(el, "oid_usernum")) openid_usernum = atol(ChrPtr(migr_chardata));
- else if (!strcasecmp(el, "openid")) { /* see serv_openid_rp.c for a description of the record format */
+ else if (!strcasecmp(el, "openid")) { // see serv_openid_rp.c for a description of the record format
char *oid_data;
int oid_data_len;
oid_data_len = sizeof(long) + strlen(openid_url) + 1;
syslog(LOG_INFO, "migrate: imported OpenID: %s (%ld)", openid_url, openid_usernum);
}
- /*** ROOM ***/
+ // *** ROOM ***
else if ((!strncasecmp(el, HKEY("QR"))) &&
migr_roomrecord(data, el))
- ; /* Nothing to do anymore */
+ ; // Nothing to do anymore
else if (!strcasecmp(el, "room")) {
CtdlPutRoom(&qrbuf);
syslog(LOG_INFO, "migrate: imported room: %s", qrbuf.QRname);
}
- /*** ROOM MESSAGE POINTERS ***/
+ // *** ROOM MESSAGE POINTERS ***
else if (!strcasecmp(el, "FRname")) {
safestrncpy(FRname, ChrPtr(migr_chardata), sizeof FRname);
}
}
- /*** FLOORS ***/
+ // *** FLOORS ***
else if ((!strncasecmp(el, HKEY("f_"))) &&
migr_floorrecord(data, el))
- ; /* Nothing to do anymore */
+ ; // Nothing to do anymore
else if (!strcasecmp(el, "floor")) {
CtdlPutFloor(&flbuf, floornum);
syslog(LOG_INFO, "migrate: imported floor #%d (%s)", floornum, flbuf.f_name);
}
- /*** VISITS ***/
+ // *** VISITS ***
else if ((!strncasecmp(el, HKEY("v_"))) && migr_visitrecord(data, el)) {
- ; /* Nothing to do anymore */
+ ; // Nothing to do anymore
}
else if (!strcasecmp(el, "visit")) {
put_visit(&vbuf);
syslog(LOG_INFO, "migrate: imported visit: %ld/%ld/%ld", vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum);
}
- /*** MESSAGES ***/
+ // *** MESSAGES ***
else if (!strcasecmp(el, "msg_msgnum")) smi.meta_msgnum = import_msgnum = atol(ChrPtr(migr_chardata));
else if (!strcasecmp(el, "msg_meta_refcount")) smi.meta_refcount = atoi(ChrPtr(migr_chardata));
}
syslog(LOG_INFO,
- "migrate: %s message #%ld, size=%d, refcount=%d, bodylength=%ld, content-type: %s",
- (rc!= 0)?"failed to import ":"Imported ",
+ "migrate: %s message #%ld, size=%d, ref=%d, body=%ld, content-type: %s",
+ (rc!= 0)?"failed to import":"imported",
import_msgnum,
StrLength(migr_MsgData),
smi.meta_refcount,
memset(&smi, 0, sizeof(smi));
}
- /*** MORE GENERAL STUFF ***/
+ // *** MORE GENERAL STUFF ***
FlushStrBuf(migr_chardata);
}
-/*
- * Import begins here
- */
+// Import begins here
void migr_do_import(void) {
XML_Parser xp;
char buf[SIZ];
}
-/******************************************************************************
- * Dispatcher, Common code *
- ******************************************************************************/
-/*
- * Dump out the pathnames of directories which can be copied "as is"
- */
+// ******************************************************************************
+// * Dispatcher, Common code *
+// ******************************************************************************
+
+// Dump out the pathnames of directories which can be copied "as is"
void migr_do_listdirs(void) {
cprintf("%d Don't forget these:\n", LISTING_FOLLOWS);
cprintf("files|%s\n", ctdl_file_dir);
}
-/******************************************************************************
- * Repair database integrity *
- ******************************************************************************/
+// ******************************************************************************
+// * Repair database integrity *
+// ******************************************************************************
StrBuf *PlainMessageBuf = NULL;
HashList *UsedMessageIDS = NULL;
struct CtdlMessage *msg;
char *mptr = NULL;
- /* We can use a static buffer here because there will never be more than
- * one of this operation happening at any given time, and it's really best
- * to just keep it allocated once instead of torturing malloc/free.
- * Call this function with msgnum "-1" to free the buffer when finished.
- */
+ // We can use a static buffer here because there will never be more than
+ // one of this operation happening at any given time, and it's really best
+ // to just keep it allocated once instead of torturing malloc/free.
+ // Call this function with msgnum "-1" to free the buffer when finished.
static int encoded_alloc = 0;
static char *encoded_msg = NULL;
PlainMessageBuf = NewStrBufPlain(NULL, 10*SIZ);
}
- /* Ok, here we go ... */
+ // Ok, here we go ...
msg = CtdlFetchMessage(msgnum, 1);
if (msg == NULL) {
smi.meta_msgnum = msgnum;
smi.meta_refcount = refcount;
- /* restore the content type from the message body: */
+ // restore the content type from the message body:
mptr = bmstrcasestr(msg->cm_fields[eMesageText], "Content-type:");
if (mptr != NULL) {
char *aptr;
void migr_check_rooms_backend(struct ctdlroom *buf, void *data) {
- /* message list goes inside this tag */
+ // message list goes inside this tag
CtdlGetRoom(&CC->room, buf->QRname);
CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, migr_check_room_msg, NULL);
}
fclose(migr_global_message_list);
}
- /*
- * Process the 'global' message list. (Sort it and remove dups.
- * Dups are ok because a message may be in more than one room, but
- * this will be handled by exporting the reference count, not by
- * exporting the message multiple times.)
- */
+ // Process the 'global' message list. (Sort it and remove dups.
+ // Dups are ok because a message may be in more than one room, but
+ // this will be handled by exporting the reference count, not by
+ // exporting the message multiple times.)
snprintf(cmd, sizeof cmd, "sort -n <%s >%s", migr_tempfilename1, migr_tempfilename2);
if (system(cmd) != 0) {
syslog(LOG_ERR, "migrate: error %d", errno);
fclose(migr_global_message_list);
}
- migr_restore_message_metadata(-1L, -1); /* This frees the encoding buffer */
+ migr_restore_message_metadata(-1L, -1); // This frees the encoding buffer
cprintf("%d system analysis completed", CIT_OK);
Ctx->kill_me = 1;
}
-/******************************************************************************
- * Dispatcher, Common code *
- ******************************************************************************/
+// ******************************************************************************
+// * Dispatcher, Common code *
+// ******************************************************************************
void cmd_migr(char *cmdbuf) {
char cmd[32];
}
-/******************************************************************************
- * Module Hook *
- ******************************************************************************/
+// ******************************************************************************
+// * Module Hook *
+// ******************************************************************************
CTDL_MODULE_INIT(migrate)
{
CtdlRegisterProtoHook(cmd_migr, "MIGR", "Across-the-wire migration");
}
- /* return our module name for the log */
+ // return our module name for the log
return "migrate";
}
StrBuf *lostr;
StrBuf *histr;
const char *pvset;
- char *is_set; /* actually an array of booleans */
+ char *is_set; // actually an array of booleans
- /* Don't bother doing *anything* if we were passed a list of zero messages */
+ // Don't bother doing *anything* if we were passed a list of zero messages
if (num_target_msgnums < 1) {
return;
}
- /* If no room was specified, we go with the current room. */
+ // If no room was specified, we go with the current room.
if (!which_room) {
which_room = &CC->room;
}
- /* If no user was specified, we go with the current user. */
+ // If no user was specified, we go with the current user.
if (!which_user) {
which_user = &CC->user;
}
which_set,
which_room->QRname);
- /* Learn about the user and room in question */
+ // Learn about the user and room in question
CtdlGetRelationship(&vbuf, which_user, which_room);
- /* Load the message list */
+ // Load the message list
cdbfr = cdb_fetch(CDB_MSGLISTS, &which_room->QRnumber, sizeof(long));
if (cdbfr != NULL) {
msglist = (long *) cdbfr->ptr;
- cdbfr->ptr = NULL; /* CtdlSetSeen() now owns this memory */
+ cdbfr->ptr = NULL; // CtdlSetSeen() now owns this memory
num_msgs = cdbfr->len / sizeof(long);
cdb_free(cdbfr);
}
else {
- return; /* No messages at all? No further action. */
+ return; // No messages at all? No further action.
}
is_set = malloc(num_msgs * sizeof(char));
}
-#if 0 /* This is a special diagnostic section. Do not allow it to run during normal operation. */
+#if 0 // This is a special diagnostic section. Do not allow it to run during normal operation.
syslog(LOG_DEBUG, "There are %d messages in the room.\n", num_msgs);
for (i=0; i<num_msgs; ++i) {
if ((i > 0) && (msglist[i] <= msglist[i-1])) abort();
}
#endif
- /* Translate the existing sequence set into an array of booleans */
+ // Translate the existing sequence set into an array of booleans
setstr = NewStrBuf();
lostr = NewStrBuf();
histr = NewStrBuf();
FreeStrBuf(&lostr);
FreeStrBuf(&histr);
- /* Now translate the array of booleans back into a sequence set */
+ // Now translate the array of booleans back into a sequence set
FlushStrBuf(vset);
was_seen = 0;
lo = (-1);
for (i=0; i<num_msgs; ++i) {
is_seen = is_set[i];
- /* Apply changes */
+ // Apply changes
for (k=0; k<num_target_msgnums; ++k) {
if (msglist[i] == target_msgnums[k]) {
is_seen = target_setting;
was_seen = is_seen;
}
- /*
- * We will have to stuff this string back into a 4096 byte buffer, so if it's
- * larger than that now, truncate it by removing tokens from the beginning.
- * The limit of 100 iterations is there to prevent an infinite loop in case
- * something unexpected happens.
- */
+ // We will have to stuff this string back into a 4096 byte buffer, so if it's
+ // larger than that now, truncate it by removing tokens from the beginning.
+ // The limit of 100 iterations is there to prevent an infinite loop in case
+ // something unexpected happens.
int number_of_truncations = 0;
while ( (StrLength(vset) > SIZ) && (number_of_truncations < 100) ) {
StrBufRemove_token(vset, 0, ',');
++number_of_truncations;
}
- /*
- * If we're truncating the sequence set of messages marked with the 'seen' flag,
- * we want the earliest messages (the truncated ones) to be marked, not unmarked.
- * Otherwise messages at the beginning will suddenly appear to be 'unseen'.
- */
+ // If we're truncating the sequence set of messages marked with the 'seen' flag,
+ // we want the earliest messages (the truncated ones) to be marked, not unmarked.
+ // Otherwise messages at the beginning will suddenly appear to be 'unseen'.
if ( (which_set == ctdlsetseen_seen) && (number_of_truncations > 0) ) {
StrBuf *first_tok;
first_tok = NewStrBuf();
vset = new_set;
}
- /* Decide which message set we're manipulating */
+ // Decide which message set we're manipulating
switch (which_set) {
case ctdlsetseen_seen:
safestrncpy(vbuf.v_seen, ChrPtr(vset), sizeof vbuf.v_seen);
}
-/*
- * API function to perform an operation for each qualifying message in the
- * current room. (Returns the number of messages processed.)
- */
+// API function to perform an operation for each qualifying message in the
+// current room. (Returns the number of messages processed.)
int CtdlForEachMessage(int mode, long ref, char *search_string,
char *content_type,
struct CtdlMessage *compare,