From: Fredrik Tolf Date: Sun, 16 Mar 2008 01:45:29 +0000 (+0100) Subject: Ported interfacing modules to new socket API. X-Git-Tag: 1.3~30 X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=d1ef02006f3d39a45ef40235f716c7f9317195f6;p=doldaconnect.git Ported interfacing modules to new socket API. --- diff --git a/daemon/auth-unix.c b/daemon/auth-unix.c index 00266e1..7cf9c8e 100644 --- a/daemon/auth-unix.c +++ b/daemon/auth-unix.c @@ -59,16 +59,18 @@ static int unixauth(struct authhandle *auth, struct socket *sk, char *passdata) { struct passwd *pwd; struct unixdata *data; + uid_t uid; + gid_t gid; data = auth->mechdata; if((pwd = getpwnam(data->username)) == NULL) return(AUTH_ERR); - if(sk->ucred.uid == -1) { + if(getucred(sk, &uid, &gid)) { errno = EOPNOTSUPP; /* Bleh */ return(AUTH_ERR); } - if(pwd->pw_uid == sk->ucred.uid) { - flog(LOG_INFO, "successful authentication as %s with Unix credentials (uid=%i, gid=%i)", data->username, sk->ucred.uid, sk->ucred.gid); + if(pwd->pw_uid == uid) { + flog(LOG_INFO, "successful authentication as %s with Unix credentials (uid=%i, gid=%i)", data->username, uid, gid); return(AUTH_SUCCESS); } auth->text = swcsdup(L"Unix credentials do not match supplied user name"); @@ -77,7 +79,7 @@ static int unixauth(struct authhandle *auth, struct socket *sk, char *passdata) static int available(struct socket *sk) { - return((sk->family == PF_UNIX) && (sk->ucred.uid != -1)); + return(sockfamily(sk) == PF_UNIX); } static struct authmech mechdesc = { diff --git a/daemon/fnet-adc.c b/daemon/fnet-adc.c index a15575d..0112710 100644 --- a/daemon/fnet-adc.c +++ b/daemon/fnet-adc.c @@ -81,7 +81,8 @@ struct adchub { static wchar_t *eoc, *ns, *fmt; /* I've never understood why both of these are necessary, but... */ static wchar_t *privid, *cid; -struct socket *udpsock, *tcpsock; +struct socket *udpsock; +struct lport *tcpsock; static wchar_t **parseadc(wchar_t *cmdline) { @@ -240,13 +241,13 @@ static void sendinf(struct fnetnode *fn) sendadc(sk, 1, L"VEDolda ", ns, icsmbstowcs(VERSION, "us-ascii", NULL), NULL); sendadc(sk, 1, L"NI", ns, fn->mynick, NULL); sendadc(sk, 1, L"SS", ns, fmt, L"mi", (intmax_t)sharesize, L"SF", ns, fmt, L"i", sharedfiles, NULL); - if(sk->family == AF_INET) + if(sockfamily(sk) == AF_INET) sendadc(sk, 1, L"I40.0.0.0", NULL); - else if(sk->family == AF_INET6) + else if(sockfamily(sk) == AF_INET6) sendadc(sk, 1, L"I6::", NULL); sendadc(sk, 1, L"SL", ns, fmt, L"i", confgetint("transfer", "slot"), NULL); if(tcpsock != NULL) { - if((sk->family == AF_INET) && !sockgetremotename(udpsock, (struct sockaddr **)&a4, &alen)) { + if((sockfamily(sk) == AF_INET) && !sockgetremotename(udpsock, (struct sockaddr **)&a4, &alen)) { sendadc(sk, 1, L"U4", ns, fmt, L"i", ntohs(a4->sin_port), NULL); free(a4); } @@ -359,7 +360,7 @@ static void dispatch(struct qcmd *qcmd, struct fnetnode *fn) flog(LOG_DEBUG, "unknown adc command: %ls", qcmd->args[0]); } -static void peeraccept(struct socket *sk, struct socket *newsk, void *uudata) +static void peeraccept(struct lport *lp, struct socket *newsk, void *uudata) { } @@ -463,7 +464,7 @@ static void hubkill(struct fnetnode *fn) struct adchub *hub; hub = fn->data; - hub->sk->close = 1; + closesock(hub->sk); } static int hubsetnick(struct fnetnode *fn, wchar_t *newnick) @@ -565,7 +566,7 @@ static int updateudpport(struct configvar *var, void *uudata) static int updatetcpport(struct configvar *var, void *uudata) { struct sockaddr_in addr; - struct socket *newsock; + struct lport *newsock; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; @@ -573,7 +574,7 @@ static int updatetcpport(struct configvar *var, void *uudata) if((newsock = netcslisten(SOCK_STREAM, (struct sockaddr *)&addr, sizeof(addr), peeraccept, NULL)) == NULL) flog(LOG_INFO, "could not listen to a remote address, going into passive mode"); if(tcpsock != NULL) - putsock(tcpsock); + closelport(tcpsock); tcpsock = newsock; return(0); } diff --git a/daemon/fnet-dc.c b/daemon/fnet-dc.c index 3dbb81f..58340b4 100644 --- a/daemon/fnet-dc.c +++ b/daemon/fnet-dc.c @@ -141,7 +141,7 @@ struct dcpeer static struct fnet dcnet; static struct transferiface dctransfer; static struct socket *udpsock = NULL; -static struct socket *tcpsock = NULL; +static struct lport *tcpsock = NULL; static struct dcpeer *peers = NULL; int numdcpeers = 0; static struct dcexppeer *expected = NULL; @@ -1145,7 +1145,7 @@ static void cmd_search(struct socket *sk, struct fnetnode *fn, char *cmd, char * goto out; prefix = sprintf2("$SR %s ", hub->nativenick); infix = sprintf2(" %i/%i\005", slotsleft(), confgetint("transfer", "slots")); - postfix = sprintf2(" (%s)\005%s|", formataddress(hub->sk->remote, hub->sk->remotelen), args + 4); + postfix = sprintf2(" (%s)\005%s|", formatsockpeer(hub->sk), args + 4); dsk = sk; getsock(dsk); } else { @@ -1158,8 +1158,8 @@ static void cmd_search(struct socket *sk, struct fnetnode *fn, char *cmd, char * addr.sin_port = htons(atoi(p2)); prefix = sprintf2("$SR %s ", hub->nativenick); infix = sprintf2(" %i/%i\005", slotsleft(), confgetint("transfer", "slots")); - postfix = sprintf2(" (%s)|", formataddress(hub->sk->remote, hub->sk->remotelen)); - netdgramconn(dsk = netdupsock(udpsock), (struct sockaddr *)&addr, sizeof(addr)); + postfix = sprintf2(" (%s)|", formatsockpeer(hub->sk)); + dsk = netdgramconn(udpsock, (struct sockaddr *)&addr, sizeof(addr)); } minsize = maxsize = -1; @@ -1351,7 +1351,7 @@ static void sendctm(struct socket *sk, char *nick) if(tcpsock == NULL) return; - if(sockgetremotename2(tcpsock, sk, &addr, &addrlen) < 0) + if(getremotename2(tcpsock, sk, &addr, &addrlen) < 0) return; if(addr->sa_family == AF_INET) qstrf(sk, "$ConnectToMe %s %s|", nick, formataddress(addr, addrlen)); @@ -2294,7 +2294,6 @@ static void cmd_adcsnd(struct socket *sk, struct dcpeer *peer, char *cmd, char * { sockpushdata(sk, peer->inbuf, peer->inbufdata); peer->inbufdata = 0; - transread(sk, peer); } } else { /* We certainly didn't request this...*/ @@ -2327,7 +2326,6 @@ static void cmd_sending(struct socket *sk, struct dcpeer *peer, char *cmd, char { sockpushdata(sk, peer->inbuf, peer->inbufdata); peer->inbufdata = 0; - transread(sk, peer); } } @@ -2767,7 +2765,7 @@ static void dctransendofdata(struct transfer *transfer, struct dcpeer *peer) static void dcwantdata(struct transfer *transfer, struct dcpeer *peer) { if(transferdatasize(transfer) < 65536) - peer->sk->ignread = 0; + sockblock(peer->sk, 0); } static void transread(struct socket *sk, struct dcpeer *peer) @@ -2794,7 +2792,7 @@ static void transread(struct socket *sk, struct dcpeer *peer) return; } if(transferdatasize(peer->transfer) > 65535) - sk->ignread = 1; + sockblock(sk, 1); } static void transerr(struct socket *sk, int err, struct dcpeer *peer) @@ -2828,6 +2826,7 @@ static void udpread(struct socket *sk, void *data) size_t buflen, hashlen; char *nick, *filename, *hubname; struct sockaddr_in hubaddr; + struct sockaddr *addrbuf; off_t size; int slots; struct fnetnode *fn, *myfn; @@ -2947,13 +2946,14 @@ static void udpread(struct socket *sk, void *data) { for(fn = fnetnodes; fn != NULL; fn = fn->next) { - if((fn->fnet == &dcnet) && ((hub = fn->data) != NULL)) + if((fn->fnet == &dcnet) && ((hub = fn->data) != NULL) && !sockpeeraddr(hub->sk, &addrbuf, NULL)) { - if((hub->sk != NULL) && addreq(hub->sk->remote, (struct sockaddr *)&hubaddr)) + if((hub->sk != NULL) && addreq(addrbuf, (struct sockaddr *)&hubaddr)) { myfn = fn; break; } + free(addrbuf); } } } @@ -3016,7 +3016,7 @@ static void hubread(struct socket *sk, struct fnetnode *fn) } memmove(hub->inbuf, p, hub->inbufdata -= p - hub->inbuf); if(hub->queue.size > 1000) - sk->ignread = 1; + sockblock(sk, 1); } static void huberr(struct socket *sk, int err, struct fnetnode *fn) @@ -3204,7 +3204,7 @@ static void hubkill(struct fnetnode *fn) struct dchub *hub; hub = (struct dchub *)fn->data; - hub->sk->close = 1; + closesock(hub->sk); } static struct transferiface dctransfer = @@ -3260,14 +3260,14 @@ static void peerread(struct socket *sk, struct dcpeer *peer) break; } else { if(peer->queue.size > 50) - sk->ignread = 1; + sockblock(sk, 1); } } } else if(peer->state == PEER_TTHL) { handletthl(peer); } if(peer->inbufdata > 500000) - sk->ignread = 1; + sockblock(sk, 1); } static void peererror(struct socket *sk, int err, struct dcpeer *peer) @@ -3301,7 +3301,7 @@ static void peerconnect(struct socket *sk, int err, struct fnetnode *fn) sendpeerlock(peer); } -static void peeraccept(struct socket *sk, struct socket *newsk, void *data) +static void peeraccept(struct lport *lp, struct socket *newsk, void *data) { struct dcpeer *peer; @@ -3771,7 +3771,7 @@ static int run(void) quota--; } if(hub->queue.size < 1000) - hub->sk->ignread = 0; + sockblock(hub->sk, 0); if(quota < 1) break; } @@ -3790,7 +3790,7 @@ static int run(void) quota--; } if((peer->queue.size < 50) && (peer->inbufdata < 500000)) - peer->sk->ignread = 0; + sockblock(peer->sk, 0); if(quota < 1) break; } @@ -3833,7 +3833,7 @@ static int updateudpport(struct configvar *var, void *uudata) static int updatetcpport(struct configvar *var, void *uudata) { struct sockaddr_in addr; - struct socket *newsock; + struct lport *newsock; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; @@ -3841,7 +3841,7 @@ static int updatetcpport(struct configvar *var, void *uudata) if((newsock = netcslisten(SOCK_STREAM, (struct sockaddr *)&addr, sizeof(addr), peeraccept, NULL)) == NULL) flog(LOG_INFO, "could not listen to a remote address, going into passive mode"); if(tcpsock != NULL) - putsock(tcpsock); + closelport(tcpsock); tcpsock = newsock; return(0); } @@ -3856,7 +3856,7 @@ static int init(int hup) if(udpsock != NULL) putsock(udpsock); if(tcpsock != NULL) - putsock(tcpsock); + closelport(tcpsock); addr.sin_family = AF_INET; memset(&addr.sin_addr, 0, sizeof(addr.sin_addr)); addr.sin_port = htons(confgetint("dc", "udpport")); diff --git a/daemon/transfer.c b/daemon/transfer.c index 29ad45d..433ceb1 100644 --- a/daemon/transfer.c +++ b/daemon/transfer.c @@ -235,7 +235,7 @@ static void transexpire(int cancelled, struct transfer *transfer) static void transferread(struct socket *sk, struct transfer *transfer) { if(sockgetdatalen(sk) >= 65536) - sk->ignread = 1; + sockblock(sk, 1); if((transfer->iface != NULL) && (transfer->iface->gotdata != NULL)) transfer->iface->gotdata(transfer, transfer->ifacedata); } @@ -287,7 +287,7 @@ void *transfergetdata(struct transfer *transfer, size_t *size) if(transfer->localend == NULL) return(NULL); - transfer->localend->ignread = 0; + sockblock(transfer->localend, 0); time(&transfer->activity); if((buf = sockgetinbuf(transfer->localend, size)) == NULL) return(NULL); @@ -311,7 +311,7 @@ void transferprepul(struct transfer *transfer, off_t size, off_t start, off_t en transfersetsize(transfer, size); transfer->curpos = start; transfer->endpos = end; - lesk->ignread = 1; + sockblock(lesk, 1); transfersetlocalend(transfer, lesk); } @@ -326,7 +326,7 @@ void transferstartul(struct transfer *transfer, struct socket *sk) transfersetstate(transfer, TRNS_MAIN); socksettos(sk, confgetint("transfer", "ultos")); if(transfer->localend != NULL) - transfer->localend->ignread = 0; + sockblock(transfer->localend, 0); } void transfersetlocalend(struct transfer *transfer, struct socket *sk) @@ -716,7 +716,7 @@ int forkfilter(struct transfer *transfer) * the fd, and thus it closes it. Until I can find out whyever the * kernel gives a POLLIN on the fd (if I can at all...), I'll just * set ignread on insock for now. */ - insock->ignread = 1; + sockblock(insock, 1); transfer->filter = pid; transfersetlocalend(transfer, insock); getsock(transfer->filterout = outsock); diff --git a/daemon/ui.c b/daemon/ui.c index 9d10fa2..0f6e701 100644 --- a/daemon/ui.c +++ b/daemon/ui.c @@ -171,8 +171,8 @@ static void notifappend(struct notif *notif, ...); struct uiuser *users = NULL; struct uidata *actives = NULL; -struct socket *tcpsocket = NULL; -struct socket *unixsocket = NULL; +struct lport *tcpsocket = NULL; +struct lport *unixsocket = NULL; static time_t starttime; static wchar_t *quoteword(wchar_t *word) @@ -340,33 +340,35 @@ static void cmd_connect(struct socket *sk, struct uidata *data, int argc, wchar_ { int valid; struct in6_addr mv4lo; + struct sockaddr *remote; if(confgetint("ui", "onlylocal")) { - switch(sk->remote->sa_family) - { - case AF_INET: - valid = ((struct sockaddr_in *)sk->remote)->sin_addr.s_addr == INADDR_LOOPBACK; - break; - case AF_INET6: - inet_pton(AF_INET6, "::ffff:127.0.0.1", &mv4lo); - valid = 0; - if(!memcmp(&((struct sockaddr_in6 *)sk->remote)->sin6_addr, &in6addr_loopback, sizeof(in6addr_loopback))) - valid = 1; - if(!memcmp(&((struct sockaddr_in6 *)sk->remote)->sin6_addr, &mv4lo, sizeof(in6addr_loopback))) + valid = 0; + if(!sockpeeraddr(sk, &remote, NULL)) { + switch(remote->sa_family) + { + case AF_INET: + valid = ((struct sockaddr_in *)remote)->sin_addr.s_addr == INADDR_LOOPBACK; + break; + case AF_INET6: + inet_pton(AF_INET6, "::ffff:127.0.0.1", &mv4lo); + valid = 0; + if(!memcmp(&((struct sockaddr_in6 *)remote)->sin6_addr, &in6addr_loopback, sizeof(in6addr_loopback))) + valid = 1; + if(!memcmp(&((struct sockaddr_in6 *)remote)->sin6_addr, &mv4lo, sizeof(in6addr_loopback))) + valid = 1; + break; + case AF_UNIX: valid = 1; - break; - case AF_UNIX: - valid = 1; - break; - default: - valid = 0; - break; + break; + } + free(remote); } if(!valid) { sq(sk, 0, L"502", L"Only localhost connections allowed to this host", NULL); - sk->close = 1; + closesock(sk); data->close = 1; return; } @@ -463,20 +465,20 @@ static void cmd_login(struct socket *sk, struct uidata *data, int argc, wchar_t if(data->uid == -1) { sq(sk, 0, L"506", L"Authentication error", NULL); - flog(LOG_INFO, "user %ls authenticated successfully from %s, but no account existed", data->username, formataddress(sk->remote, sk->remotelen)); + flog(LOG_INFO, "user %ls authenticated successfully from %s, but no account existed", data->username, formatsockpeer(sk)); logout(data); } else if((data->userinfo == NULL) || (data->userinfo->perms & PERM_DISALLOW)) { sq(sk, 0, L"506", L"Authentication error", NULL); - flog(LOG_INFO, "user %ls authenticated successfully from %s, but was not authorized", data->username, formataddress(sk->remote, sk->remotelen)); + flog(LOG_INFO, "user %ls authenticated successfully from %s, but was not authorized", data->username, formatsockpeer(sk)); logout(data); } else { sq(sk, 0, L"200", L"Welcome", NULL); - flog(LOG_INFO, "%ls (UID %i) logged in from %s", data->username, data->uid, formataddress(sk->remote, sk->remotelen)); + flog(LOG_INFO, "%ls (UID %i) logged in from %s", data->username, data->uid, formatsockpeer(sk)); } break; case AUTH_DENIED: sq(sk, 0, L"506", L"Authentication error", L"%ls", (data->auth->text == NULL)?L"":(data->auth->text), NULL); - flog(LOG_INFO, "authentication failed for %ls from %s", data->username, formataddress(sk->remote, sk->remotelen)); + flog(LOG_INFO, "authentication failed for %ls from %s", data->username, formatsockpeer(sk)); logout(data); break; case AUTH_PASS: @@ -537,20 +539,20 @@ static void cmd_pass(struct socket *sk, struct uidata *data, int argc, wchar_t * if(data->uid == -1) { sq(sk, 0, L"506", L"Authentication error", NULL); - flog(LOG_INFO, "user %ls authenticated successfully from %s, but no account existed", data->username, formataddress(sk->remote, sk->remotelen)); + flog(LOG_INFO, "user %ls authenticated successfully from %s, but no account existed", data->username, formatsockpeer(sk)); logout(data); } else if((data->userinfo == NULL) || (data->userinfo->perms & PERM_DISALLOW)) { sq(sk, 0, L"506", L"Authentication error", NULL); - flog(LOG_INFO, "user %ls authenticated successfully from %s, but was not authorized", data->username, formataddress(sk->remote, sk->remotelen)); + flog(LOG_INFO, "user %ls authenticated successfully from %s, but was not authorized", data->username, formatsockpeer(sk)); logout(data); } else { sq(sk, 0, L"200", L"Welcome", NULL); - flog(LOG_INFO, "%ls (UID %i) logged in from %s", data->username, data->uid, formataddress(sk->remote, sk->remotelen)); + flog(LOG_INFO, "%ls (UID %i) logged in from %s", data->username, data->uid, formatsockpeer(sk)); } break; case AUTH_DENIED: sq(sk, 0, L"506", L"Authentication error", L"%ls", (data->auth->text == NULL)?L"":(data->auth->text), NULL); - flog(LOG_INFO, "authentication failed for %ls from %s", data->username, formataddress(sk->remote, sk->remotelen)); + flog(LOG_INFO, "authentication failed for %ls from %s", data->username, formatsockpeer(sk)); logout(data); break; case AUTH_PASS: @@ -1821,7 +1823,7 @@ static void uierror(struct socket *sk, int err, struct uidata *data) freeuidata(data); } -static void uiaccept(struct socket *sk, struct socket *newsk, void *data) +static void uiaccept(struct lport *lp, struct socket *newsk, void *data) { struct uidata *uidata; @@ -2235,7 +2237,7 @@ static struct sockaddr_un *makeunixname(void) static int tcpportupdate(struct configvar *var, void *uudata) { - struct socket *newsock; + struct lport *newsock; newsock = NULL; if((var->val.num != -1) && ((newsock = netcstcplisten(var->val.num, 1, uiaccept, NULL)) == NULL)) @@ -2245,7 +2247,7 @@ static int tcpportupdate(struct configvar *var, void *uudata) } if(tcpsocket != NULL) { - putsock(tcpsocket); + closelport(tcpsocket); tcpsocket = NULL; } tcpsocket = newsock; @@ -2254,7 +2256,7 @@ static int tcpportupdate(struct configvar *var, void *uudata) static int unixsockupdate(struct configvar *var, void *uudata) { - struct socket *newsock; + struct lport *newsock; struct sockaddr_un *un; mode_t ou; @@ -2269,7 +2271,7 @@ static int unixsockupdate(struct configvar *var, void *uudata) umask(ou); if(unixsocket != NULL) { - putsock(unixsocket); + closelport(unixsocket); unixsocket = NULL; } unixsocket = newsock; @@ -2427,9 +2429,9 @@ static void terminate(void) while(users != NULL) freeuser(users); if(tcpsocket != NULL) - putsock(tcpsocket); + closelport(tcpsocket); if(unixsocket != NULL) - putsock(unixsocket); + closelport(unixsocket); } static struct configvar myvars[] =