@ -15,6 +15,7 @@
# include "feuille.h"
# include "feuille.h"
# ifndef COSMOPOLITAN
# include <errno.h> /* for errno, ERANGE, EAGAIN, EFBIG, ENOENT */
# include <errno.h> /* for errno, ERANGE, EAGAIN, EFBIG, ENOENT */
# include <grp.h> /* for initgroups */
# include <grp.h> /* for initgroups */
# include <limits.h> /* for USHRT_MAX, ULONG_MAX, CHAR_MAX, PATH_MAX, UCHA... */
# include <limits.h> /* for USHRT_MAX, ULONG_MAX, CHAR_MAX, PATH_MAX, UCHA... */
@ -29,6 +30,7 @@
# include <syslog.h> /* for syslog, openlog, LOG_WARNING, LOG_NDELAY, LOG_... */
# include <syslog.h> /* for syslog, openlog, LOG_WARNING, LOG_NDELAY, LOG_... */
# include <time.h> /* for time */
# include <time.h> /* for time */
# include <unistd.h> /* for getuid, access, chdir, chown, chroot, close */
# include <unistd.h> /* for getuid, access, chdir, chown, chroot, close */
# endif
# include "arg.h" /* for EARGF, ARGBEGIN, ARGEND */
# include "arg.h" /* for EARGF, ARGBEGIN, ARGEND */
# include "bin.h" /* for create_url, generate_id, write_paste */
# include "bin.h" /* for create_url, generate_id, write_paste */
@ -93,6 +95,12 @@ void accept_loop(int server)
/* accept loop */
/* accept loop */
int connection ;
int connection ;
while ( ( connection = accept_connection ( server ) ) ) {
while ( ( connection = accept_connection ( server ) ) ) {
/* check if the socket is invalid */
if ( connection = = - 1 ) {
error ( " error while accepting incoming connection: %s " , strerror ( errno ) ) ;
continue ;
}
verbose ( 1 , " --- new incoming connection. connection ID: %d:%d --- " , pid , time ( 0 ) ) ;
verbose ( 1 , " --- new incoming connection. connection ID: %d:%d --- " , pid , time ( 0 ) ) ;
unsigned long paste_size = 0 ;
unsigned long paste_size = 0 ;
@ -342,7 +350,6 @@ int main(int argc, char *argv[])
gid = user - > pw_gid ;
gid = user - > pw_gid ;
} else {
} else {
puts ( " " ) ;
syslog ( LOG_WARNING , " running as non-root user. " ) ;
syslog ( LOG_WARNING , " running as non-root user. " ) ;
syslog ( LOG_WARNING , " `chroot' and user switching have been disabled. " ) ;
syslog ( LOG_WARNING , " `chroot' and user switching have been disabled. " ) ;
puts ( " " ) ;
puts ( " " ) ;
@ -382,15 +389,18 @@ int main(int argc, char *argv[])
if ( setgid ( gid ) ! = 0 | | getgid ( ) ! = gid )
if ( setgid ( gid ) ! = 0 | | getgid ( ) ! = gid )
die ( 1 , " could not switch to group for user `%s'. \n " , settings . user ) ;
die ( 1 , " could not switch to group for user `%s'. \n " , settings . user ) ;
# ifndef COSMOPOLITAN
/* initgroups doesn't work on cosmopolitan libc yet */
if ( initgroups ( settings . user , gid ) ! = 0 )
if ( initgroups ( settings . user , gid ) ! = 0 )
die ( 1 , " could not initialize other groups for user `%s'. \n " , settings . user ) ;
die ( 1 , " could not initialize other groups for user `%s'. \n " , settings . user ) ;
# endif
/* switching user */
/* switching user */
if ( setuid ( uid ) ! = 0 | | getuid ( ) ! = uid )
if ( setuid ( uid ) ! = 0 | | getuid ( ) ! = uid )
die ( 1 , " could not switch to user `%s'. \n " , settings . user ) ;
die ( 1 , " could not switch to user `%s'. \n " , settings . user ) ;
}
}
# if def __OpenBSD__
# if defined __OpenBSD__ || defined COSMOPOLITAN
/* OpenBSD-only security measures */
/* OpenBSD-only security measures */
pledge ( " proc stdio rpath wpath cpath inet " , " stdio rpath wpath cpath inet " ) ;
pledge ( " proc stdio rpath wpath cpath inet " , " stdio rpath wpath cpath inet " ) ;
# endif
# endif