summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaul <paul@7b491191-dbf0-0310-aff6-d879d4d69008>2007-04-08 08:10:09 +0000
committerpaul <paul@7b491191-dbf0-0310-aff6-d879d4d69008>2007-04-08 08:10:09 +0000
commit311fa1637152186f0f2dff48dbd89fe5bf69eafb (patch)
treec9e9e9b8e26c4139a1d3ea73c1f48af388c8f339
parent60d0e5d765833860274ba5c7e333bd669e0f67e5 (diff)
Merge with dbmail_2_2
git-svn-id: https://svn.ic-s.nl/svn/dbmail/branches/dbmail_2_2_branch@2509 7b491191-dbf0-0310-aff6-d879d4d69008
-rw-r--r--ChangeLog9
-rw-r--r--dbmail-user.c10
-rw-r--r--imapcommands.c2
-rw-r--r--lmtp.c1
-rw-r--r--main.c9
-rw-r--r--pool.c73
-rw-r--r--pool.h4
-rw-r--r--pop3.c4
-rw-r--r--serverchild.c2
-rw-r--r--serverparent.c7
-rw-r--r--timsieve.c1
11 files changed, 94 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index ef9b0fca..b658a739 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-04-07 Aaron Stone <aaron@serendipity.cx>
+
+ * pool.h, pool.c, lmtp.c, pop3.c, timsieve.c, imapcommands.c,
+ serverchild.c:
+ Further work on the scoreboard status output, and added currently
+ logged in user (pop3, imap, timsieve) or mail sender (lmtp)
+ * main.c, serverparent.c, dbmail-user.c:
+ Added definitions for yes_to_all, no_to_all, etc.
+
2007-04-06 Paul J Stevens <paul@nfg.nl>
* README.usermap, UPGRADING:
diff --git a/dbmail-user.c b/dbmail-user.c
index 19911c18..dbeeda04 100644
--- a/dbmail-user.c
+++ b/dbmail-user.c
@@ -41,11 +41,11 @@ static const char ValidChars[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
"_.!@#$%^&*()-+=~[]{}<>:;\\/";
-extern int yes_to_all = 0;
-extern int no_to_all = 0;
-extern int verbose = 0;
-extern int quiet = 0; /* Don't be helpful. */
-extern int reallyquiet = 0; /* Don't print errors. */
+extern int yes_to_all;
+extern int no_to_all;
+extern int verbose;
+extern int quiet; /* Don't be helpful. */
+extern int reallyquiet; /* Don't print errors. */
int do_add(const char * const user,
const char * const password, const char * const enctype,
diff --git a/imapcommands.c b/imapcommands.c
index 4fc9db22..7f3836fb 100644
--- a/imapcommands.c
+++ b/imapcommands.c
@@ -143,6 +143,8 @@ int _ic_login(struct ImapSession *self)
if (imap_before_smtp)
db_log_ip(self->ci->ip_src);
+ child_reg_connected_user(self->args[self->args_idx]);
+
dbmail_imap_session_printf(self, "%s OK LOGIN completed\r\n", self->tag);
return 0;
}
diff --git a/lmtp.c b/lmtp.c
index f69bd234..37b729a5 100644
--- a/lmtp.c
+++ b/lmtp.c
@@ -457,6 +457,7 @@ int lmtp(void *stream, void *instream, char *buffer,
ci_write((FILE *) stream,
"250 Sender <%s> OK\r\n",
(char *)(dm_list_getstart(&from)->data));
+ child_reg_connected_user(tmpaddr);
}
if (tmpaddr != NULL)
dm_free(tmpaddr);
diff --git a/main.c b/main.c
index e4483da2..413758aa 100644
--- a/main.c
+++ b/main.c
@@ -52,8 +52,13 @@ int brute_force = 0;
char *deliver_to_header = NULL;
char *deliver_to_mailbox = NULL;
-/* loudness and assumptions */
-static int verbose = 0;
+/* Loudness and assumptions. */
+int verbose = 0;
+/* Not used, but required to link with libdbmail.so */
+int no_to_all = 0;
+int yes_to_all = 0;
+int reallyquiet = 0;
+int quiet = 0;
int do_showhelp(void) {
printf("*** dbmail-smtp ***\n");
diff --git a/pool.c b/pool.c
index 124ee3ca..926502e8 100644
--- a/pool.c
+++ b/pool.c
@@ -25,7 +25,7 @@ static FILE *scoreFD;
extern volatile sig_atomic_t GeneralStopRequested;
extern ChildInfo_t childinfo;
-static child_state_t state_new(void);
+static void state_reset(child_state_t *child);
static int set_lock(int type);
static pid_t reap_child(void);
@@ -37,15 +37,14 @@ static pid_t reap_child(void);
*
*/
-child_state_t state_new(void)
+void state_reset(child_state_t *s)
{
- child_state_t s;
- s.pid = -1;
- s.ctime = time(0);
- s.status = STATE_NOOP;
- s.count = 0;
- snprintf(s.client, 127, "none");
- return s;
+ s->pid = -1;
+ s->ctime = time(0);
+ s->status = STATE_NOOP;
+ s->count = 0;
+ memset(s->client, '\0', 128);
+ memset(s->user, '\0', 128);
}
int set_lock(int type)
@@ -122,7 +121,7 @@ void scoreboard_setup(void) {
int i;
scoreboard_wrlck();
for (i = 0; i < HARD_MAX_CHILDREN; i++)
- scoreboard->child[i] = state_new();
+ state_reset(&scoreboard->child[i]);
scoreboard_unlck();
}
@@ -187,7 +186,7 @@ void scoreboard_release(pid_t pid)
return;
scoreboard_wrlck();
- scoreboard->child[key] = state_new();
+ state_reset(&scoreboard->child[key]);
scoreboard_unlck();
}
@@ -333,10 +332,11 @@ void child_reg_connected(void)
scoreboard_wrlck();
scoreboard->child[key].status = STATE_CONNECTED;
+ scoreboard->child[key].count++;
scoreboard_unlck();
}
-void child_reg_connected_details(char *ip, char *name)
+void child_reg_connected_client(char *ip, char *name)
{
int key;
pid_t pid;
@@ -350,9 +350,29 @@ void child_reg_connected_details(char *ip, char *name)
scoreboard_wrlck();
if (scoreboard->child[key].status == STATE_CONNECTED) {
if (name && name[0])
- snprintf(scoreboard->child[key].client, 127, name);
+ strncpy(scoreboard->child[key].client, name, 127);
else
- snprintf(scoreboard->child[key].client, 127, ip);
+ strncpy(scoreboard->child[key].client, ip, 127);
+ } else {
+ TRACE(TRACE_MESSAGE, "client disconnected before status detail was logged");
+ }
+ scoreboard_unlck();
+}
+
+void child_reg_connected_user(char *user)
+{
+ int key;
+ pid_t pid;
+
+ pid = getpid();
+ key = getKey(pid);
+
+ if (key == -1)
+ TRACE(TRACE_FATAL, "unable to find this pid on the scoreboard");
+
+ scoreboard_wrlck();
+ if (scoreboard->child[key].status == STATE_CONNECTED) {
+ strncpy(scoreboard->child[key].user, user, 127);
} else {
TRACE(TRACE_MESSAGE, "client disconnected before status detail was logged");
}
@@ -372,7 +392,8 @@ void child_reg_disconnected(void)
scoreboard_wrlck();
scoreboard->child[key].status = STATE_IDLE;
- snprintf(scoreboard->child[key].client, 127, "none");
+ memset(scoreboard->child[key].client, '\0', 128);
+ memset(scoreboard->child[key].user, '\0', 128);
scoreboard_unlck();
}
@@ -558,18 +579,32 @@ void scoreboard_state(void)
TRACE(TRACE_ERROR, "Couldn't write scoreboard state to top file [%s].",
strerror(errno));
}
+
+ // Fixed 78 char output width.
+ if ((printlen = fprintf(scoreFD, "%8s%8s%8s%8s%22s%22s\n\n",
+ "Child", "PID", "Status", "Count", "Client", "User") <= 0)
+ || !(scorelen += printlen)) {
+ TRACE(TRACE_ERROR, "Couldn't write scoreboard state to top file [%s].",
+ strerror(errno));
+ }
+
for (i = 0; i < scoreboard->conf->maxChildren; i++) {
- int chpid;
- int status;
- char *client;
+ int chpid, status;
+ char *client, *user;
+ unsigned count;
scoreboard_rdlck();
chpid = scoreboard->child[i].pid;
status = scoreboard->child[i].status;
+ count = scoreboard->child[i].count;
client = scoreboard->child[i].client;
+ user = scoreboard->child[i].user;
scoreboard_unlck();
- if ((printlen = fprintf(scoreFD, "Child %d Pid %d Status %d Client %s\n", i, chpid, status, client)) <= 0
+ // Matching 78 char fixed width as above.
+ // Long hostnames may make the output a little messy.
+ if ((printlen = fprintf(scoreFD, "%8d%8d%8d%8u%22s%22s\n",
+ i, chpid, status, count, client, user)) <= 0
|| !(scorelen += printlen)) {
TRACE(TRACE_ERROR, "Couldn't write scoreboard state to top file [%s].",
strerror(errno));
diff --git a/pool.h b/pool.h
index e57299ec..efb6cfdd 100644
--- a/pool.h
+++ b/pool.h
@@ -29,6 +29,7 @@ typedef struct {
unsigned char status;
unsigned long count;
char client[128];
+ char user[128];
} child_state_t;
typedef struct {
@@ -44,7 +45,8 @@ void scoreboard_release(pid_t pid);
void scoreboard_delete(void);
int child_register(void);
void child_reg_connected(void);
-void child_reg_connected_details(char *ip, char *name);
+void child_reg_connected_client(char *ip, char *name);
+void child_reg_connected_user(char *user);
void child_reg_disconnected(void);
void child_unregister(void);
int count_children(void);
diff --git a/pop3.c b/pop3.c
index 7bfcd923..e1e0e4e6 100644
--- a/pop3.c
+++ b/pop3.c
@@ -410,6 +410,8 @@ int pop3(clientinfo_t *ci, char *buffer, PopSession_t * session)
if (pop_before_smtp)
db_log_ip(client_ip);
+ child_reg_connected_user(session->username);
+
result = db_createsession(result, session);
if (result == 1) {
ci_write((FILE *) stream, "+OK %s has %llu messages (%llu octets)\r\n",
@@ -686,6 +688,8 @@ int pop3(clientinfo_t *ci, char *buffer, PopSession_t * session)
if (pop_before_smtp)
db_log_ip(client_ip);
+ child_reg_connected_user(session->username);
+
result = db_createsession(result, session);
if (result == 1) {
ci_write((FILE *) stream, "+OK %s has %llu messages (%llu octets)\r\n",
diff --git a/serverchild.c b/serverchild.c
index 0439a04b..366bff76 100644
--- a/serverchild.c
+++ b/serverchild.c
@@ -342,7 +342,7 @@ int PerformChildTask(ChildInfo_t * info)
client.ip_src, getpid());
}
- child_reg_connected_details(client.ip_src, client.clientname);
+ child_reg_connected_client(client.ip_src, client.clientname);
/* make streams */
if (!(client.rx = fdopen(dup(clientSocket), "r"))) {
diff --git a/serverparent.c b/serverparent.c
index ecc594d9..f3dd6dcb 100644
--- a/serverparent.c
+++ b/serverparent.c
@@ -39,6 +39,13 @@ extern volatile sig_atomic_t mainStatus;
extern volatile sig_atomic_t mainStop;
extern volatile sig_atomic_t mainSig;
+/* Not used, but required to link with libdbmail.so */
+int verbose = 0;
+int no_to_all = 0;
+int yes_to_all = 0;
+int reallyquiet = 0;
+int quiet = 0;
+
static int SetMainSigHandler(void);
static void MainSigHandler(int sig, siginfo_t * info, void *data);
static void ClearConfig(serverConfig_t * conf);
diff --git a/timsieve.c b/timsieve.c
index 1ca9e252..da9031ee 100644
--- a/timsieve.c
+++ b/timsieve.c
@@ -319,6 +319,7 @@ int tims(clientinfo_t *ci, char *buffer, PopSession_t * session)
session->useridnr = useridnr;
session->username = dm_strdup(tmp64[1]);
session->password = dm_strdup(tmp64[2]);
+ child_reg_connected_user(session->username);
} else {
ci_write((FILE *) stream, "NO \"Username or password incorrect.\"\r\n");
}