diff -rNu slrn-0.9.8.0-debian/configure.in slrn-0.9.8.0/configure.in --- slrn-0.9.8.0-debian/configure.in Mon Aug 25 15:38:10 2003 +++ slrn-0.9.8.0/configure.in Fri Aug 29 15:01:15 2003 @@ -309,6 +309,7 @@ gettimeofday \ setlocale \ isalpha isspace isdigit isalnum ispunct \ +strsignal \ getaddrinfo getnameinfo \ ) diff -rNu slrn-0.9.8.0-debian/src/config.h.in slrn-0.9.8.0/src/config.h.in --- slrn-0.9.8.0-debian/src/config.h.in Mon Aug 25 15:40:50 2003 +++ slrn-0.9.8.0/src/config.h.in Fri Aug 29 15:03:31 2003 @@ -123,6 +123,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H +/* Define to 1 if you have the `strsignal' function. */ +#undef HAVE_STRSIGNAL + /* Define to 1 if you have the header file, and it defines `DIR'. */ #undef HAVE_SYS_DIR_H diff -rNu slrn-0.9.8.0-debian/src/nntplib.c slrn-0.9.8.0/src/nntplib.c --- slrn-0.9.8.0-debian/src/nntplib.c Thu Jul 31 16:54:50 2003 +++ slrn-0.9.8.0/src/nntplib.c Fri Aug 29 15:29:03 2003 @@ -22,6 +22,7 @@ #include "slrnfeat.h" #include #include +#include #ifdef HAVE_STDLIB_H # include @@ -31,6 +32,15 @@ # include #endif +#if HAVE_SYS_WAIT_H +# define NNTPAUTH 1 +#endif + +#ifdef NNTPAUTH +# include +# include +#endif + #include #include #include "jdmacros.h" @@ -407,6 +417,74 @@ int nntp_authorization (NNTP_Type *s) { char *name, *pass; + +#ifdef NNTPAUTH + const char *nntpauth = getenv("NNTPAUTH"); + + if(nntpauth) { + static int cookie_fd = -1; + pid_t child, r; + int status; + + slrn_message_now ("Authenticating with AUTHINFO GENERIC ..."); + if(cookie_fd == -1) { + const char *nntp_auth_fds = getenv("NNTP_AUTH_FDS"); + if(nntp_auth_fds) + sscanf(nntp_auth_fds, "%*u.%*u.%d", &cookie_fd); + if(cookie_fd == -1) { + FILE *cookie_file = tmpfile(); + + if(!cookie_file) { + slrn_error ("error creating temporary file: %s", strerror(errno)); + return -1; + } + cookie_fd = fileno(cookie_file); + } + } + if (-1 == nntp_start_server_vcmd (s, "AUTHINFO GENERIC %s", nntpauth)) + return -1; + child = fork(); + if(child == -1) { + slrn_error ("error forking NNTPAUTH child: %s", strerror(errno)); + return -1; + } + if(!child) { + char buf[128]; + + sprintf(buf, "NNTP_AUTH_FDS=%d.%d.%d", + sltcp_get_fd(s->tcp), sltcp_get_fd(s->tcp), cookie_fd); + /* XXX we'd like to generate an error message, but what's the + right way to do it? */ + if(putenv(buf)) + _exit(-1); + execlp("sh", "sh", "-c", nntpauth, (char *)0); + _exit(-1); + } + while((r = waitpid(child, &status, 0)) < 0 && errno == EINTR) + ; + if(r < 0) { + slrn_error ("error waiting for NNTPAUTH child: %s", strerror(errno)); + return -1; + } + if(WIFEXITED(status) && WEXITSTATUS(status)) { + slrn_error ("NNTPAUTH failed: status %d", WEXITSTATUS(status)); + return -1; + } else if(WIFSIGNALED(status)) { +#if HAVE_STRSIGNAL + slrn_error ("NNTPAUTH failed: signal %d (%s)", + WTERMSIG(status), strsignal(WTERMSIG(status))); +#else + slrn_error ("NNTPAUTH failed: signal %d", WTERMSIG(status)); +#endif + return -1; + } else if(status) { + slrn_error ("NNTPAUTH failed: wstat %#x", (unsigned)status); + return -1; + } + s->can_post = 1; + return 0; + } +#endif if ((NNTP_Authorization_Hook == NULL) || (-1 == (*NNTP_Authorization_Hook) (s->name, &name, &pass)) ||