diff options
author | Jeremy Allison <jra@samba.org> | 2007-10-03 20:43:55 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:31:09 -0500 |
commit | 0d87820380416955a132d565a479b4234f78c113 (patch) | |
tree | 9e6debb4b26796a386c188e7933ab7032e77e838 /source3/smbd | |
parent | 334b288831c1730cb88fb431f684b9062e139efd (diff) | |
download | samba-0d87820380416955a132d565a479b4234f78c113.tar.gz samba-0d87820380416955a132d565a479b4234f78c113.tar.bz2 samba-0d87820380416955a132d565a479b4234f78c113.zip |
r25492: Start adding IPv6 compatible code to lib/util_sock.c and deal with
the ripple effects this causes. utmp has to change etc. Remove some
global varables and store address/port in the unexpected db.
Jeremy.
(This used to be commit 18c6a2211d9e25233d01715b3f78977edcd6d869)
Diffstat (limited to 'source3/smbd')
-rw-r--r-- | source3/smbd/session.c | 25 | ||||
-rw-r--r-- | source3/smbd/sockinit.c | 63 | ||||
-rw-r--r-- | source3/smbd/utmp.c | 63 |
3 files changed, 85 insertions, 66 deletions
diff --git a/source3/smbd/session.c b/source3/smbd/session.c index 3cc93c1a7f..c7cdf41fb5 100644 --- a/source3/smbd/session.c +++ b/source3/smbd/session.c @@ -62,8 +62,6 @@ BOOL session_claim(user_struct *vuser) { TDB_DATA key, data; int i = 0; - struct sockaddr sa; - struct in_addr *client_ip; struct sessionid sessionid; struct server_id pid = procid_self(); fstring keystr; @@ -124,7 +122,7 @@ BOOL session_claim(user_struct *vuser) TALLOC_FREE(rec); } - + if (i == MAX_SESSION_ID) { SMB_ASSERT(rec == NULL); DEBUG(1,("session_claim: out of session IDs " @@ -147,16 +145,16 @@ BOOL session_claim(user_struct *vuser) return False; } - snprintf(sessionid.id_str, sizeof(sessionid.id_str), - SESSION_TEMPLATE, (long unsigned int)sys_getpid(), + snprintf(sessionid.id_str, sizeof(sessionid.id_str), + SESSION_TEMPLATE, (long unsigned int)sys_getpid(), vuser->vuid); } SMB_ASSERT(rec != NULL); /* If 'hostname lookup' == yes, then do the DNS lookup. This is - needed because utmp and PAM both expect DNS names - + needed because utmp and PAM both expect DNS names + client_name() handles this case internally. */ @@ -172,11 +170,9 @@ BOOL session_claim(user_struct *vuser) sessionid.uid = vuser->uid; sessionid.gid = vuser->gid; fstrcpy(sessionid.remote_machine, get_remote_machine_name()); - fstrcpy(sessionid.ip_addr, client_addr()); + fstrcpy(sessionid.ip_addr_str, client_addr()); sessionid.connect_start = time(NULL); - client_ip = client_inaddr(&sa); - if (!smb_pam_claim_session(sessionid.username, sessionid.id_str, sessionid.hostname)) { DEBUG(1,("pam_session rejected the session for %s [%s]\n", @@ -200,8 +196,8 @@ BOOL session_claim(user_struct *vuser) } if (lp_utmp()) { - sys_utmp_claim(sessionid.username, sessionid.hostname, - client_ip, + sys_utmp_claim(sessionid.username, sessionid.hostname, + sessionid.ip_addr_str, sessionid.id_str, sessionid.id_num); } @@ -224,7 +220,6 @@ void session_yield(user_struct *vuser) { TDB_DATA key; struct sessionid sessionid; - struct in_addr *client_ip; struct db_context *ctx; struct db_record *rec; @@ -245,11 +240,9 @@ void session_yield(user_struct *vuser) memcpy(&sessionid, rec->value.dptr, sizeof(sessionid)); - client_ip = interpret_addr2(sessionid.ip_addr); - if (lp_utmp()) { sys_utmp_yield(sessionid.username, sessionid.hostname, - client_ip, + sessionid.ip_addr_str, sessionid.id_str, sessionid.id_num); } diff --git a/source3/smbd/sockinit.c b/source3/smbd/sockinit.c index c526a181d3..598bbd1bda 100644 --- a/source3/smbd/sockinit.c +++ b/source3/smbd/sockinit.c @@ -1,19 +1,19 @@ -/* +/* Unix SMB/CIFS implementation. Copyright (C) Andrew Tridgell 1992-1998 Copyright (C) James Peach 2007 - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -43,11 +43,11 @@ static int init_sockets_smbd(const char *smb_ports, int listenset[FD_SETSIZE]) } if (lp_interfaces() && lp_bind_interfaces_only()) { - /* We have been given an interfaces line, and been + /* We have been given an interfaces line, and been told to only bind to those interfaces. Create a socket per interface and bind to only these. */ - + /* Now open a listen socket for each of the interfaces. */ for(i = 0; i < num_interfaces; i++) { @@ -56,35 +56,45 @@ static int init_sockets_smbd(const char *smb_ports, int listenset[FD_SETSIZE]) const char *ptr; if(ifip == NULL) { - DEBUG(0,("init_sockets_smbd: interface %d has NULL IP address !\n", i)); + DEBUG(0,("init_sockets_smbd: interface %d has " + "NULL IP address !\n", i)); continue; } - for (ptr=ports; next_token(&ptr, tok, " \t,", sizeof(tok)); ) { + for (ptr=ports; next_token(&ptr, tok, " \t,", + sizeof(tok)); ) { unsigned port = atoi(tok); if (port == 0 || port > 0xffff) { continue; } - s = listenset[num_sockets] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True); + s = listenset[num_sockets] = + open_socket_in(SOCK_STREAM, + port, + 0, + ifip->s_addr, + True); if(s == -1) return 0; /* ready to listen */ - set_socket_options(s,"SO_KEEPALIVE"); + set_socket_options(s,"SO_KEEPALIVE"); set_socket_options(s,user_socket_options); - - /* Set server socket to non-blocking for the accept. */ - set_blocking(s,False); - + + /* Set server socket to non-blocking + * for the accept. */ + set_blocking(s,False); + if (listen(s, SMBD_LISTEN_BACKLOG) == -1) { - DEBUG(0,("listen: %s\n",strerror(errno))); + DEBUG(0,("listen: %s\n", + strerror(errno))); close(s); return 0; } num_sockets++; if (num_sockets >= FD_SETSIZE) { - DEBUG(0,("init_sockets_smbd: Too many sockets to bind to\n")); + DEBUG(0,("init_sockets_smbd: " + "Too many sockets to bind to\n")); return 0; } } @@ -97,23 +107,24 @@ static int init_sockets_smbd(const char *smb_ports, int listenset[FD_SETSIZE]) const char *ptr; num_interfaces = 1; - + for (ptr=ports; next_token(&ptr, tok, " \t,", sizeof(tok)); ) { unsigned port = atoi(tok); if (port == 0 || port > 0xffff) continue; /* open an incoming socket */ s = open_socket_in(SOCK_STREAM, port, 0, - interpret_addr(lp_socket_address()),True); + interpret_addr(lp_socket_address()), + True); if (s == -1) return 0; - + /* ready to listen */ - set_socket_options(s,"SO_KEEPALIVE"); + set_socket_options(s,"SO_KEEPALIVE"); set_socket_options(s,user_socket_options); - + /* Set server socket to non-blocking for the accept. */ - set_blocking(s,False); - + set_blocking(s,False); + if (listen(s, SMBD_LISTEN_BACKLOG) == -1) { DEBUG(0,("init_sockets_smbd: listen: %s\n", strerror(errno))); @@ -125,11 +136,12 @@ static int init_sockets_smbd(const char *smb_ports, int listenset[FD_SETSIZE]) num_sockets++; if (num_sockets >= FD_SETSIZE) { - DEBUG(0,("init_sockets_smbd: Too many sockets to bind to\n")); + DEBUG(0,("init_sockets_smbd: " + "Too many sockets to bind to\n")); return 0; } } - } + } SAFE_FREE(ports); return num_sockets; @@ -197,4 +209,3 @@ int smbd_sockinit(const char *cmdline_ports, int listenset[FD_SETSIZE], return num_sockets; } - diff --git a/source3/smbd/utmp.c b/source3/smbd/utmp.c index eb2152dac2..52174c4d83 100644 --- a/source3/smbd/utmp.c +++ b/source3/smbd/utmp.c @@ -112,14 +112,14 @@ Notes: * Not WITH_UTMP? Simply supply dummy routines. */ -void sys_utmp_claim(const char *username, const char *hostname, - struct in_addr *ipaddr, - const char *id_str, int id_num) +void sys_utmp_claim(const char *username, const char *hostname, + const char *ip_addr_str, + const char *id_str, int id_num) {} -void sys_utmp_yield(const char *username, const char *hostname, - struct in_addr *ipaddr, - const char *id_str, int id_num) +void sys_utmp_yield(const char *username, const char *hostname, + const char *ip_addr_str, + const char *id_str, int id_num) {} #else /* WITH_UTMP */ @@ -448,7 +448,7 @@ static int ut_id_encode(int i, char *fourbyte) { int nbase; const char *ut_id_encstr = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - + fourbyte[0] = 'S'; fourbyte[1] = 'M'; @@ -470,13 +470,13 @@ static int ut_id_encode(int i, char *fourbyte) /* - fill a system utmp structure given all the info we can gather + fill a system utmp structure given all the info we can gather */ static BOOL sys_utmp_fill(struct utmp *u, - const char *username, const char *hostname, - struct in_addr *ipaddr, - const char *id_str, int id_num) -{ + const char *username, const char *hostname, + const char *ip_addr_str, + const char *id_str, int id_num) +{ struct timeval timeval; /* @@ -507,7 +507,7 @@ static BOOL sys_utmp_fill(struct utmp *u, #endif /* - * ut_time, ut_tv: + * ut_time, ut_tv: * Some have one, some the other. Many have both, but defined (aliased). * It is easier and clearer simply to let the following take its course. * But note that we do the more precise ut_tv as the final assignment. @@ -525,9 +525,22 @@ static BOOL sys_utmp_fill(struct utmp *u, #if defined(HAVE_UT_UT_HOST) utmp_strcpy(u->ut_host, hostname, sizeof(u->ut_host)); #endif -#if defined(HAVE_UT_UT_ADDR) - if (ipaddr) - u->ut_addr = ipaddr->s_addr; +#if defined(AF_INET6) && defined(HAVE_UT_UT_ADDR_V6) + memset(&u->ut_addr_v6, '\0', sizeof(u->ut_addr_v6)); + if (ip_addr_str) { + struct in6_addr addr; + if (inet_pton(AF_INET6, ip_addr_str, &addr) > 0) { + memcpy(&u->ut_addr_v6, &addr, sizeof(addr)); + } + } +#elif defined(HAVE_UT_UT_ADDR) + memset(&u->ut_addr, '\0', sizeof(u->ut_addr)); + if (ip_addr_str) { + struct in_addr addr; + if (inet_pton(AF_INET, ip_addr_str, &addr) > 0) { + memcpy(&u->ut_addr, &addr, sizeof(addr)); + } + } /* * "(unsigned long) ut_addr" apparently exists on at least HP-UX 10.20. * Volunteer to implement, please ... @@ -548,9 +561,9 @@ static BOOL sys_utmp_fill(struct utmp *u, Close a connection. ****************************************************************************/ -void sys_utmp_yield(const char *username, const char *hostname, - struct in_addr *ipaddr, - const char *id_str, int id_num) +void sys_utmp_yield(const char *username, const char *hostname, + const char *ip_addr_str, + const char *id_str, int id_num) { struct utmp u; @@ -565,7 +578,8 @@ void sys_utmp_yield(const char *username, const char *hostname, u.ut_type = DEAD_PROCESS; #endif - if (!sys_utmp_fill(&u, username, hostname, ipaddr, id_str, id_num)) return; + if (!sys_utmp_fill(&u, username, hostname, ip_addr_str, id_str, id_num)) + return; sys_utmp_update(&u, NULL, False); } @@ -574,9 +588,9 @@ void sys_utmp_yield(const char *username, const char *hostname, Claim a entry in whatever utmp system the OS uses. ****************************************************************************/ -void sys_utmp_claim(const char *username, const char *hostname, - struct in_addr *ipaddr, - const char *id_str, int id_num) +void sys_utmp_claim(const char *username, const char *hostname, + const char *ip_addr_str, + const char *id_str, int id_num) { struct utmp u; @@ -586,7 +600,8 @@ void sys_utmp_claim(const char *username, const char *hostname, u.ut_type = USER_PROCESS; #endif - if (!sys_utmp_fill(&u, username, hostname, ipaddr, id_str, id_num)) return; + if (!sys_utmp_fill(&u, username, hostname, ip_addr_str, id_str, id_num)) + return; sys_utmp_update(&u, hostname, True); } |