9d46370ca3
This automatically-generated patch converts 703 function definitions in glibc from old-style K&R to prototype-style. This conversion is deliberately simplistic, excluding any tricky cases as even a patch covering only simple cases is still very large. Currently excluded are: sysdeps files (to improve test coverage for the initial patch); files containing assertions (to avoid line number changes so that generated libraries can be compared); any cases where the generated function declaration would involve lines over 79 characters and so need to be wrapped; any cases with array parameters or other cases where parameter declarators don't end with the parameter name; any other cases that my script didn't parse. I didn't try to make the ChangeLog generation indicate when function definitions are conditional; it just lists the functions changed without regard to that. Tested for x86_64 and x86 (testsuite, and that installed stripped shared libraries are unchanged by the patch). * crypt/cert.c (good_bye): Convert to prototype-style function definition. (get8): Likewise. (put8): Likewise. * crypt/crypt-entry.c (crypt): Likewise. (__fcrypt): Likewise. * crypt/crypt_util.c (_ufc_prbits): Likewise. (_ufc_set_bits): Likewise. (_ufc_clearmem): Likewise. (__init_des_r): Likewise. (shuffle_sb): Likewise. (shuffle_sb): Likewise. (_ufc_setup_salt_r): Likewise. (_ufc_mk_keytab_r): Likewise. (_ufc_dofinalperm_r): Likewise. (encrypt): Likewise. (__setkey_r): Likewise. (setkey): Likewise. * crypt/md5.c (md5_init_ctx): Likewise. (md5_read_ctx): Likewise. (md5_finish_ctx): Likewise. (md5_stream): Likewise. (md5_buffer): Likewise. (md5_process_bytes): Likewise. * crypt/sha256.c (__sha256_init_ctx): Likewise. (__sha256_finish_ctx): Likewise. (__sha256_process_bytes): Likewise. * crypt/sha512.c (__sha512_init_ctx): Likewise. (__sha512_finish_ctx): Likewise. (__sha512_process_bytes): Likewise. * ctype/isctype.c (__isctype): Likewise. * debug/backtrace.c (__backtrace): Likewise. * debug/backtracesymsfd.c (__backtrace_symbols_fd): Likewise. * debug/fgets_chk.c (__fgets_chk): Likewise. * debug/fgets_u_chk.c (__fgets_unlocked_chk): Likewise. * debug/memcpy_chk.c (__memcpy_chk): Likewise. * debug/memmove_chk.c (MEMMOVE_CHK): Likewise. * debug/mempcpy_chk.c (__mempcpy_chk): Likewise. * debug/memset_chk.c (__memset_chk): Likewise. * debug/strcat_chk.c (__strcat_chk): Likewise. * debug/strncat_chk.c (__strncat_chk): Likewise. * debug/strncpy_chk.c (__strncpy_chk): Likewise. * debug/vsprintf_chk.c (_IO_str_chk_overflow): Likewise. * dirent/dirfd.c (dirfd): Likewise. * dirent/getdents.c (__getdirentries): Likewise. * dirent/getdents64.c (getdirentries64): Likewise. * dirent/rewinddir.c (__rewinddir): Likewise. * dirent/seekdir.c (seekdir): Likewise. * dirent/telldir.c (telldir): Likewise. * elf/sln.c (makesymlinks): Likewise. (makesymlink): Likewise. * gmon/gmon.c (__moncontrol): Likewise. (__monstartup): Likewise. (write_hist): Likewise. (write_call_graph): Likewise. (write_bb_counts): Likewise. * grp/setgroups.c (setgroups): Likewise. * inet/inet_lnaof.c (inet_lnaof): Likewise. * inet/inet_net.c (inet_network): Likewise. * inet/inet_netof.c (inet_netof): Likewise. * inet/rcmd.c (rresvport_af): Likewise. (rresvport): Likewise. * io/access.c (__access): Likewise. * io/chdir.c (__chdir): Likewise. * io/chmod.c (__chmod): Likewise. * io/chown.c (__chown): Likewise. * io/close.c (__close): Likewise. * io/creat.c (creat): Likewise. * io/creat64.c (creat64): Likewise. * io/dup.c (__dup): Likewise. * io/dup2.c (__dup2): Likewise. * io/dup3.c (__dup3): Likewise. * io/euidaccess.c (__euidaccess): Likewise. * io/faccessat.c (faccessat): Likewise. * io/fchmod.c (__fchmod): Likewise. * io/fchmodat.c (fchmodat): Likewise. * io/fchown.c (__fchown): Likewise. * io/fchownat.c (fchownat): Likewise. * io/fcntl.c (__fcntl): Likewise. * io/flock.c (__flock): Likewise. * io/fts.c (fts_load): Likewise. (fts_close): Likewise. (fts_read): Likewise. (fts_set): Likewise. (fts_children): Likewise. (fts_build): Likewise. (fts_stat): Likewise. (fts_sort): Likewise. (fts_alloc): Likewise. (fts_lfree): Likewise. (fts_palloc): Likewise. (fts_padjust): Likewise. (fts_maxarglen): Likewise. (fts_safe_changedir): Likewise. * io/getwd.c (getwd): Likewise. * io/isatty.c (__isatty): Likewise. * io/lchown.c (__lchown): Likewise. * io/link.c (__link): Likewise. * io/linkat.c (linkat): Likewise. * io/lseek.c (__libc_lseek): Likewise. * io/mkdir.c (__mkdir): Likewise. * io/mkdirat.c (mkdirat): Likewise. * io/mkfifo.c (mkfifo): Likewise. * io/mkfifoat.c (mkfifoat): Likewise. * io/open.c (__libc_open): Likewise. * io/open64.c (__libc_open64): Likewise. * io/readlink.c (__readlink): Likewise. * io/readlinkat.c (readlinkat): Likewise. * io/rmdir.c (__rmdir): Likewise. * io/symlink.c (__symlink): Likewise. * io/symlinkat.c (symlinkat): Likewise. * io/ttyname.c (ttyname): Likewise. * io/ttyname_r.c (__ttyname_r): Likewise. * io/umask.c (__umask): Likewise. * io/unlink.c (__unlink): Likewise. * io/unlinkat.c (unlinkat): Likewise. * io/utime.c (utime): Likewise. * libio/clearerr.c (clearerr): Likewise. * libio/clearerr_u.c (clearerr_unlocked): Likewise. * libio/feof.c (_IO_feof): Likewise. * libio/feof_u.c (feof_unlocked): Likewise. * libio/ferror.c (_IO_ferror): Likewise. * libio/ferror_u.c (ferror_unlocked): Likewise. * libio/filedoalloc.c (_IO_file_doallocate): Likewise. * libio/fileno.c (__fileno): Likewise. * libio/fputc.c (fputc): Likewise. * libio/fputc_u.c (fputc_unlocked): Likewise. * libio/fputwc.c (fputwc): Likewise. * libio/fputwc_u.c (fputwc_unlocked): Likewise. * libio/freopen.c (freopen): Likewise. * libio/freopen64.c (freopen64): Likewise. * libio/fseek.c (fseek): Likewise. * libio/fseeko.c (fseeko): Likewise. * libio/fseeko64.c (fseeko64): Likewise. * libio/ftello.c (__ftello): Likewise. * libio/ftello64.c (ftello64): Likewise. * libio/fwide.c (fwide): Likewise. * libio/genops.c (_IO_un_link): Likewise. (_IO_link_in): Likewise. (_IO_least_marker): Likewise. (_IO_switch_to_main_get_area): Likewise. (_IO_switch_to_backup_area): Likewise. (_IO_switch_to_get_mode): Likewise. (_IO_free_backup_area): Likewise. (_IO_switch_to_put_mode): Likewise. (__overflow): Likewise. (__underflow): Likewise. (__uflow): Likewise. (_IO_setb): Likewise. (_IO_doallocbuf): Likewise. (_IO_default_underflow): Likewise. (_IO_default_uflow): Likewise. (_IO_default_xsputn): Likewise. (_IO_sgetn): Likewise. (_IO_default_xsgetn): Likewise. (_IO_sync): Likewise. (_IO_default_setbuf): Likewise. (_IO_default_seekpos): Likewise. (_IO_default_doallocate): Likewise. (_IO_init): Likewise. (_IO_old_init): Likewise. (_IO_default_sync): Likewise. (_IO_default_finish): Likewise. (_IO_default_seekoff): Likewise. (_IO_sputbackc): Likewise. (_IO_sungetc): Likewise. (_IO_set_column): Likewise. (_IO_set_column): Likewise. (_IO_adjust_column): Likewise. (_IO_get_column): Likewise. (_IO_init_marker): Likewise. (_IO_remove_marker): Likewise. (_IO_marker_difference): Likewise. (_IO_marker_delta): Likewise. (_IO_seekmark): Likewise. (_IO_unsave_markers): Likewise. (_IO_nobackup_pbackfail): Likewise. (_IO_default_pbackfail): Likewise. (_IO_default_seek): Likewise. (_IO_default_stat): Likewise. (_IO_default_read): Likewise. (_IO_default_write): Likewise. (_IO_default_showmanyc): Likewise. (_IO_default_imbue): Likewise. (_IO_iter_next): Likewise. (_IO_iter_file): Likewise. * libio/getc.c (_IO_getc): Likewise. * libio/getwc.c (_IO_getwc): Likewise. * libio/iofclose.c (_IO_new_fclose): Likewise. * libio/iofdopen.c (_IO_new_fdopen): Likewise. * libio/iofflush.c (_IO_fflush): Likewise. * libio/iofflush_u.c (__fflush_unlocked): Likewise. * libio/iofgetpos.c (_IO_new_fgetpos): Likewise. * libio/iofgetpos64.c (_IO_new_fgetpos64): Likewise. * libio/iofgets.c (_IO_fgets): Likewise. * libio/iofgets_u.c (__fgets_unlocked): Likewise. * libio/iofgetws.c (fgetws): Likewise. * libio/iofgetws_u.c (fgetws_unlocked): Likewise. * libio/iofopen64.c (_IO_fopen64): Likewise. * libio/iofopncook.c (_IO_cookie_read): Likewise. (_IO_cookie_write): Likewise. (_IO_cookie_seek): Likewise. (_IO_cookie_close): Likewise. (_IO_cookie_seekoff): Likewise. (_IO_old_cookie_seek): Likewise. * libio/iofputs.c (_IO_fputs): Likewise. * libio/iofputs_u.c (__fputs_unlocked): Likewise. * libio/iofputws.c (fputws): Likewise. * libio/iofputws_u.c (fputws_unlocked): Likewise. * libio/iofread.c (_IO_fread): Likewise. * libio/iofread_u.c (__fread_unlocked): Likewise. * libio/iofsetpos.c (_IO_new_fsetpos): Likewise. * libio/iofsetpos64.c (_IO_new_fsetpos64): Likewise. * libio/ioftell.c (_IO_ftell): Likewise. * libio/iofwrite.c (_IO_fwrite): Likewise. * libio/iogetdelim.c (_IO_getdelim): Likewise. * libio/iogets.c (_IO_gets): Likewise. * libio/iopadn.c (_IO_padn): Likewise. * libio/iopopen.c (_IO_new_proc_open): Likewise. (_IO_new_popen): Likewise. (_IO_new_proc_close): Likewise. * libio/ioputs.c (_IO_puts): Likewise. * libio/ioseekoff.c (_IO_seekoff_unlocked): Likewise. (_IO_seekoff): Likewise. * libio/ioseekpos.c (_IO_seekpos_unlocked): Likewise. (_IO_seekpos): Likewise. * libio/iosetbuffer.c (_IO_setbuffer): Likewise. * libio/iosetvbuf.c (_IO_setvbuf): Likewise. * libio/ioungetc.c (_IO_ungetc): Likewise. * libio/ioungetwc.c (ungetwc): Likewise. * libio/iovdprintf.c (_IO_vdprintf): Likewise. * libio/iovsscanf.c (_IO_vsscanf): Likewise. * libio/iowpadn.c (_IO_wpadn): Likewise. * libio/libc_fatal.c (__libc_fatal): Likewise. * libio/memstream.c (__open_memstream): Likewise. (_IO_mem_sync): Likewise. (_IO_mem_finish): Likewise. * libio/oldfileops.c (_IO_old_file_init): Likewise. (_IO_old_file_close_it): Likewise. (_IO_old_file_finish): Likewise. (_IO_old_file_fopen): Likewise. (_IO_old_file_attach): Likewise. (_IO_old_file_setbuf): Likewise. (_IO_old_do_write): Likewise. (old_do_write): Likewise. (_IO_old_file_underflow): Likewise. (_IO_old_file_overflow): Likewise. (_IO_old_file_sync): Likewise. (_IO_old_file_seekoff): Likewise. (_IO_old_file_write): Likewise. (_IO_old_file_xsputn): Likewise. * libio/oldiofclose.c (_IO_old_fclose): Likewise. * libio/oldiofdopen.c (_IO_old_fdopen): Likewise. * libio/oldiofgetpos.c (_IO_old_fgetpos): Likewise. * libio/oldiofgetpos64.c (_IO_old_fgetpos64): Likewise. * libio/oldiofopen.c (_IO_old_fopen): Likewise. * libio/oldiofsetpos.c (_IO_old_fsetpos): Likewise. * libio/oldiofsetpos64.c (_IO_old_fsetpos64): Likewise. * libio/oldiopopen.c (_IO_old_proc_open): Likewise. (_IO_old_popen): Likewise. (_IO_old_proc_close): Likewise. * libio/oldpclose.c (__old_pclose): Likewise. * libio/pclose.c (__new_pclose): Likewise. * libio/peekc.c (_IO_peekc_locked): Likewise. * libio/putc.c (_IO_putc): Likewise. * libio/putc_u.c (putc_unlocked): Likewise. * libio/putchar.c (putchar): Likewise. * libio/putchar_u.c (putchar_unlocked): Likewise. * libio/putwc.c (putwc): Likewise. * libio/putwc_u.c (putwc_unlocked): Likewise. * libio/putwchar.c (putwchar): Likewise. * libio/putwchar_u.c (putwchar_unlocked): Likewise. * libio/rewind.c (rewind): Likewise. * libio/setbuf.c (setbuf): Likewise. * libio/setlinebuf.c (setlinebuf): Likewise. * libio/vasprintf.c (_IO_vasprintf): Likewise. * libio/vscanf.c (_IO_vscanf): Likewise. * libio/vsnprintf.c (_IO_strn_overflow): Likewise. * libio/vswprintf.c (_IO_wstrn_overflow): Likewise. * libio/wfiledoalloc.c (_IO_wfile_doallocate): Likewise. * libio/wgenops.c (_IO_least_wmarker): Likewise. (_IO_switch_to_main_wget_area): Likewise. (_IO_switch_to_wbackup_area): Likewise. (_IO_wsetb): Likewise. (_IO_wdefault_pbackfail): Likewise. (_IO_wdefault_finish): Likewise. (_IO_wdefault_uflow): Likewise. (__woverflow): Likewise. (__wuflow): Likewise. (__wunderflow): Likewise. (_IO_wdefault_xsputn): Likewise. (_IO_wdefault_xsgetn): Likewise. (_IO_wdoallocbuf): Likewise. (_IO_wdefault_doallocate): Likewise. (_IO_switch_to_wget_mode): Likewise. (_IO_free_wbackup_area): Likewise. (_IO_switch_to_wput_mode): Likewise. (_IO_sputbackwc): Likewise. (_IO_sungetwc): Likewise. (_IO_adjust_wcolumn): Likewise. (_IO_init_wmarker): Likewise. (_IO_wmarker_delta): Likewise. (_IO_seekwmark): Likewise. (_IO_unsave_wmarkers): Likewise. * libio/wmemstream.c (open_wmemstream): Likewise. (_IO_wmem_sync): Likewise. (_IO_wmem_finish): Likewise. * locale/nl_langinfo.c (nl_langinfo): Likewise. * locale/nl_langinfo_l.c (__nl_langinfo_l): Likewise. * locale/programs/simple-hash.c (init_hash): Likewise. (delete_hash): Likewise. (insert_entry): Likewise. (set_entry): Likewise. (next_prime): Likewise. (is_prime): Likewise. * locale/programs/xmalloc.c (fixup_null_alloc): Likewise. (xmalloc): Likewise. (xrealloc): Likewise. * locale/programs/xstrdup.c (xstrdup): Likewise. * localedata/collate-test.c (xstrcoll): Likewise. * localedata/xfrm-test.c (xstrcmp): Likewise. * login/getlogin_r.c (__getlogin_r): Likewise. * login/getpt.c (__posix_openpt): Likewise. * login/login_tty.c (login_tty): Likewise. * login/setlogin.c (setlogin): Likewise. * mach/msg-destroy.c (__mach_msg_destroy): Likewise. (mach_msg_destroy_port): Likewise. (mach_msg_destroy_memory): Likewise. * malloc/mcheck.c (flood): Likewise. * misc/acct.c (acct): Likewise. * misc/brk.c (__brk): Likewise. * misc/chflags.c (chflags): Likewise. * misc/chroot.c (chroot): Likewise. * misc/fchflags.c (fchflags): Likewise. * misc/fstab.c (getfsspec): Likewise. (getfsfile): Likewise. * misc/fsync.c (fsync): Likewise. * misc/ftruncate.c (__ftruncate): Likewise. * misc/ftruncate64.c (__ftruncate64): Likewise. * misc/getdomain.c (getdomainname): Likewise. (getdomainname): Likewise. * misc/gethostname.c (__gethostname): Likewise. * misc/getpass.c (getpass): Likewise. * misc/getttyent.c (skip): Likewise. (value): Likewise. * misc/gtty.c (gtty): Likewise. * misc/hsearch.c (hsearch): Likewise. (hcreate): Likewise. * misc/hsearch_r.c (__hcreate_r): Likewise. (__hdestroy_r): Likewise. * misc/ioctl.c (__ioctl): Likewise. * misc/mkdtemp.c (mkdtemp): Likewise. * misc/mkostemp.c (mkostemp): Likewise. * misc/mkostemp64.c (mkostemp64): Likewise. * misc/mkostemps.c (mkostemps): Likewise. * misc/mkostemps64.c (mkostemps64): Likewise. * misc/mkstemp.c (mkstemp): Likewise. * misc/mkstemp64.c (mkstemp64): Likewise. * misc/mkstemps.c (mkstemps): Likewise. * misc/mkstemps64.c (mkstemps64): Likewise. * misc/mktemp.c (__mktemp): Likewise. * misc/preadv.c (preadv): Likewise. * misc/preadv64.c (preadv64): Likewise. * misc/pwritev.c (pwritev): Likewise. * misc/pwritev64.c (pwritev64): Likewise. * misc/readv.c (__readv): Likewise. * misc/revoke.c (revoke): Likewise. * misc/setdomain.c (setdomainname): Likewise. * misc/setegid.c (setegid): Likewise. * misc/seteuid.c (seteuid): Likewise. * misc/sethostid.c (sethostid): Likewise. * misc/sethostname.c (sethostname): Likewise. * misc/setregid.c (__setregid): Likewise. * misc/setreuid.c (__setreuid): Likewise. * misc/sstk.c (sstk): Likewise. * misc/stty.c (stty): Likewise. * misc/syscall.c (syscall): Likewise. * misc/syslog.c (setlogmask): Likewise. * misc/truncate.c (__truncate): Likewise. * misc/truncate64.c (truncate64): Likewise. * misc/ualarm.c (ualarm): Likewise. * misc/usleep.c (usleep): Likewise. * misc/ustat.c (ustat): Likewise. * misc/writev.c (__writev): Likewise. * nptl/cleanup_compat.c (_pthread_cleanup_pop): Likewise. * nptl/old_pthread_cond_broadcast.c (__pthread_cond_broadcast_2_0): Likewise. * nptl/old_pthread_cond_destroy.c (__pthread_cond_destroy_2_0): Likewise. * nptl/old_pthread_cond_signal.c (__pthread_cond_signal_2_0): Likewise. * nptl/old_pthread_cond_wait.c (__pthread_cond_wait_2_0): Likewise. * nptl/pt-raise.c (raise): Likewise. * nptl/pthread_barrier_destroy.c (pthread_barrier_destroy): Likewise. * nptl/pthread_barrier_wait.c (__pthread_barrier_wait): Likewise. * nptl/pthread_barrierattr_destroy.c (pthread_barrierattr_destroy): Likewise. * nptl/pthread_barrierattr_init.c (pthread_barrierattr_init): Likewise. * nptl/pthread_barrierattr_setpshared.c (pthread_barrierattr_setpshared): Likewise. * nptl/pthread_cond_broadcast.c (__pthread_cond_broadcast): Likewise. * nptl/pthread_cond_destroy.c (__pthread_cond_destroy): Likewise. * nptl/pthread_cond_init.c (__pthread_cond_init): Likewise. * nptl/pthread_cond_signal.c (__pthread_cond_signal): Likewise. * nptl/pthread_condattr_destroy.c (__pthread_condattr_destroy): Likewise. * nptl/pthread_condattr_getclock.c (pthread_condattr_getclock): Likewise. * nptl/pthread_condattr_getpshared.c (pthread_condattr_getpshared): Likewise. * nptl/pthread_condattr_init.c (__pthread_condattr_init): Likewise. * nptl/pthread_condattr_setpshared.c (pthread_condattr_setpshared): Likewise. * nptl/pthread_detach.c (pthread_detach): Likewise. * nptl/pthread_equal.c (__pthread_equal): Likewise. * nptl/pthread_getcpuclockid.c (pthread_getcpuclockid): Likewise. * nptl/pthread_getspecific.c (__pthread_getspecific): Likewise. * nptl/pthread_key_delete.c (pthread_key_delete): Likewise. * nptl/pthread_mutex_consistent.c (pthread_mutex_consistent): Likewise. * nptl/pthread_mutex_destroy.c (__pthread_mutex_destroy): Likewise. * nptl/pthread_mutex_getprioceiling.c (pthread_mutex_getprioceiling): Likewise. * nptl/pthread_mutexattr_destroy.c (__pthread_mutexattr_destroy): Likewise. * nptl/pthread_mutexattr_getprotocol.c (pthread_mutexattr_getprotocol): Likewise. * nptl/pthread_mutexattr_getpshared.c (pthread_mutexattr_getpshared): Likewise. * nptl/pthread_mutexattr_getrobust.c (pthread_mutexattr_getrobust): Likewise. * nptl/pthread_mutexattr_gettype.c (pthread_mutexattr_gettype): Likewise. * nptl/pthread_mutexattr_init.c (__pthread_mutexattr_init): Likewise. * nptl/pthread_mutexattr_setprioceiling.c (pthread_mutexattr_setprioceiling): Likewise. * nptl/pthread_mutexattr_setprotocol.c (pthread_mutexattr_setprotocol): Likewise. * nptl/pthread_mutexattr_setpshared.c (pthread_mutexattr_setpshared): Likewise. * nptl/pthread_mutexattr_setrobust.c (pthread_mutexattr_setrobust): Likewise. * nptl/pthread_mutexattr_settype.c (__pthread_mutexattr_settype): Likewise. * nptl/pthread_rwlock_destroy.c (__pthread_rwlock_destroy): Likewise. * nptl/pthread_rwlockattr_destroy.c (pthread_rwlockattr_destroy): Likewise. * nptl/pthread_rwlockattr_getkind_np.c (pthread_rwlockattr_getkind_np): Likewise. * nptl/pthread_rwlockattr_getpshared.c (pthread_rwlockattr_getpshared): Likewise. * nptl/pthread_rwlockattr_init.c (pthread_rwlockattr_init): Likewise. * nptl/pthread_rwlockattr_setkind_np.c (pthread_rwlockattr_setkind_np): Likewise. * nptl/pthread_rwlockattr_setpshared.c (pthread_rwlockattr_setpshared): Likewise. * nptl/pthread_setcancelstate.c (__pthread_setcancelstate): Likewise. * nptl/pthread_setcanceltype.c (__pthread_setcanceltype): Likewise. * nptl/pthread_setconcurrency.c (pthread_setconcurrency): Likewise. * nptl/pthread_setschedprio.c (pthread_setschedprio): Likewise. * nptl/pthread_setspecific.c (__pthread_setspecific): Likewise. * nptl/pthread_spin_destroy.c (pthread_spin_destroy): Likewise. * nptl/pthread_tryjoin.c (pthread_tryjoin_np): Likewise. * nptl/sem_close.c (sem_close): Likewise. * nptl/sem_destroy.c (__new_sem_destroy): Likewise. * nptl/sem_init.c (__old_sem_init): Likewise. * nptl/sigaction.c (__sigaction): Likewise. * nptl/unregister-atfork.c (__unregister_atfork): Likewise. * posix/_exit.c (_exit): Likewise. * posix/alarm.c (alarm): Likewise. * posix/confstr.c (confstr): Likewise. * posix/fpathconf.c (__fpathconf): Likewise. * posix/getgroups.c (__getgroups): Likewise. * posix/getpgid.c (__getpgid): Likewise. * posix/group_member.c (__group_member): Likewise. * posix/pathconf.c (__pathconf): Likewise. * posix/sched_getaffinity.c (sched_getaffinity): Likewise. * posix/sched_setaffinity.c (sched_setaffinity): Likewise. * posix/setgid.c (__setgid): Likewise. * posix/setpgid.c (__setpgid): Likewise. * posix/setuid.c (__setuid): Likewise. * posix/sleep.c (__sleep): Likewise. * posix/sysconf.c (__sysconf): Likewise. * posix/times.c (__times): Likewise. * posix/uname.c (__uname): Likewise. * posix/waitid.c (__waitid): Likewise. * pwd/getpw.c (__getpw): Likewise. * resolv/base64.c (b64_pton): Likewise. * resolv/gai_sigqueue.c (__gai_sigqueue): Likewise. * resolv/gethnamaddr.c (Dprintf): Likewise. (gethostbyname): Likewise. (gethostbyname2): Likewise. (gethostbyaddr): Likewise. (_sethtent): Likewise. (_gethtbyname): Likewise. (_gethtbyname2): Likewise. (_gethtbyaddr): Likewise. (map_v4v6_address): Likewise. (map_v4v6_hostent): Likewise. (addrsort): Likewise. (ht_sethostent): Likewise. (ht_gethostbyname): Likewise. (ht_gethostbyaddr): Likewise. * resolv/inet_net_ntop.c (inet_net_ntop): Likewise. (inet_net_ntop_ipv4): Likewise. * resolv/inet_neta.c (inet_neta): Likewise. * resolv/inet_ntop.c (inet_ntop): Likewise. (inet_ntop4): Likewise. (inet_ntop6): Likewise. * resolv/inet_pton.c (__inet_pton): Likewise. (inet_pton4): Likewise. (inet_pton6): Likewise. * resolv/res_debug.c (loc_aton): Likewise. (loc_ntoa): Likewise. * resource/getpriority.c (__getpriority): Likewise. * resource/getrusage.c (__getrusage): Likewise. * resource/nice.c (nice): Likewise. * resource/setpriority.c (__setpriority): Likewise. * resource/setrlimit64.c (setrlimit64): Likewise. * resource/vlimit.c (vlimit): Likewise. * resource/vtimes.c (vtimes): Likewise. * rt/aio_error.c (aio_error): Likewise. * rt/aio_return.c (aio_return): Likewise. * rt/aio_sigqueue.c (__aio_sigqueue): Likewise. * signal/kill.c (__kill): Likewise. * signal/killpg.c (killpg): Likewise. * signal/raise.c (raise): Likewise. * signal/sigaction.c (__sigaction): Likewise. * signal/sigaddset.c (sigaddset): Likewise. * signal/sigaltstack.c (sigaltstack): Likewise. * signal/sigandset.c (sigandset): Likewise. * signal/sigblock.c (__sigblock): Likewise. * signal/sigdelset.c (sigdelset): Likewise. * signal/sigempty.c (sigemptyset): Likewise. * signal/sigfillset.c (sigfillset): Likewise. * signal/sighold.c (sighold): Likewise. * signal/sigignore.c (sigignore): Likewise. * signal/sigintr.c (siginterrupt): Likewise. * signal/sigisempty.c (sigisemptyset): Likewise. * signal/sigismem.c (sigismember): Likewise. * signal/signal.c (signal): Likewise. * signal/sigorset.c (sigorset): Likewise. * signal/sigpause.c (__sigpause): Likewise. * signal/sigpending.c (sigpending): Likewise. * signal/sigprocmask.c (__sigprocmask): Likewise. * signal/sigrelse.c (sigrelse): Likewise. * signal/sigreturn.c (__sigreturn): Likewise. * signal/sigset.c (sigset): Likewise. * signal/sigsetmask.c (__sigsetmask): Likewise. * signal/sigstack.c (sigstack): Likewise. * signal/sigsuspend.c (__sigsuspend): Likewise. * signal/sigvec.c (sigvec_wrapper_handler): Likewise. * signal/sysv_signal.c (__sysv_signal): Likewise. * socket/accept.c (accept): Likewise. * socket/accept4.c (__libc_accept4): Likewise. * socket/bind.c (__bind): Likewise. * socket/connect.c (__connect): Likewise. * socket/getpeername.c (getpeername): Likewise. * socket/getsockname.c (__getsockname): Likewise. * socket/getsockopt.c (getsockopt): Likewise. * socket/listen.c (__listen): Likewise. * socket/recv.c (__recv): Likewise. * socket/recvmsg.c (__recvmsg): Likewise. * socket/send.c (__send): Likewise. * socket/sendmsg.c (__sendmsg): Likewise. * socket/shutdown.c (shutdown): Likewise. * socket/sockatmark.c (sockatmark): Likewise. * socket/socket.c (__socket): Likewise. * stdio-common/ctermid.c (ctermid): Likewise. * stdio-common/cuserid.c (cuserid): Likewise. * stdio-common/printf-prs.c (parse_printf_format): Likewise. * stdio-common/remove.c (remove): Likewise. * stdio-common/rename.c (rename): Likewise. * stdio-common/renameat.c (renameat): Likewise. * stdio-common/tempname.c (__gen_tempname): Likewise. * stdio-common/xbug.c (InitBuffer): Likewise. (AppendToBuffer): Likewise. (ReadFile): Likewise. * stdlib/a64l.c (a64l): Likewise. * stdlib/drand48_r.c (drand48_r): Likewise. * stdlib/getcontext.c (getcontext): Likewise. * stdlib/getenv.c (getenv): Likewise. * stdlib/l64a.c (l64a): Likewise. * stdlib/llabs.c (llabs): Likewise. * stdlib/lldiv.c (lldiv): Likewise. * stdlib/lrand48_r.c (lrand48_r): Likewise. * stdlib/mrand48_r.c (mrand48_r): Likewise. * stdlib/putenv.c (putenv): Likewise. * stdlib/random.c (__srandom): Likewise. (__initstate): Likewise. (__setstate): Likewise. * stdlib/random_r.c (__srandom_r): Likewise. (__setstate_r): Likewise. (__random_r): Likewise. * stdlib/secure-getenv.c (__libc_secure_getenv): Likewise. * stdlib/setcontext.c (setcontext): Likewise. * stdlib/setenv.c (setenv): Likewise. (unsetenv): Likewise. * stdlib/srand48.c (srand48): Likewise. * stdlib/srand48_r.c (__srand48_r): Likewise. * stdlib/swapcontext.c (swapcontext): Likewise. * stdlib/system.c (__libc_system): Likewise. * stdlib/tst-strtod.c (expand): Likewise. * stdlib/tst-strtol.c (expand): Likewise. * stdlib/tst-strtoll.c (expand): Likewise. * streams/fattach.c (fattach): Likewise. * streams/fdetach.c (fdetach): Likewise. * streams/getmsg.c (getmsg): Likewise. * streams/isastream.c (isastream): Likewise. * string/ffs.c (__ffs): Likewise. * string/ffsll.c (ffsll): Likewise. * string/memcmp.c (memcmp_common_alignment): Likewise. (memcmp_not_common_alignment): Likewise. (MEMCMP): Likewise. * string/memcpy.c (memcpy): Likewise. * string/memmove.c (MEMMOVE): Likewise. * string/memset.c (memset): Likewise. * string/rawmemchr.c (RAWMEMCHR): Likewise. * string/strchrnul.c (STRCHRNUL): Likewise. * string/strerror.c (strerror): Likewise. * string/strndup.c (__strndup): Likewise. * string/strverscmp.c (__strverscmp): Likewise. * sunrpc/clnt_raw.c (clntraw_freeres): Likewise. * sunrpc/clnt_tcp.c (clnttcp_geterr): Likewise. (clnttcp_freeres): Likewise. * sunrpc/clnt_unix.c (clntunix_freeres): Likewise. * sunrpc/pmap_prot.c (xdr_pmap): Likewise. * sunrpc/pmap_prot2.c (xdr_pmaplist): Likewise. * sunrpc/pmap_rmt.c (xdr_rmtcallres): Likewise. * sunrpc/rpc_prot.c (xdr_replymsg): Likewise. (xdr_callhdr): Likewise. * sunrpc/rpcinfo.c (udpping): Likewise. (tcpping): Likewise. (pstatus): Likewise. (pmapdump): Likewise. (brdcst): Likewise. (deletereg): Likewise. (getprognum): Likewise. (getvers): Likewise. (get_inet_address): Likewise. * sunrpc/svc_raw.c (svcraw_recv): Likewise. * sunrpc/svc_udp.c (svcudp_create): Likewise. (svcudp_stat): Likewise. (svcudp_recv): Likewise. (svcudp_reply): Likewise. (svcudp_getargs): Likewise. (svcudp_freeargs): Likewise. (svcudp_destroy): Likewise. * sunrpc/xdr.c (xdr_bytes): Likewise. (xdr_netobj): Likewise. (xdr_string): Likewise. (xdr_wrapstring): Likewise. * sunrpc/xdr_float.c (xdr_float): Likewise. (xdr_double): Likewise. * sunrpc/xdr_mem.c (xdrmem_setpos): Likewise. * sunrpc/xdr_ref.c (xdr_pointer): Likewise. * sysvipc/ftok.c (ftok): Likewise. * sysvipc/msgctl.c (msgctl): Likewise. * sysvipc/msgget.c (msgget): Likewise. * sysvipc/msgrcv.c (msgrcv): Likewise. * sysvipc/msgsnd.c (msgsnd): Likewise. * sysvipc/semget.c (semget): Likewise. * sysvipc/semop.c (semop): Likewise. * sysvipc/shmat.c (shmat): Likewise. * sysvipc/shmctl.c (shmctl): Likewise. * sysvipc/shmdt.c (shmdt): Likewise. * sysvipc/shmget.c (shmget): Likewise. * termios/cfmakeraw.c (cfmakeraw): Likewise. * termios/speed.c (cfgetospeed): Likewise. (cfgetispeed): Likewise. (cfsetospeed): Likewise. (cfsetispeed): Likewise. * termios/tcflow.c (tcflow): Likewise. * termios/tcflush.c (tcflush): Likewise. * termios/tcgetattr.c (__tcgetattr): Likewise. * termios/tcgetpgrp.c (tcgetpgrp): Likewise. * termios/tcgetsid.c (tcgetsid): Likewise. * termios/tcsendbrk.c (tcsendbreak): Likewise. * termios/tcsetpgrp.c (tcsetpgrp): Likewise. * time/adjtime.c (__adjtime): Likewise. * time/dysize.c (dysize): Likewise. * time/ftime.c (ftime): Likewise. * time/getitimer.c (__getitimer): Likewise. * time/gettimeofday.c (__gettimeofday): Likewise. * time/gmtime.c (__gmtime_r): Likewise. (gmtime): Likewise. * time/localtime.c (__localtime_r): Likewise. (localtime): Likewise. * time/offtime.c (__offtime): Likewise. * time/settimeofday.c (__settimeofday): Likewise. * time/stime.c (stime): Likewise. * time/strftime_l.c (tm_diff): Likewise. (iso_week_days): Likewise. * time/strptime.c (strptime): Likewise. * time/time.c (time): Likewise. * time/timespec_get.c (timespec_get): Likewise. * time/tzset.c (tzset_internal): Likewise. (compute_change): Likewise. (__tz_compute): Likewise. * wcsmbs/btowc.c (__btowc): Likewise. * wcsmbs/mbrlen.c (__mbrlen): Likewise. * wcsmbs/mbsinit.c (__mbsinit): Likewise. * wcsmbs/mbsrtowcs.c (__mbsrtowcs): Likewise. * wcsmbs/wcpcpy.c (__wcpcpy): Likewise. * wcsmbs/wcpncpy.c (__wcpncpy): Likewise. * wcsmbs/wcscat.c (__wcscat): Likewise. * wcsmbs/wcschrnul.c (__wcschrnul): Likewise. * wcsmbs/wcscmp.c (WCSCMP): Likewise. * wcsmbs/wcscpy.c (WCSCPY): Likewise. * wcsmbs/wcscspn.c (wcscspn): Likewise. * wcsmbs/wcsdup.c (wcsdup): Likewise. * wcsmbs/wcslen.c (__wcslen): Likewise. * wcsmbs/wcsncat.c (WCSNCAT): Likewise. * wcsmbs/wcsncmp.c (WCSNCMP): Likewise. * wcsmbs/wcsncpy.c (__wcsncpy): Likewise. * wcsmbs/wcsnlen.c (__wcsnlen): Likewise. * wcsmbs/wcspbrk.c (wcspbrk): Likewise. * wcsmbs/wcsrchr.c (WCSRCHR): Likewise. * wcsmbs/wcsspn.c (wcsspn): Likewise. * wcsmbs/wcsstr.c (wcsstr): Likewise. * wcsmbs/wcstok.c (wcstok): Likewise. * wcsmbs/wctob.c (wctob): Likewise. * wcsmbs/wmemchr.c (__wmemchr): Likewise. * wcsmbs/wmemcmp.c (WMEMCMP): Likewise. * wcsmbs/wmemcpy.c (__wmemcpy): Likewise. * wcsmbs/wmemmove.c (__wmemmove): Likewise. * wcsmbs/wmempcpy.c (__wmempcpy): Likewise. * wcsmbs/wmemset.c (__wmemset): Likewise. * wctype/wcfuncs.c (__towlower): Likewise. (__towupper): Likewise.
853 lines
21 KiB
C
853 lines
21 KiB
C
/*
|
|
* Copyright (C) 1998 WIDE Project.
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. Neither the name of the project nor the names of its contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*/
|
|
/*
|
|
* Copyright (c) 1983, 1993, 1994
|
|
* The Regents of the University of California. All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*/
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
|
static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94";
|
|
#endif /* LIBC_SCCS and not lint */
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/poll.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
|
|
#include <alloca.h>
|
|
#include <signal.h>
|
|
#include <fcntl.h>
|
|
#include <netdb.h>
|
|
#include <unistd.h>
|
|
#include <pwd.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdio_ext.h>
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
#include <libintl.h>
|
|
#include <stdlib.h>
|
|
#include <wchar.h>
|
|
#include <sys/uio.h>
|
|
|
|
|
|
int __ivaliduser (FILE *, u_int32_t, const char *, const char *);
|
|
static int __validuser2_sa (FILE *, struct sockaddr *, size_t,
|
|
const char *, const char *, const char *);
|
|
static int ruserok2_sa (struct sockaddr *ra, size_t ralen,
|
|
int superuser, const char *ruser,
|
|
const char *luser, const char *rhost);
|
|
static int ruserok_sa (struct sockaddr *ra, size_t ralen,
|
|
int superuser, const char *ruser,
|
|
const char *luser);
|
|
int iruserok_af (const void *raddr, int superuser, const char *ruser,
|
|
const char *luser, sa_family_t af);
|
|
int iruserok (u_int32_t raddr, int superuser, const char *ruser,
|
|
const char *luser);
|
|
|
|
libc_hidden_proto (iruserok_af)
|
|
|
|
libc_freeres_ptr(static char *ahostbuf);
|
|
|
|
int
|
|
rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
|
|
char **ahost;
|
|
u_short rport;
|
|
const char *locuser, *remuser, *cmd;
|
|
int *fd2p;
|
|
sa_family_t af;
|
|
{
|
|
char paddr[INET6_ADDRSTRLEN];
|
|
struct addrinfo hints, *res, *ai;
|
|
union
|
|
{
|
|
struct sockaddr sa;
|
|
struct sockaddr_storage ss;
|
|
struct sockaddr_in sin;
|
|
struct sockaddr_in6 sin6;
|
|
} from;
|
|
struct pollfd pfd[2];
|
|
int32_t oldmask;
|
|
pid_t pid;
|
|
int s, lport, timo, error;
|
|
char c;
|
|
int refused;
|
|
char num[8];
|
|
ssize_t n;
|
|
|
|
if (af != AF_INET && af != AF_INET6 && af != AF_UNSPEC)
|
|
{
|
|
__set_errno (EAFNOSUPPORT);
|
|
return -1;
|
|
}
|
|
|
|
pid = __getpid();
|
|
|
|
memset(&hints, '\0', sizeof(hints));
|
|
hints.ai_flags = AI_CANONNAME;
|
|
hints.ai_family = af;
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
(void)__snprintf(num, sizeof(num), "%d", ntohs(rport));
|
|
error = getaddrinfo(*ahost, num, &hints, &res);
|
|
if (error) {
|
|
if (error == EAI_NONAME && *ahost != NULL)
|
|
__fxprintf(NULL, "%s: Unknown host\n", *ahost);
|
|
else
|
|
__fxprintf(NULL, "rcmd: getaddrinfo: %s\n",
|
|
gai_strerror(error));
|
|
|
|
return -1;
|
|
}
|
|
|
|
pfd[0].events = POLLIN;
|
|
pfd[1].events = POLLIN;
|
|
|
|
if (res->ai_canonname){
|
|
free (ahostbuf);
|
|
ahostbuf = strdup (res->ai_canonname);
|
|
if (ahostbuf == NULL) {
|
|
__fxprintf(NULL, "%s",
|
|
_("rcmd: Cannot allocate memory\n"));
|
|
return -1;
|
|
}
|
|
*ahost = ahostbuf;
|
|
} else
|
|
*ahost = NULL;
|
|
ai = res;
|
|
refused = 0;
|
|
oldmask = __sigblock(sigmask(SIGURG));
|
|
for (timo = 1, lport = IPPORT_RESERVED - 1;;) {
|
|
char errbuf[200];
|
|
|
|
s = rresvport_af(&lport, ai->ai_family);
|
|
if (s < 0) {
|
|
if (errno == EAGAIN)
|
|
__fxprintf(NULL, "%s", _("\
|
|
rcmd: socket: All ports in use\n"));
|
|
else
|
|
__fxprintf(NULL, "rcmd: socket: %m\n");
|
|
|
|
__sigsetmask(oldmask);
|
|
freeaddrinfo(res);
|
|
return -1;
|
|
}
|
|
__fcntl(s, F_SETOWN, pid);
|
|
if (__connect(s, ai->ai_addr, ai->ai_addrlen) >= 0)
|
|
break;
|
|
(void)__close(s);
|
|
if (errno == EADDRINUSE) {
|
|
lport--;
|
|
continue;
|
|
}
|
|
if (errno == ECONNREFUSED)
|
|
refused = 1;
|
|
if (ai->ai_next != NULL) {
|
|
int oerrno = errno;
|
|
char *buf = NULL;
|
|
|
|
getnameinfo(ai->ai_addr, ai->ai_addrlen,
|
|
paddr, sizeof(paddr),
|
|
NULL, 0,
|
|
NI_NUMERICHOST);
|
|
|
|
if (__asprintf (&buf, _("connect to address %s: "),
|
|
paddr) >= 0)
|
|
{
|
|
__fxprintf(NULL, "%s", buf);
|
|
free (buf);
|
|
}
|
|
__set_errno (oerrno);
|
|
perror(0);
|
|
ai = ai->ai_next;
|
|
getnameinfo(ai->ai_addr, ai->ai_addrlen,
|
|
paddr, sizeof(paddr),
|
|
NULL, 0,
|
|
NI_NUMERICHOST);
|
|
if (__asprintf (&buf, _("Trying %s...\n"), paddr) >= 0)
|
|
{
|
|
__fxprintf (NULL, "%s", buf);
|
|
free (buf);
|
|
}
|
|
continue;
|
|
}
|
|
if (refused && timo <= 16) {
|
|
(void)__sleep(timo);
|
|
timo *= 2;
|
|
ai = res;
|
|
refused = 0;
|
|
continue;
|
|
}
|
|
freeaddrinfo(res);
|
|
(void)__fxprintf(NULL, "%s: %s\n", *ahost,
|
|
__strerror_r(errno, errbuf, sizeof (errbuf)));
|
|
__sigsetmask(oldmask);
|
|
return -1;
|
|
}
|
|
lport--;
|
|
if (fd2p == 0) {
|
|
__write(s, "", 1);
|
|
lport = 0;
|
|
} else {
|
|
char num[8];
|
|
int s2 = rresvport_af(&lport, ai->ai_family), s3;
|
|
socklen_t len = ai->ai_addrlen;
|
|
|
|
if (s2 < 0)
|
|
goto bad;
|
|
__listen(s2, 1);
|
|
(void)__snprintf(num, sizeof(num), "%d", lport);
|
|
if (__write(s, num, strlen(num)+1) != (ssize_t)strlen(num)+1) {
|
|
char *buf = NULL;
|
|
|
|
if (__asprintf (&buf, _("\
|
|
rcmd: write (setting up stderr): %m\n")) >= 0)
|
|
{
|
|
__fxprintf(NULL, "%s", buf);
|
|
free (buf);
|
|
}
|
|
(void)__close(s2);
|
|
goto bad;
|
|
}
|
|
pfd[0].fd = s;
|
|
pfd[1].fd = s2;
|
|
__set_errno (0);
|
|
if (__poll (pfd, 2, -1) < 1 || (pfd[1].revents & POLLIN) == 0){
|
|
char *buf = NULL;
|
|
|
|
if ((errno != 0
|
|
&& __asprintf(&buf, _("\
|
|
rcmd: poll (setting up stderr): %m\n")) >= 0)
|
|
|| (errno == 0
|
|
&& __asprintf(&buf, _("\
|
|
poll: protocol failure in circuit setup\n")) >= 0))
|
|
{
|
|
__fxprintf (NULL, "%s", buf);
|
|
free (buf);
|
|
}
|
|
(void)__close(s2);
|
|
goto bad;
|
|
}
|
|
s3 = TEMP_FAILURE_RETRY (accept(s2, &from.sa, &len));
|
|
switch (from.sa.sa_family) {
|
|
case AF_INET:
|
|
rport = ntohs(from.sin.sin_port);
|
|
break;
|
|
case AF_INET6:
|
|
rport = ntohs(from.sin6.sin6_port);
|
|
break;
|
|
default:
|
|
rport = 0;
|
|
break;
|
|
}
|
|
(void)__close(s2);
|
|
if (s3 < 0) {
|
|
(void)__fxprintf(NULL, "rcmd: accept: %m\n");
|
|
lport = 0;
|
|
goto bad;
|
|
}
|
|
*fd2p = s3;
|
|
|
|
if (rport >= IPPORT_RESERVED || rport < IPPORT_RESERVED / 2){
|
|
char *buf = NULL;
|
|
|
|
if (__asprintf(&buf, _("\
|
|
socket: protocol failure in circuit setup\n")) >= 0)
|
|
{
|
|
__fxprintf (NULL, "%s", buf);
|
|
free (buf);
|
|
}
|
|
goto bad2;
|
|
}
|
|
}
|
|
struct iovec iov[3] =
|
|
{
|
|
[0] = { .iov_base = (void *) locuser,
|
|
.iov_len = strlen (locuser) + 1 },
|
|
[1] = { .iov_base = (void *) remuser,
|
|
.iov_len = strlen (remuser) + 1 },
|
|
[2] = { .iov_base = (void *) cmd,
|
|
.iov_len = strlen (cmd) + 1 }
|
|
};
|
|
(void) TEMP_FAILURE_RETRY (__writev (s, iov, 3));
|
|
n = TEMP_FAILURE_RETRY (__read(s, &c, 1));
|
|
if (n != 1) {
|
|
char *buf = NULL;
|
|
|
|
if ((n == 0
|
|
&& __asprintf(&buf, _("rcmd: %s: short read"),
|
|
*ahost) >= 0)
|
|
|| (n != 0
|
|
&& __asprintf(&buf, "rcmd: %s: %m\n", *ahost) >= 0))
|
|
{
|
|
__fxprintf (NULL, "%s", buf);
|
|
free (buf);
|
|
}
|
|
goto bad2;
|
|
}
|
|
if (c != 0) {
|
|
while (__read(s, &c, 1) == 1) {
|
|
(void)__write(STDERR_FILENO, &c, 1);
|
|
if (c == '\n')
|
|
break;
|
|
}
|
|
goto bad2;
|
|
}
|
|
__sigsetmask(oldmask);
|
|
freeaddrinfo(res);
|
|
return s;
|
|
bad2:
|
|
if (lport)
|
|
(void)__close(*fd2p);
|
|
bad:
|
|
(void)__close(s);
|
|
__sigsetmask(oldmask);
|
|
freeaddrinfo(res);
|
|
return -1;
|
|
}
|
|
libc_hidden_def (rcmd_af)
|
|
|
|
int
|
|
rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
|
|
char **ahost;
|
|
u_short rport;
|
|
const char *locuser, *remuser, *cmd;
|
|
int *fd2p;
|
|
{
|
|
return rcmd_af (ahost, rport, locuser, remuser, cmd, fd2p, AF_INET);
|
|
}
|
|
|
|
int
|
|
rresvport_af (int *alport, sa_family_t family)
|
|
{
|
|
union {
|
|
struct sockaddr generic;
|
|
struct sockaddr_in in;
|
|
struct sockaddr_in6 in6;
|
|
} ss;
|
|
int s;
|
|
size_t len;
|
|
uint16_t *sport;
|
|
|
|
switch(family){
|
|
case AF_INET:
|
|
len = sizeof(struct sockaddr_in);
|
|
sport = &ss.in.sin_port;
|
|
break;
|
|
case AF_INET6:
|
|
len = sizeof(struct sockaddr_in6);
|
|
sport = &ss.in6.sin6_port;
|
|
break;
|
|
default:
|
|
__set_errno (EAFNOSUPPORT);
|
|
return -1;
|
|
}
|
|
s = __socket(family, SOCK_STREAM, 0);
|
|
if (s < 0)
|
|
return -1;
|
|
|
|
memset (&ss, '\0', sizeof(ss));
|
|
#ifdef SALEN
|
|
ss.generic.__ss_len = len;
|
|
#endif
|
|
ss.generic.sa_family = family;
|
|
|
|
/* Ignore invalid values. */
|
|
if (*alport < IPPORT_RESERVED / 2)
|
|
*alport = IPPORT_RESERVED / 2;
|
|
else if (*alport >= IPPORT_RESERVED)
|
|
*alport = IPPORT_RESERVED - 1;
|
|
|
|
int start = *alport;
|
|
do {
|
|
*sport = htons((uint16_t) *alport);
|
|
if (__bind(s, &ss.generic, len) >= 0)
|
|
return s;
|
|
if (errno != EADDRINUSE) {
|
|
(void)__close(s);
|
|
return -1;
|
|
}
|
|
if ((*alport)-- == IPPORT_RESERVED/2)
|
|
*alport = IPPORT_RESERVED - 1;
|
|
} while (*alport != start);
|
|
(void)__close(s);
|
|
__set_errno (EAGAIN);
|
|
return -1;
|
|
}
|
|
libc_hidden_def (rresvport_af)
|
|
|
|
int
|
|
rresvport (int *alport)
|
|
{
|
|
return rresvport_af(alport, AF_INET);
|
|
}
|
|
|
|
int __check_rhosts_file = 1;
|
|
char *__rcmd_errstr;
|
|
|
|
int
|
|
ruserok_af(rhost, superuser, ruser, luser, af)
|
|
const char *rhost, *ruser, *luser;
|
|
int superuser;
|
|
sa_family_t af;
|
|
{
|
|
struct addrinfo hints, *res, *res0;
|
|
int gai;
|
|
int ret;
|
|
|
|
memset (&hints, '\0', sizeof(hints));
|
|
hints.ai_family = af;
|
|
gai = getaddrinfo(rhost, NULL, &hints, &res0);
|
|
if (gai)
|
|
return -1;
|
|
ret = -1;
|
|
for (res=res0; res; res=res->ai_next)
|
|
if (ruserok2_sa(res->ai_addr, res->ai_addrlen,
|
|
superuser, ruser, luser, rhost) == 0){
|
|
ret = 0;
|
|
break;
|
|
}
|
|
freeaddrinfo(res0);
|
|
return (ret);
|
|
}
|
|
libc_hidden_def (ruserok_af)
|
|
|
|
int
|
|
ruserok(rhost, superuser, ruser, luser)
|
|
const char *rhost, *ruser, *luser;
|
|
int superuser;
|
|
{
|
|
return ruserok_af(rhost, superuser, ruser, luser, AF_INET);
|
|
}
|
|
|
|
/* Extremely paranoid file open function. */
|
|
static FILE *
|
|
iruserfopen (const char *file, uid_t okuser)
|
|
{
|
|
struct stat64 st;
|
|
char *cp = NULL;
|
|
FILE *res = NULL;
|
|
|
|
/* If not a regular file, if owned by someone other than user or
|
|
root, if writeable by anyone but the owner, or if hardlinked
|
|
anywhere, quit. */
|
|
if (__lxstat64 (_STAT_VER, file, &st))
|
|
cp = _("lstat failed");
|
|
else if (!S_ISREG (st.st_mode))
|
|
cp = _("not regular file");
|
|
else
|
|
{
|
|
res = fopen (file, "rce");
|
|
if (!res)
|
|
cp = _("cannot open");
|
|
else if (__fxstat64 (_STAT_VER, fileno (res), &st) < 0)
|
|
cp = _("fstat failed");
|
|
else if (st.st_uid && st.st_uid != okuser)
|
|
cp = _("bad owner");
|
|
else if (st.st_mode & (S_IWGRP|S_IWOTH))
|
|
cp = _("writeable by other than owner");
|
|
else if (st.st_nlink > 1)
|
|
cp = _("hard linked somewhere");
|
|
}
|
|
|
|
/* If there were any problems, quit. */
|
|
if (cp != NULL)
|
|
{
|
|
__rcmd_errstr = cp;
|
|
if (res)
|
|
fclose (res);
|
|
return NULL;
|
|
}
|
|
|
|
/* No threads use this stream. */
|
|
__fsetlocking (res, FSETLOCKING_BYCALLER);
|
|
|
|
return res;
|
|
}
|
|
|
|
/*
|
|
* New .rhosts strategy: We are passed an ip address. We spin through
|
|
* hosts.equiv and .rhosts looking for a match. When the .rhosts only
|
|
* has ip addresses, we don't have to trust a nameserver. When it
|
|
* contains hostnames, we spin through the list of addresses the nameserver
|
|
* gives us and look for a match.
|
|
*
|
|
* Returns 0 if ok, -1 if not ok.
|
|
*/
|
|
static int
|
|
ruserok2_sa (ra, ralen, superuser, ruser, luser, rhost)
|
|
struct sockaddr *ra;
|
|
size_t ralen;
|
|
int superuser;
|
|
const char *ruser, *luser, *rhost;
|
|
{
|
|
FILE *hostf = NULL;
|
|
int isbad = -1;
|
|
|
|
if (!superuser)
|
|
hostf = iruserfopen (_PATH_HEQUIV, 0);
|
|
|
|
if (hostf)
|
|
{
|
|
isbad = __validuser2_sa (hostf, ra, ralen, luser, ruser, rhost);
|
|
fclose (hostf);
|
|
|
|
if (!isbad)
|
|
return 0;
|
|
}
|
|
|
|
if (__check_rhosts_file || superuser)
|
|
{
|
|
char *pbuf;
|
|
struct passwd pwdbuf, *pwd;
|
|
size_t dirlen;
|
|
size_t buflen = __sysconf (_SC_GETPW_R_SIZE_MAX);
|
|
char *buffer = __alloca (buflen);
|
|
uid_t uid;
|
|
|
|
if (__getpwnam_r (luser, &pwdbuf, buffer, buflen, &pwd) != 0
|
|
|| pwd == NULL)
|
|
return -1;
|
|
|
|
dirlen = strlen (pwd->pw_dir);
|
|
pbuf = alloca (dirlen + sizeof "/.rhosts");
|
|
__mempcpy (__mempcpy (pbuf, pwd->pw_dir, dirlen),
|
|
"/.rhosts", sizeof "/.rhosts");
|
|
|
|
/* Change effective uid while reading .rhosts. If root and
|
|
reading an NFS mounted file system, can't read files that
|
|
are protected read/write owner only. */
|
|
uid = __geteuid ();
|
|
seteuid (pwd->pw_uid);
|
|
hostf = iruserfopen (pbuf, pwd->pw_uid);
|
|
|
|
if (hostf != NULL)
|
|
{
|
|
isbad = __validuser2_sa (hostf, ra, ralen, luser, ruser, rhost);
|
|
fclose (hostf);
|
|
}
|
|
|
|
seteuid (uid);
|
|
return isbad;
|
|
}
|
|
return -1;
|
|
}
|
|
/*
|
|
* ruserok_sa() is now discussed on ipng, so
|
|
* currently disabled for external use
|
|
*/
|
|
static int ruserok_sa(ra, ralen, superuser, ruser, luser)
|
|
struct sockaddr *ra;
|
|
size_t ralen;
|
|
int superuser;
|
|
const char *ruser, *luser;
|
|
{
|
|
return ruserok2_sa(ra, ralen, superuser, ruser, luser, "-");
|
|
}
|
|
|
|
/* This is the exported version. */
|
|
int
|
|
iruserok_af (raddr, superuser, ruser, luser, af)
|
|
const void *raddr;
|
|
int superuser;
|
|
const char *ruser, *luser;
|
|
sa_family_t af;
|
|
{
|
|
union {
|
|
struct sockaddr generic;
|
|
struct sockaddr_in in;
|
|
struct sockaddr_in6 in6;
|
|
} ra;
|
|
size_t ralen;
|
|
|
|
memset (&ra, '\0', sizeof(ra));
|
|
switch (af){
|
|
case AF_INET:
|
|
ra.in.sin_family = AF_INET;
|
|
memcpy (&ra.in.sin_addr, raddr, sizeof(struct in_addr));
|
|
ralen = sizeof(struct sockaddr_in);
|
|
break;
|
|
case AF_INET6:
|
|
ra.in6.sin6_family = AF_INET6;
|
|
memcpy (&ra.in6.sin6_addr, raddr, sizeof(struct in6_addr));
|
|
ralen = sizeof(struct sockaddr_in6);
|
|
break;
|
|
default:
|
|
return 0;
|
|
}
|
|
return ruserok_sa (&ra.generic, ralen, superuser, ruser, luser);
|
|
}
|
|
libc_hidden_def (iruserok_af)
|
|
|
|
int
|
|
iruserok (raddr, superuser, ruser, luser)
|
|
u_int32_t raddr;
|
|
int superuser;
|
|
const char *ruser, *luser;
|
|
{
|
|
return iruserok_af (&raddr, superuser, ruser, luser, AF_INET);
|
|
}
|
|
|
|
/*
|
|
* XXX
|
|
* Don't make static, used by lpd(8).
|
|
*
|
|
* This function is not used anymore. It is only present because lpd(8)
|
|
* calls it (!?!). We simply call __invaliduser2() with an illegal rhost
|
|
* argument. This means that netgroups won't work in .rhost/hosts.equiv
|
|
* files. If you want lpd to work with netgroups, fix lpd to use ruserok()
|
|
* or PAM.
|
|
* Returns 0 if ok, -1 if not ok.
|
|
*/
|
|
int
|
|
__ivaliduser(hostf, raddr, luser, ruser)
|
|
FILE *hostf;
|
|
u_int32_t raddr;
|
|
const char *luser, *ruser;
|
|
{
|
|
struct sockaddr_in ra;
|
|
memset(&ra, '\0', sizeof(ra));
|
|
ra.sin_family = AF_INET;
|
|
ra.sin_addr.s_addr = raddr;
|
|
return __validuser2_sa(hostf, (struct sockaddr *)&ra, sizeof(ra),
|
|
luser, ruser, "-");
|
|
}
|
|
|
|
|
|
/* Returns 1 on positive match, 0 on no match, -1 on negative match. */
|
|
static int
|
|
internal_function
|
|
__checkhost_sa (struct sockaddr *ra, size_t ralen, char *lhost,
|
|
const char *rhost)
|
|
{
|
|
struct addrinfo hints, *res0, *res;
|
|
char raddr[INET6_ADDRSTRLEN];
|
|
int match;
|
|
int negate=1; /* Multiply return with this to get -1 instead of 1 */
|
|
|
|
/* Check nis netgroup. */
|
|
if (strncmp ("+@", lhost, 2) == 0)
|
|
return innetgr (&lhost[2], rhost, NULL, NULL);
|
|
|
|
if (strncmp ("-@", lhost, 2) == 0)
|
|
return -innetgr (&lhost[2], rhost, NULL, NULL);
|
|
|
|
/* -host */
|
|
if (strncmp ("-", lhost,1) == 0) {
|
|
negate = -1;
|
|
lhost++;
|
|
} else if (strcmp ("+",lhost) == 0) {
|
|
return 1; /* asking for trouble, but ok.. */
|
|
}
|
|
|
|
/* Try for raw ip address first. */
|
|
/* XXX */
|
|
if (getnameinfo(ra, ralen,
|
|
raddr, sizeof(raddr), NULL, 0,
|
|
NI_NUMERICHOST) == 0
|
|
&& strcmp(raddr, lhost) == 0)
|
|
return negate;
|
|
|
|
/* Better be a hostname. */
|
|
match = 0;
|
|
memset(&hints, '\0', sizeof(hints));
|
|
hints.ai_family = ra->sa_family;
|
|
if (getaddrinfo(lhost, NULL, &hints, &res0) == 0){
|
|
/* Spin through ip addresses. */
|
|
for (res = res0; res; res = res->ai_next)
|
|
{
|
|
if (res->ai_family == ra->sa_family
|
|
&& !memcmp(res->ai_addr, ra, res->ai_addrlen))
|
|
{
|
|
match = 1;
|
|
break;
|
|
}
|
|
}
|
|
freeaddrinfo (res0);
|
|
}
|
|
return negate * match;
|
|
}
|
|
|
|
/* Returns 1 on positive match, 0 on no match, -1 on negative match. */
|
|
static int
|
|
internal_function
|
|
__icheckuser (const char *luser, const char *ruser)
|
|
{
|
|
/*
|
|
luser is user entry from .rhosts/hosts.equiv file
|
|
ruser is user id on remote host
|
|
*/
|
|
|
|
/* [-+]@netgroup */
|
|
if (strncmp ("+@", luser, 2) == 0)
|
|
return innetgr (&luser[2], NULL, ruser, NULL);
|
|
|
|
if (strncmp ("-@", luser,2) == 0)
|
|
return -innetgr (&luser[2], NULL, ruser, NULL);
|
|
|
|
/* -user */
|
|
if (strncmp ("-", luser, 1) == 0)
|
|
return -(strcmp (&luser[1], ruser) == 0);
|
|
|
|
/* + */
|
|
if (strcmp ("+", luser) == 0)
|
|
return 1;
|
|
|
|
/* simple string match */
|
|
return strcmp (ruser, luser) == 0;
|
|
}
|
|
|
|
/*
|
|
* Returns 1 for blank lines (or only comment lines) and 0 otherwise
|
|
*/
|
|
static int
|
|
__isempty (char *p)
|
|
{
|
|
while (*p && isspace (*p)) {
|
|
++p;
|
|
}
|
|
|
|
return (*p == '\0' || *p == '#') ? 1 : 0 ;
|
|
}
|
|
|
|
/*
|
|
* Returns 0 if positive match, -1 if _not_ ok.
|
|
*/
|
|
static int
|
|
__validuser2_sa(hostf, ra, ralen, luser, ruser, rhost)
|
|
FILE *hostf;
|
|
struct sockaddr *ra;
|
|
size_t ralen;
|
|
const char *luser, *ruser, *rhost;
|
|
{
|
|
const char *user;
|
|
char *p;
|
|
int hcheck, ucheck;
|
|
char *buf = NULL;
|
|
size_t bufsize = 0;
|
|
int retval = -1;
|
|
|
|
while (__getline (&buf, &bufsize, hostf) > 0) {
|
|
buf[bufsize - 1] = '\0'; /* Make sure it's terminated. */
|
|
p = buf;
|
|
|
|
/* Skip empty or comment lines */
|
|
if (__isempty (p)) {
|
|
continue;
|
|
}
|
|
|
|
for (;*p && !isspace(*p); ++p) {
|
|
*p = _tolower (*p);
|
|
}
|
|
|
|
/* Next we want to find the permitted name for the remote user. */
|
|
if (*p == ' ' || *p == '\t') {
|
|
/* <nul> terminate hostname and skip spaces */
|
|
for (*p++='\0'; *p && isspace (*p); ++p);
|
|
|
|
user = p; /* this is the user's name */
|
|
while (*p && !isspace (*p))
|
|
++p; /* find end of user's name */
|
|
} else
|
|
user = p;
|
|
|
|
*p = '\0'; /* <nul> terminate username (+host?) */
|
|
|
|
/* buf -> host(?) ; user -> username(?) */
|
|
if (*buf == '\0')
|
|
break;
|
|
if (*user == '\0')
|
|
user = luser;
|
|
|
|
/* First check the user part. In a naive implementation we
|
|
would check the host part first, then the user. However,
|
|
if we check the user first and reject the entry we will
|
|
have saved doing any host lookups to normalize the comparison
|
|
and that likely saves several DNS queries. Therefore we
|
|
check the user first. */
|
|
ucheck = __icheckuser (user, ruser);
|
|
|
|
/* Either we found the user, or we didn't and this is a
|
|
negative host check. We must do the negative host lookup
|
|
in order to preserve the semantics of stopping on this line
|
|
before processing others. */
|
|
if (ucheck != 0 || *buf == '-') {
|
|
|
|
/* Next check host part. */
|
|
hcheck = __checkhost_sa (ra, ralen, buf, rhost);
|
|
|
|
/* Negative '-host user(?)' match? */
|
|
if (hcheck < 0)
|
|
break;
|
|
|
|
/* Positive 'host user' match? */
|
|
if (hcheck > 0 && ucheck > 0) {
|
|
retval = 0;
|
|
break;
|
|
}
|
|
|
|
/* Negative 'host -user' match? */
|
|
if (hcheck > 0 && ucheck < 0)
|
|
break;
|
|
|
|
/* Neither, go on looking for match. */
|
|
}
|
|
}
|
|
|
|
free (buf);
|
|
|
|
return retval;
|
|
}
|