Improve generation of session identifiers for server programs
* include/mailutils/acl.h (mu_acl_set_session_id): Remove proto. * include/mailutils/server.h (mu_session_id): Remove extern. (mu_sid): New proto. * libmailutils/server/sid.c: New file. * libmailutils/server/Makefile.am: Add sid.c * libmailutils/server/ipsrv.c (mu_ip_tcp_accept) (mu_ip_udp_accept): Remove calls to mu_acl_set_session_id. (mu_ip_server_accept): Make sure output to mu_strerr is filtered so that session ID is prepended to each line. (mu_ip_server_loop): Remove. * libmailutils/server/msrv.c (mu_m_server_check_acl): Remove call to mu_acl_set_session_id. * libmailutils/server/server.c (mu_session_id): Remove variable. * imap4d/imap4d.c (get_client_address, set_strerr_flt) (clr_strerr_flt): Remove unused functions. (imap4d_connection): Simplify. * pop3d/pop3d.c: Likewise.
Showing
9 changed files
with
175 additions
and
205 deletions
... | @@ -17,8 +17,8 @@ | ... | @@ -17,8 +17,8 @@ |
17 | 17 | ||
18 | #include "imap4d.h" | 18 | #include "imap4d.h" |
19 | #include <mailutils/gsasl.h> | 19 | #include <mailutils/gsasl.h> |
20 | #include "mailutils/cli.h" | 20 | #include <mailutils/cli.h> |
21 | #include "mailutils/kwd.h" | 21 | #include <mailutils/kwd.h> |
22 | #include "tcpwrap.h" | 22 | #include "tcpwrap.h" |
23 | 23 | ||
24 | mu_m_server_t server; | 24 | mu_m_server_t server; |
... | @@ -705,83 +705,6 @@ imap4d_session_setup (char *username) | ... | @@ -705,83 +705,6 @@ imap4d_session_setup (char *username) |
705 | } | 705 | } |
706 | return imap4d_session_setup0 (); | 706 | return imap4d_session_setup0 (); |
707 | } | 707 | } |
708 | |||
709 | int | ||
710 | get_client_address (int fd, struct sockaddr_in *pcs) | ||
711 | { | ||
712 | socklen_t len = sizeof *pcs; | ||
713 | |||
714 | if (getpeername (fd, (struct sockaddr *) pcs, &len) < 0) | ||
715 | { | ||
716 | mu_diag_funcall (MU_DIAG_ERROR, "getpeername", NULL, errno); | ||
717 | return 1; | ||
718 | } | ||
719 | return 0; | ||
720 | } | ||
721 | |||
722 | static int | ||
723 | set_strerr_flt (void) | ||
724 | { | ||
725 | mu_stream_t flt, trans[2]; | ||
726 | int rc; | ||
727 | |||
728 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans); | ||
729 | if (rc == 0) | ||
730 | { | ||
731 | char sessidstr[10]; | ||
732 | char *argv[] = { "inline-comment", NULL, "-S", NULL }; | ||
733 | |||
734 | snprintf (sessidstr, sizeof sessidstr, "%08lx:", mu_session_id); | ||
735 | argv[1] = sessidstr; | ||
736 | rc = mu_filter_create_args (&flt, trans[0], "inline-comment", 3, | ||
737 | (const char **)argv, | ||
738 | MU_FILTER_ENCODE, MU_STREAM_WRITE); | ||
739 | mu_stream_unref (trans[0]); | ||
740 | if (rc == 0) | ||
741 | { | ||
742 | mu_stream_set_buffer (flt, mu_buffer_line, 0); | ||
743 | trans[0] = flt; | ||
744 | trans[1] = NULL; | ||
745 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, | ||
746 | MU_IOCTL_OP_SET, trans); | ||
747 | mu_stream_unref (trans[0]); | ||
748 | if (rc) | ||
749 | mu_error (_("%s failed: %s"), "MU_IOCTL_SET_STREAM", | ||
750 | mu_stream_strerror (mu_strerr, rc)); | ||
751 | } | ||
752 | else | ||
753 | mu_error (_("cannot create log filter stream: %s"), mu_strerror (rc)); | ||
754 | } | ||
755 | else | ||
756 | { | ||
757 | mu_error (_("%s failed: %s"), "MU_IOCTL_GET_STREAM", | ||
758 | mu_stream_strerror (mu_strerr, rc)); | ||
759 | } | ||
760 | return rc; | ||
761 | } | ||
762 | |||
763 | static void | ||
764 | clr_strerr_flt (void) | ||
765 | { | ||
766 | mu_stream_t flt, trans[2]; | ||
767 | int rc; | ||
768 | |||
769 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans); | ||
770 | if (rc == 0) | ||
771 | { | ||
772 | flt = trans[0]; | ||
773 | |||
774 | rc = mu_stream_ioctl (flt, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans); | ||
775 | if (rc == 0) | ||
776 | { | ||
777 | mu_stream_unref (trans[0]); | ||
778 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, | ||
779 | MU_IOCTL_OP_SET, trans); | ||
780 | if (rc == 0) | ||
781 | mu_stream_unref (flt); | ||
782 | } | ||
783 | } | ||
784 | } | ||
785 | 708 | ||
786 | void | 709 | void |
787 | imap4d_child_signal_setup (RETSIGTYPE (*handler) (int signo)) | 710 | imap4d_child_signal_setup (RETSIGTYPE (*handler) (int signo)) |
... | @@ -895,27 +818,18 @@ imap4d_mainloop (int ifd, int ofd, struct imap4d_srv_config *cfg) | ... | @@ -895,27 +818,18 @@ imap4d_mainloop (int ifd, int ofd, struct imap4d_srv_config *cfg) |
895 | 818 | ||
896 | return 0; | 819 | return 0; |
897 | } | 820 | } |
898 | 821 | ||
899 | int | 822 | int |
900 | imap4d_connection (int fd, struct sockaddr *sa, int salen, | 823 | imap4d_connection (int fd, struct sockaddr *sa, int salen, |
901 | struct mu_srv_config *pconf, void *data) | 824 | struct mu_srv_config *pconf, void *data) |
902 | { | 825 | { |
903 | struct imap4d_srv_config *cfg = (struct imap4d_srv_config *) pconf; | 826 | struct imap4d_srv_config *cfg = (struct imap4d_srv_config *) pconf; |
904 | int rc; | ||
905 | 827 | ||
906 | idle_timeout = pconf->timeout; | 828 | idle_timeout = cfg->m_cfg.timeout; |
907 | imap4d_transcript = pconf->transcript; | 829 | imap4d_transcript = cfg->m_cfg.transcript; |
908 | 830 | ||
909 | if (mu_log_session_id) | ||
910 | rc = set_strerr_flt (); | ||
911 | else | ||
912 | rc = 1; | ||
913 | |||
914 | imap4d_mainloop (fd, fd, cfg); | 831 | imap4d_mainloop (fd, fd, cfg); |
915 | 832 | ||
916 | if (rc == 0) | ||
917 | clr_strerr_flt (); | ||
918 | |||
919 | return 0; | 833 | return 0; |
920 | } | 834 | } |
921 | 835 | ||
... | @@ -1057,7 +971,7 @@ main (int argc, char **argv) | ... | @@ -1057,7 +971,7 @@ main (int argc, char **argv) |
1057 | if (setgid (gr->gr_gid) == -1) | 971 | if (setgid (gr->gr_gid) == -1) |
1058 | { | 972 | { |
1059 | mu_error (_("error setting mail group: %s"), mu_strerror (errno)); | 973 | mu_error (_("error setting mail group: %s"), mu_strerror (errno)); |
1060 | exit (EX_OSERR); | 974 | //exit (EX_OSERR); |
1061 | } | 975 | } |
1062 | } | 976 | } |
1063 | 977 | ... | ... |
... | @@ -66,6 +66,5 @@ int mu_acl_string_to_action (const char *str, mu_acl_action_t *pres); | ... | @@ -66,6 +66,5 @@ int mu_acl_string_to_action (const char *str, mu_acl_action_t *pres); |
66 | 66 | ||
67 | int mu_acl_setenv (mu_acl_t acl, const char *name, const char *val); | 67 | int mu_acl_setenv (mu_acl_t acl, const char *name, const char *val); |
68 | const char *mu_acl_getenv (mu_acl_t acl, const char *name); | 68 | const char *mu_acl_getenv (mu_acl_t acl, const char *name); |
69 | int mu_acl_set_session_id (mu_acl_t acl); | ||
70 | 69 | ||
71 | #endif | 70 | #endif | ... | ... |
... | @@ -22,8 +22,6 @@ | ... | @@ -22,8 +22,6 @@ |
22 | #include <mailutils/types.h> | 22 | #include <mailutils/types.h> |
23 | #include <signal.h> | 23 | #include <signal.h> |
24 | 24 | ||
25 | extern unsigned long mu_session_id; | ||
26 | |||
27 | typedef int (*mu_conn_loop_fp) (int fd, void *conn_data, void *server_data); | 25 | typedef int (*mu_conn_loop_fp) (int fd, void *conn_data, void *server_data); |
28 | typedef void (*mu_conn_free_fp) (void *conn_data, void *server_data); | 26 | typedef void (*mu_conn_free_fp) (void *conn_data, void *server_data); |
29 | typedef int (*mu_server_idle_fp) (void *server_data); | 27 | typedef int (*mu_server_idle_fp) (void *server_data); |
... | @@ -71,7 +69,6 @@ int mu_ip_server_set_data (mu_ip_server_t srv, | ... | @@ -71,7 +69,6 @@ int mu_ip_server_set_data (mu_ip_server_t srv, |
71 | int mu_ip_server_open (mu_ip_server_t srv); | 69 | int mu_ip_server_open (mu_ip_server_t srv); |
72 | int mu_ip_server_shutdown (mu_ip_server_t srv); | 70 | int mu_ip_server_shutdown (mu_ip_server_t srv); |
73 | int mu_ip_server_accept (mu_ip_server_t srv, void *call_data); | 71 | int mu_ip_server_accept (mu_ip_server_t srv, void *call_data); |
74 | int mu_ip_server_loop (mu_ip_server_t srv, void *call_data); | ||
75 | int mu_ip_server_get_fd (mu_ip_server_t srv); | 72 | int mu_ip_server_get_fd (mu_ip_server_t srv); |
76 | int mu_ip_server_get_sockaddr (mu_ip_server_t srv, struct mu_sockaddr **psa); | 73 | int mu_ip_server_get_sockaddr (mu_ip_server_t srv, struct mu_sockaddr **psa); |
77 | const char *mu_ip_server_addrstr (mu_ip_server_t srv); | 74 | const char *mu_ip_server_addrstr (mu_ip_server_t srv); |
... | @@ -96,7 +93,6 @@ struct mu_srv_config /* Configuration data for a single TCP server. */ | ... | @@ -96,7 +93,6 @@ struct mu_srv_config /* Configuration data for a single TCP server. */ |
96 | /* Application-dependent data may follow */ | 93 | /* Application-dependent data may follow */ |
97 | }; | 94 | }; |
98 | 95 | ||
99 | |||
100 | typedef struct mu_m_server_connect_data mu_m_server_connect_data_t; | 96 | typedef struct mu_m_server_connect_data mu_m_server_connect_data_t; |
101 | typedef int (*mu_m_server_handler_fp) (int fd, struct sockaddr *sa, int salen, | 97 | typedef int (*mu_m_server_handler_fp) (int fd, struct sockaddr *sa, int salen, |
102 | struct mu_srv_config *pconf, | 98 | struct mu_srv_config *pconf, |
... | @@ -149,4 +145,6 @@ int mu_m_server_check_acl (mu_m_server_t msrv, struct sockaddr *s, int salen); | ... | @@ -149,4 +145,6 @@ int mu_m_server_check_acl (mu_m_server_t msrv, struct sockaddr *s, int salen); |
149 | struct mu_cfg_param; | 145 | struct mu_cfg_param; |
150 | void mu_m_server_cfg_init (mu_m_server_t msrv, struct mu_cfg_param *app_param); | 146 | void mu_m_server_cfg_init (mu_m_server_t msrv, struct mu_cfg_param *app_param); |
151 | 147 | ||
148 | int mu_sid (char **); | ||
149 | |||
152 | #endif | 150 | #endif | ... | ... |
... | @@ -21,6 +21,7 @@ libserver_la_SOURCES = \ | ... | @@ -21,6 +21,7 @@ libserver_la_SOURCES = \ |
21 | acl.c\ | 21 | acl.c\ |
22 | server.c\ | 22 | server.c\ |
23 | msrv.c\ | 23 | msrv.c\ |
24 | ipsrv.c | 24 | ipsrv.c\ |
25 | sid.c | ||
25 | 26 | ||
26 | AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils | 27 | AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils | ... | ... |
... | @@ -36,7 +36,10 @@ | ... | @@ -36,7 +36,10 @@ |
36 | #include <mailutils/errno.h> | 36 | #include <mailutils/errno.h> |
37 | #include <mailutils/nls.h> | 37 | #include <mailutils/nls.h> |
38 | #include <mailutils/sockaddr.h> | 38 | #include <mailutils/sockaddr.h> |
39 | 39 | #include <mailutils/stream.h> | |
40 | #include <mailutils/stdstream.h> | ||
41 | #include <mailutils/filter.h> | ||
42 | #include <mailutils/syslog.h> | ||
40 | 43 | ||
41 | struct _mu_ip_server | 44 | struct _mu_ip_server |
42 | { | 45 | { |
... | @@ -386,7 +389,6 @@ mu_ip_tcp_accept (mu_ip_server_t srv, void *call_data) | ... | @@ -386,7 +389,6 @@ mu_ip_tcp_accept (mu_ip_server_t srv, void *call_data) |
386 | mu_acl_result_t res; | 389 | mu_acl_result_t res; |
387 | int rc; | 390 | int rc; |
388 | 391 | ||
389 | mu_acl_set_session_id (srv->acl); | ||
390 | rc = mu_acl_check_sockaddr (srv->acl, &client.sa, size, &res); | 392 | rc = mu_acl_check_sockaddr (srv->acl, &client.sa, size, &res); |
391 | if (rc) | 393 | if (rc) |
392 | mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR, | 394 | mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR, |
... | @@ -470,7 +472,6 @@ mu_ip_udp_accept (mu_ip_server_t srv, void *call_data) | ... | @@ -470,7 +472,6 @@ mu_ip_udp_accept (mu_ip_server_t srv, void *call_data) |
470 | mu_acl_result_t res; | 472 | mu_acl_result_t res; |
471 | int rc; | 473 | int rc; |
472 | 474 | ||
473 | mu_acl_set_session_id (srv->acl); | ||
474 | rc = mu_acl_check_sockaddr (srv->acl, &client.sa, size, &res); | 475 | rc = mu_acl_check_sockaddr (srv->acl, &client.sa, size, &res); |
475 | if (rc) | 476 | if (rc) |
476 | mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR, | 477 | mu_debug (MU_DEBCAT_SERVER, MU_DEBUG_ERROR, |
... | @@ -488,12 +489,91 @@ mu_ip_udp_accept (mu_ip_server_t srv, void *call_data) | ... | @@ -488,12 +489,91 @@ mu_ip_udp_accept (mu_ip_server_t srv, void *call_data) |
488 | return rc; | 489 | return rc; |
489 | } | 490 | } |
490 | 491 | ||
492 | static int | ||
493 | set_strerr_flt (void) | ||
494 | { | ||
495 | mu_stream_t flt, trans[2]; | ||
496 | int rc; | ||
497 | |||
498 | if (!mu_log_session_id) | ||
499 | return ENOSYS; | ||
500 | |||
501 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans); | ||
502 | if (rc == 0) | ||
503 | { | ||
504 | char *sid; | ||
505 | char *argv[] = { "inline-comment", NULL, "-S", NULL }; | ||
506 | |||
507 | rc = mu_sid (&sid); | ||
508 | if (rc) | ||
509 | { | ||
510 | mu_diag_funcall (MU_DIAG_ERR, "mu_sid", NULL, rc); | ||
511 | return 0; | ||
512 | } | ||
513 | |||
514 | argv[1] = sid; | ||
515 | rc = mu_filter_create_args (&flt, trans[0], "inline-comment", 3, | ||
516 | (const char **)argv, | ||
517 | MU_FILTER_ENCODE, MU_STREAM_WRITE); | ||
518 | free (sid); | ||
519 | mu_stream_unref (trans[0]); | ||
520 | if (rc == 0) | ||
521 | { | ||
522 | mu_stream_set_buffer (flt, mu_buffer_line, 0); | ||
523 | trans[0] = flt; | ||
524 | trans[1] = NULL; | ||
525 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, | ||
526 | MU_IOCTL_OP_SET, trans); | ||
527 | mu_stream_unref (trans[0]); | ||
528 | if (rc) | ||
529 | mu_error (_("%s failed: %s"), "MU_IOCTL_SET_STREAM", | ||
530 | mu_stream_strerror (mu_strerr, rc)); | ||
531 | } | ||
532 | else | ||
533 | mu_error (_("cannot create log filter stream: %s"), mu_strerror (rc)); | ||
534 | } | ||
535 | else | ||
536 | { | ||
537 | mu_error (_("%s failed: %s"), "MU_IOCTL_GET_STREAM", | ||
538 | mu_stream_strerror (mu_strerr, rc)); | ||
539 | } | ||
540 | return rc; | ||
541 | } | ||
542 | |||
543 | static void | ||
544 | clr_strerr_flt (void) | ||
545 | { | ||
546 | mu_stream_t flt, trans[2]; | ||
547 | int rc; | ||
548 | |||
549 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans); | ||
550 | if (rc == 0) | ||
551 | { | ||
552 | flt = trans[0]; | ||
553 | |||
554 | rc = mu_stream_ioctl (flt, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans); | ||
555 | if (rc == 0) | ||
556 | { | ||
557 | mu_stream_unref (trans[0]); | ||
558 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, | ||
559 | MU_IOCTL_OP_SET, trans); | ||
560 | if (rc == 0) | ||
561 | mu_stream_unref (flt); | ||
562 | } | ||
563 | } | ||
564 | } | ||
565 | |||
491 | int | 566 | int |
492 | mu_ip_server_accept (mu_ip_server_t srv, void *call_data) | 567 | mu_ip_server_accept (mu_ip_server_t srv, void *call_data) |
493 | { | 568 | { |
494 | int rc; | 569 | int rc; |
570 | int flt; | ||
571 | |||
495 | if (!srv || srv->fd == -1) | 572 | if (!srv || srv->fd == -1) |
496 | return EINVAL; | 573 | return EINVAL; |
574 | |||
575 | flt = set_strerr_flt (); | ||
576 | |||
497 | switch (srv->type) | 577 | switch (srv->type) |
498 | { | 578 | { |
499 | case MU_IP_UDP: | 579 | case MU_IP_UDP: |
... | @@ -510,27 +590,12 @@ mu_ip_server_accept (mu_ip_server_t srv, void *call_data) | ... | @@ -510,27 +590,12 @@ mu_ip_server_accept (mu_ip_server_t srv, void *call_data) |
510 | mu_strerror (rc)); | 590 | mu_strerror (rc)); |
511 | mu_ip_server_shutdown (srv); | 591 | mu_ip_server_shutdown (srv); |
512 | } | 592 | } |
593 | if (flt == 0) | ||
594 | clr_strerr_flt (); | ||
513 | return rc; | 595 | return rc; |
514 | } | 596 | } |
515 | 597 | ||
516 | int | 598 | int |
517 | mu_ip_server_loop (mu_ip_server_t srv, void *call_data) | ||
518 | { | ||
519 | if (!srv) | ||
520 | return EINVAL; | ||
521 | while (srv->fd != -1) | ||
522 | { | ||
523 | int rc = mu_ip_server_accept (srv, call_data); | ||
524 | if (rc && rc != EINTR) | ||
525 | { | ||
526 | mu_ip_server_shutdown (srv); | ||
527 | return rc; | ||
528 | } | ||
529 | } | ||
530 | return 0; | ||
531 | } | ||
532 | |||
533 | int | ||
534 | mu_ip_server_get_fd (mu_ip_server_t srv) | 599 | mu_ip_server_get_fd (mu_ip_server_t srv) |
535 | { | 600 | { |
536 | return srv->fd; | 601 | return srv->fd; | ... | ... |
... | @@ -676,7 +676,6 @@ mu_m_server_check_acl (mu_m_server_t msrv, struct sockaddr *s, int salen) | ... | @@ -676,7 +676,6 @@ mu_m_server_check_acl (mu_m_server_t msrv, struct sockaddr *s, int salen) |
676 | mu_acl_result_t res; | 676 | mu_acl_result_t res; |
677 | int rc; | 677 | int rc; |
678 | 678 | ||
679 | mu_acl_set_session_id (msrv->acl); | ||
680 | rc = mu_acl_check_sockaddr (msrv->acl, s, salen, &res); | 679 | rc = mu_acl_check_sockaddr (msrv->acl, s, salen, &res); |
681 | if (rc) | 680 | if (rc) |
682 | { | 681 | { | ... | ... |
... | @@ -41,8 +41,6 @@ struct _mu_connection | ... | @@ -41,8 +41,6 @@ struct _mu_connection |
41 | 41 | ||
42 | #define MU_SERVER_TIMEOUT 0x1 | 42 | #define MU_SERVER_TIMEOUT 0x1 |
43 | 43 | ||
44 | unsigned long mu_session_id; | ||
45 | |||
46 | struct _mu_server | 44 | struct _mu_server |
47 | { | 45 | { |
48 | int nfd; | 46 | int nfd; |
... | @@ -111,7 +109,6 @@ connection_loop (mu_server_t srv, fd_set *fdset) | ... | @@ -111,7 +109,6 @@ connection_loop (mu_server_t srv, fd_set *fdset) |
111 | { | 109 | { |
112 | int rc; | 110 | int rc; |
113 | 111 | ||
114 | ++mu_session_id; | ||
115 | rc = conn->f_loop (conn->fd, conn->data, srv->server_data); | 112 | rc = conn->f_loop (conn->fd, conn->data, srv->server_data); |
116 | switch (rc) | 113 | switch (rc) |
117 | { | 114 | { |
... | @@ -300,11 +297,4 @@ mu_server_add_connection (mu_server_t srv, | ... | @@ -300,11 +297,4 @@ mu_server_add_connection (mu_server_t srv, |
300 | return 0; | 297 | return 0; |
301 | } | 298 | } |
302 | 299 | ||
303 | int | ||
304 | mu_acl_set_session_id (mu_acl_t acl) | ||
305 | { | ||
306 | char sessidstr[9]; | ||
307 | snprintf (sessidstr, sizeof sessidstr, "%08lx", mu_session_id); | ||
308 | return mu_acl_setenv (acl, "sessid", sessidstr); | ||
309 | } | ||
310 | 300 | ... | ... |
libmailutils/server/sid.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2017 Free Software Foundation, Inc. | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 3 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General | ||
15 | Public License along with this library; If not, see | ||
16 | <http://www.gnu.org/licenses/>. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | #include <config.h> | ||
20 | #endif | ||
21 | #include <sys/types.h> | ||
22 | #include <sys/time.h> | ||
23 | #include <unistd.h> | ||
24 | #include <time.h> | ||
25 | #include <string.h> | ||
26 | #include <mailutils/errno.h> | ||
27 | #include <mailutils/alloc.h> | ||
28 | |||
29 | #define SID_ABC "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | ||
30 | #define SID_LEN (sizeof (SID_ABC) - 1) | ||
31 | #define SID_LEN_SQR (SID_LEN * SID_LEN) | ||
32 | |||
33 | /* Generate (almost) unique session ID. The idea borrowed from Sendmail | ||
34 | queue ID. | ||
35 | */ | ||
36 | int | ||
37 | mu_sid (char **res) | ||
38 | { | ||
39 | static int init; | ||
40 | static unsigned int seqno = 0; | ||
41 | static char abc[] = SID_ABC; | ||
42 | |||
43 | struct timeval t; | ||
44 | struct tm *tm; | ||
45 | unsigned int n; | ||
46 | char sidbuf[9]; | ||
47 | char *p; | ||
48 | |||
49 | if (!res) | ||
50 | return MU_ERR_OUT_PTR_NULL; | ||
51 | |||
52 | gettimeofday (&t, NULL); | ||
53 | |||
54 | if (!init) | ||
55 | { | ||
56 | seqno = getpid () + t.tv_sec + t.tv_usec; | ||
57 | init = 1; | ||
58 | } | ||
59 | |||
60 | n = seqno++ % SID_LEN_SQR; | ||
61 | tm = gmtime (&t.tv_sec); | ||
62 | sidbuf[0] = abc[tm->tm_year % SID_LEN]; | ||
63 | sidbuf[1] = abc[tm->tm_mon]; | ||
64 | sidbuf[2] = abc[tm->tm_mday]; | ||
65 | sidbuf[3] = abc[tm->tm_hour]; | ||
66 | sidbuf[4] = abc[tm->tm_min % SID_LEN]; | ||
67 | sidbuf[5] = abc[tm->tm_sec % SID_LEN]; | ||
68 | sidbuf[6] = abc[n / SID_LEN]; | ||
69 | sidbuf[7] = abc[n % SID_LEN]; | ||
70 | sidbuf[8] = 0; | ||
71 | |||
72 | p = strdup (sidbuf); | ||
73 | if (!p) | ||
74 | return errno; | ||
75 | *res = p; | ||
76 | return 0; | ||
77 | } |
... | @@ -392,91 +392,18 @@ pop3d_mainloop (int ifd, int ofd, struct pop3d_srv_config *cfg) | ... | @@ -392,91 +392,18 @@ pop3d_mainloop (int ifd, int ofd, struct pop3d_srv_config *cfg) |
392 | 392 | ||
393 | return status; | 393 | return status; |
394 | } | 394 | } |
395 | 395 | ||
396 | static int | ||
397 | set_strerr_flt () | ||
398 | { | ||
399 | mu_stream_t flt, trans[2]; | ||
400 | int rc; | ||
401 | |||
402 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans); | ||
403 | if (rc == 0) | ||
404 | { | ||
405 | char sessidstr[10]; | ||
406 | char *argv[] = { "inline-comment", NULL, "-S", NULL }; | ||
407 | |||
408 | snprintf (sessidstr, sizeof sessidstr, "%08lx:", mu_session_id); | ||
409 | argv[1] = sessidstr; | ||
410 | rc = mu_filter_create_args (&flt, trans[0], "inline-comment", 3, | ||
411 | (const char **)argv, | ||
412 | MU_FILTER_ENCODE, MU_STREAM_WRITE); | ||
413 | mu_stream_unref (trans[0]); | ||
414 | if (rc == 0) | ||
415 | { | ||
416 | mu_stream_set_buffer (flt, mu_buffer_line, 0); | ||
417 | trans[0] = flt; | ||
418 | trans[1] = NULL; | ||
419 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, | ||
420 | MU_IOCTL_OP_SET, trans); | ||
421 | mu_stream_unref (trans[0]); | ||
422 | if (rc) | ||
423 | mu_error (_("%s failed: %s"), "MU_IOCTL_SET_STREAM", | ||
424 | mu_stream_strerror (mu_strerr, rc)); | ||
425 | } | ||
426 | else | ||
427 | mu_error (_("cannot create log filter stream: %s"), mu_strerror (rc)); | ||
428 | } | ||
429 | else | ||
430 | { | ||
431 | mu_error (_("%s failed: %s"), "MU_IOCTL_GET_STREAM", | ||
432 | mu_stream_strerror (mu_strerr, rc)); | ||
433 | } | ||
434 | return rc; | ||
435 | } | ||
436 | |||
437 | static void | ||
438 | clr_strerr_flt () | ||
439 | { | ||
440 | mu_stream_t flt, trans[2]; | ||
441 | int rc; | ||
442 | |||
443 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans); | ||
444 | if (rc == 0) | ||
445 | { | ||
446 | flt = trans[0]; | ||
447 | |||
448 | rc = mu_stream_ioctl (flt, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans); | ||
449 | if (rc == 0) | ||
450 | { | ||
451 | mu_stream_unref (trans[0]); | ||
452 | rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, | ||
453 | MU_IOCTL_OP_SET, trans); | ||
454 | if (rc == 0) | ||
455 | mu_stream_unref (flt); | ||
456 | } | ||
457 | } | ||
458 | } | ||
459 | |||
460 | int | 396 | int |
461 | pop3d_connection (int fd, struct sockaddr *sa, int salen, | 397 | pop3d_connection (int fd, struct sockaddr *sa, int salen, |
462 | struct mu_srv_config *pconf, | 398 | struct mu_srv_config *pconf, |
463 | void *data) | 399 | void *data) |
464 | { | 400 | { |
465 | struct pop3d_srv_config *cfg = (struct pop3d_srv_config *) pconf; | 401 | struct pop3d_srv_config *cfg = (struct pop3d_srv_config *) pconf; |
466 | int rc; | ||
467 | 402 | ||
468 | idle_timeout = pconf->timeout; | 403 | idle_timeout = cfg->m_cfg.timeout; |
469 | pop3d_transcript = pconf->transcript; | 404 | pop3d_transcript = cfg->m_cfg.transcript; |
470 | |||
471 | if (mu_log_session_id) | ||
472 | rc = set_strerr_flt (); | ||
473 | else | ||
474 | rc = 1; | ||
475 | 405 | ||
476 | pop3d_mainloop (fd, fd, cfg); | 406 | pop3d_mainloop (fd, fd, cfg); |
477 | |||
478 | if (rc == 0) | ||
479 | clr_strerr_flt (); | ||
480 | return 0; | 407 | return 0; |
481 | } | 408 | } |
482 | 409 | ... | ... |
-
Please register or sign in to post a comment