X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Fui.c;h=fd5601f8df8210c3a079d15c70b929168dbdfe39;hb=70628d22a27223639e610c96608e4450ed477d6e;hp=94241e7fbde0d294ea0e28f9a779689ca08cfd57;hpb=efc05613724470915c842b3217ec0625dc8147a7;p=doldaconnect.git diff --git a/daemon/ui.c b/daemon/ui.c index 94241e7..fd5601f 100644 --- a/daemon/ui.c +++ b/daemon/ui.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -315,6 +316,7 @@ static int haspriv(struct uidata *data, int perm) static void cmd_connect(struct socket *sk, struct uidata *data, int argc, wchar_t **argv) { int valid; + struct in6_addr mv4lo; if(confgetint("ui", "onlylocal")) { @@ -324,7 +326,12 @@ static void cmd_connect(struct socket *sk, struct uidata *data, int argc, wchar_ valid = ((struct sockaddr_in *)sk->remote)->sin_addr.s_addr == INADDR_LOOPBACK; break; case AF_INET6: - valid = !memcmp(&((struct sockaddr_in6 *)sk->remote)->sin6_addr, &in6addr_loopback, sizeof(in6addr_loopback)); + 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 = 1; break; default: valid = 0; @@ -430,19 +437,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, but no account existed", data->username); + flog(LOG_INFO, "user %ls authenticated successfully from %s, but no account existed", data->username, formataddress(sk->remote, sk->remotelen)); 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, but was not authorized", data->username); + flog(LOG_INFO, "user %ls authenticated successfully from %s, but was not authorized", data->username, formataddress(sk->remote, sk->remotelen)); logout(data); } else { sq(sk, 0, L"200", L"Welcome", NULL); - flog(LOG_INFO, "%ls (UID %i) logged in", data->username, data->uid); + flog(LOG_INFO, "%ls (UID %i) logged in from %s", data->username, data->uid, formataddress(sk->remote, sk->remotelen)); } 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)); logout(data); break; case AUTH_PASS: @@ -503,19 +511,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, but no account existed", data->username); + flog(LOG_INFO, "user %ls authenticated successfully from %s, but no account existed", data->username, formataddress(sk->remote, sk->remotelen)); 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, but was not authorized", data->username); + flog(LOG_INFO, "user %ls authenticated successfully from %s, but was not authorized", data->username, formataddress(sk->remote, sk->remotelen)); logout(data); } else { sq(sk, 0, L"200", L"Welcome", NULL); - flog(LOG_INFO, "%ls (UID %i) logged in", data->username, data->uid); + flog(LOG_INFO, "%ls (UID %i) logged in from %s", data->username, data->uid, formataddress(sk->remote, sk->remotelen)); } 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)); logout(data); break; case AUTH_PASS: @@ -598,7 +607,7 @@ static void cmd_lsnodes(struct socket *sk, struct uidata *data, int argc, wchar_ } for(fn = fnetnodes; fn != NULL; fn = fn->next) { - sq(sk, (fn->next != NULL)?1:0, L"200", L"%%i", fn->id, fn->fnet->name, (fn->name == NULL)?L"":fn->name, L"%%i", fn->numpeers, L"%%i", fn->state, NULL); + sq(sk, (fn->next != NULL)?1:0, L"200", L"%%i", fn->id, fn->fnet->name, (fn->name == NULL)?L"":fn->name, L"%%i", fn->numpeers, L"%%i", fn->state, L"%%ls", fn->pubid, NULL); } } @@ -1204,6 +1213,18 @@ static void cmd_hashstatus(struct socket *sk, struct uidata *data, int argc, wch sq(sk, 0, L"200", L"%%i", total, L"tth", L"%%i", hashed, NULL); } +static void cmd_transstatus(struct socket *sk, struct uidata *data, int argc, wchar_t **argv) +{ + wchar_t *buf1, *buf2; + + havepriv(PERM_TRANS); + buf1 = swprintf2(L"%lli", bytesdownload); + buf2 = swprintf2(L"%lli", bytesupload); + sq(sk, 0, L"200", L"%%ls", buf1, L"%%ls", buf2, NULL); + free(buf1); + free(buf2); +} + #undef haveargs #undef havepriv @@ -1239,6 +1260,7 @@ static struct command commands[] = {L"filtercmd", cmd_filtercmd}, {L"lstrarg", cmd_lstrarg}, {L"hashstatus", cmd_hashstatus}, + {L"transstatus", cmd_transstatus}, {NULL, NULL} };