From: Tim Clem tclem@codeweavers.com
--- dlls/nsiproxy.sys/tcp.c | 180 ------------------------------- dlls/nsiproxy.sys/unix_private.h | 9 -- 2 files changed, 189 deletions(-)
diff --git a/dlls/nsiproxy.sys/tcp.c b/dlls/nsiproxy.sys/tcp.c index 96d517d1539..7a3004b1a97 100644 --- a/dlls/nsiproxy.sys/tcp.c +++ b/dlls/nsiproxy.sys/tcp.c @@ -63,14 +63,6 @@ #include <ifaddrs.h> #endif
-#ifdef HAVE_LIBPROCSTAT_H -#include <libprocstat.h> -#endif - -#ifdef HAVE_LIBPROC_H -#include <libproc.h> -#endif - #include "ntstatus.h" #define WIN32_NO_STATUS #include "windef.h" @@ -302,178 +294,6 @@ UINT find_ipv6_addr_scope( const IN6_ADDR *addr, const struct ipv6_addr_scope *t return -1; }
-struct pid_map *get_pid_map( unsigned int *num_entries ) -{ - struct pid_map *map; - unsigned int i = 0, buffer_len = 4096, process_count, pos = 0; - NTSTATUS ret; - char *buffer = NULL, *new_buffer; - - if (!(buffer = malloc( buffer_len ))) return NULL; - - for (;;) - { - SERVER_START_REQ( list_processes ) - { - wine_server_set_reply( req, buffer, buffer_len ); - ret = wine_server_call( req ); - buffer_len = reply->info_size; - process_count = reply->process_count; - } - SERVER_END_REQ; - - if (ret != STATUS_INFO_LENGTH_MISMATCH) break; - - if (!(new_buffer = realloc( buffer, buffer_len ))) - { - free( buffer ); - return NULL; - } - buffer = new_buffer; - } - - if (!(map = malloc( process_count * sizeof(*map) ))) - { - free( buffer ); - return NULL; - } - - for (i = 0; i < process_count; ++i) - { - const struct process_info *process; - - pos = (pos + 7) & ~7; - process = (const struct process_info *)(buffer + pos); - - map[i].pid = process->pid; - map[i].unix_pid = process->unix_pid; - - pos += sizeof(struct process_info) + process->name_len; - pos = (pos + 7) & ~7; - pos += process->thread_count * sizeof(struct thread_info); - } - - free( buffer ); - *num_entries = process_count; - return map; -} - -unsigned int find_owning_pid( struct pid_map *map, unsigned int num_entries, UINT_PTR inode ) -{ -#ifdef __linux__ - unsigned int i, len_socket; - char socket[32]; - - sprintf( socket, "socket:[%zu]", inode ); - len_socket = strlen( socket ); - for (i = 0; i < num_entries; i++) - { - char dir[32]; - struct dirent *dirent; - DIR *dirfd; - - sprintf( dir, "/proc/%u/fd", map[i].unix_pid ); - if ((dirfd = opendir( dir ))) - { - while ((dirent = readdir( dirfd ))) - { - char link[sizeof(dirent->d_name) + 32], name[32]; - int len; - - sprintf( link, "/proc/%u/fd/%s", map[i].unix_pid, dirent->d_name ); - if ((len = readlink( link, name, sizeof(name) - 1 )) > 0) name[len] = 0; - if (len == len_socket && !strcmp( socket, name )) - { - closedir( dirfd ); - return map[i].pid; - } - } - closedir( dirfd ); - } - } - return 0; -#elif defined(HAVE_LIBPROCSTAT) - struct procstat *pstat; - struct kinfo_proc *proc; - struct filestat_list *fds; - struct filestat *fd; - struct sockstat sock; - unsigned int i, proc_count; - - pstat = procstat_open_sysctl(); - if (!pstat) return 0; - - for (i = 0; i < num_entries; i++) - { - proc = procstat_getprocs( pstat, KERN_PROC_PID, map[i].unix_pid, &proc_count ); - if (!proc || proc_count < 1) continue; - - fds = procstat_getfiles( pstat, proc, 0 ); - if (!fds) - { - procstat_freeprocs( pstat, proc ); - continue; - } - - STAILQ_FOREACH( fd, fds, next ) - { - char errbuf[_POSIX2_LINE_MAX]; - - if (fd->fs_type != PS_FST_TYPE_SOCKET) continue; - - procstat_get_socket_info( pstat, fd, &sock, errbuf ); - - if (sock.so_pcb == inode) - { - procstat_freefiles( pstat, fds ); - procstat_freeprocs( pstat, proc ); - procstat_close( pstat ); - return map[i].pid; - } - } - - procstat_freefiles( pstat, fds ); - procstat_freeprocs( pstat, proc ); - } - - procstat_close( pstat ); - return 0; -#elif defined(HAVE_PROC_PIDINFO) - struct proc_fdinfo *fds; - struct socket_fdinfo sock; - unsigned int i, j, n; - - for (i = 0; i < num_entries; i++) - { - int fd_len = proc_pidinfo( map[i].unix_pid, PROC_PIDLISTFDS, 0, NULL, 0 ); - if (fd_len <= 0) continue; - - fds = malloc( fd_len ); - if (!fds) continue; - - proc_pidinfo( map[i].unix_pid, PROC_PIDLISTFDS, 0, fds, fd_len ); - n = fd_len / sizeof(struct proc_fdinfo); - for (j = 0; j < n; j++) - { - if (fds[j].proc_fdtype != PROX_FDTYPE_SOCKET) continue; - - proc_pidfdinfo( map[i].unix_pid, fds[j].proc_fd, PROC_PIDFDSOCKETINFO, &sock, sizeof(sock) ); - if (sock.psi.soi_pcb == inode) - { - free( fds ); - return map[i].pid; - } - } - - free( fds ); - } - return 0; -#else - FIXME( "not implemented\n" ); - return 0; -#endif -} - static NTSTATUS tcp_conns_enumerate_all( UINT filter, struct nsi_tcp_conn_key *key_data, UINT key_size, void *rw, UINT rw_size, struct nsi_tcp_conn_dynamic *dynamic_data, UINT dynamic_size, diff --git a/dlls/nsiproxy.sys/unix_private.h b/dlls/nsiproxy.sys/unix_private.h index 907496a01c7..b7c56710e22 100644 --- a/dlls/nsiproxy.sys/unix_private.h +++ b/dlls/nsiproxy.sys/unix_private.h @@ -107,15 +107,6 @@ struct ipv6_addr_scope struct ipv6_addr_scope *get_ipv6_addr_scope_table( unsigned int *size ); UINT find_ipv6_addr_scope( const IN6_ADDR *addr, const struct ipv6_addr_scope *table, unsigned int size );
-struct pid_map -{ - unsigned int pid; - unsigned int unix_pid; -}; - -struct pid_map *get_pid_map( unsigned int *num_entries ); -unsigned int find_owning_pid( struct pid_map *map, unsigned int num_entries, UINT_PTR inode ); - struct module_table { UINT table;