diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..f01e7779057d55c3e2f9d091c60879e100af9deb --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,7 @@ +stages: + - update-from-upstream + +include: + - project: 'e/templates' + ref: master + file: '/gitlab-ci/.gitlab-ci-import-updates-from-upstream.yml' diff --git a/resolv/getaddrinfo.cpp b/resolv/getaddrinfo.cpp index cf8e4d269f980c7bfb495e01d2bb31036b4877b9..5065497d280f17e1918696296f60eec0e5f0f759 100644 --- a/resolv/getaddrinfo.cpp +++ b/resolv/getaddrinfo.cpp @@ -3,6 +3,7 @@ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * Copyright (C) 2022 ECORP * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -275,6 +276,66 @@ int getaddrinfo_numeric(const char* hostname, const char* servname, addrinfo hin &event); } +int shouldBlockRequest(const char* hostname, int uid){ + int sock, len; + struct sockaddr_un server; + char message[1000], server_reply[2000]; + + //Create socket + sock = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + if (sock == -1) { + LOG(DEBUG) << "Socket: Could not create socket"; + } + LOG(DEBUG) << "Socket: created"; + + char const* name = "foundation.e.privacy"; + int nameLen = strlen(name); + server.sun_path[0] = '\0'; /* abstract namespace */ + strncpy(server.sun_path + 1, name, nameLen); + server.sun_family = AF_UNIX; + len = 1 + nameLen + offsetof(struct sockaddr_un, sun_path); + + //Connect to remote server + if (connect(sock, (struct sockaddr *)&server, len) < 0) { + LOG(DEBUG) << "Socket: connect failed. Error"; + close(sock); + return -1; + } + + LOG(DEBUG) << "Socket: Connected"; + + //keep communicating with server + snprintf(message, sizeof(message), "%s,%d", hostname, uid); + + //Send some data + if(send(sock, message, strlen(message), 0) < 0) { + LOG(DEBUG) << "Socket: Send failed"; + close(sock); + return 0; + } + shutdown(sock, SHUT_WR); + //Receive a reply from the server + if (recv(sock, server_reply, 2000, 0) < 0) { + LOG(DEBUG) << "Socket:recv failed"; + close(sock); + return 0; + } + + LOG(DEBUG) << "Socket: Server reply : " << server_reply; + if (strncmp(server_reply, "pass", 4) == 0) { + LOG(DEBUG) << "Socket: Shouldn't block"; + close(sock); + return 0; + } else { + LOG(DEBUG) << "Socket: should block"; + close(sock); + return 1; + } + close(sock); + return 0; + +} + int android_getaddrinfofornetcontext(const char* hostname, const char* servname, const struct addrinfo* hints, const struct android_net_context* netcontext, @@ -301,6 +362,12 @@ int android_getaddrinfofornetcontext(const char* hostname, const char* servname, .ai_next = nullptr, }; + if (shouldBlockRequest(hostname, netcontext->uid)) { + char* dest = new char[10]; + strncpy(dest, "localhost", strlen("localhost")); + hostname = dest; + } + do { if (hostname == NULL && servname == NULL) { error = EAI_NONAME;