On 5 July 2016 at 12:36, Bernhard Reutner-Fischer <[email protected]>
wrote:
On Tue, Jul 05, 2016 at 12:48:36PM +0200, Bernhard Reutner-Fischer wrote:
> On July 5, 2016 12:26:07 PM GMT+02:00, "Vito Mulè" <[email protected]>
wrote:
>
>
> Care to send an updated patch, including bloat-o-meter output?

Hello I managed to get the whois server hostname as you suggested, please
let me know what you think.
Patch also attached to the bug
Thanks

vmule@agent4:~/busybox.old$ ./busybox_unstripped whois  nic.ikano
Domain Name: nic.ikano
Domain ID: D0000000007-IKANO
WHOIS Server: whois.nic.ikano
Referral URL: http://www.nic.ikano/

vmule@agent4:~/busybox.old$ ./busybox_unstripped whois amazon.it

Domain:             amazon.it
Status:             ok
Created:            2000-02-10 00:00:00
Last Update:        2016-01-28 00:47:21
Expire Date:        2017-01-12



Signed-off-by: Vito Mule' <[email protected]>

function                                             old     new   delta
whois_host                                             -     277    +277
whois_main                                           133     277    +144
WHOIS_HOST                                             -      15     +15
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 1/0 up/down: 436/0)             Total: 436
bytes

---
 networking/whois.c | 78
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 68 insertions(+), 10 deletions(-)

diff --git a/networking/whois.c b/networking/whois.c
index bf33033..052f079 100644
--- a/networking/whois.c
+++ b/networking/whois.c
@@ -3,6 +3,7 @@
  * whois - tiny client for the whois directory service
  *
  * Copyright (c) 2011 Pere Orga <[email protected]>
+ * modified by Vito Mule' <[email protected]>
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 /* TODO
@@ -28,6 +29,11 @@

 #include "libbb.h"

+static const char WHOIS_HOST[] = "whois.iana.org";
+#define WHOIS_HOST_LEN  128
+#define WHOIS_DOMAIN_LEN  32
+#define WHOIS_PORT 43
+
 static void pipe_out(int fd)
 {
  FILE *fp;
@@ -36,30 +42,82 @@ static void pipe_out(int fd)
  fp = xfdopen_for_read(fd);
  while (fgets(buf, sizeof(buf), fp)) {
  char *p = strpbrk(buf, "\r\n");
- if (p)
+ if (p) {
  *p = '\0';
+ }
  puts(buf);
  }
-
  fclose(fp); /* closes fd too */
 }

+/* Gets tld from NAME to find right whois sever. */
+/* Called only from main for each NAME*/
+void whois_host(char* host, char *argv_host)
+{
+ FILE *fp;
+ char buf[1024];
+ char domain[WHOIS_DOMAIN_LEN];
+ char *str_token = strdup(argv_host);
+
+ if (strlen(host) >= 1) {
+ memset(&host[0], 0, WHOIS_HOST_LEN);
+ }
+ char *domain_token = strtok(str_token, ".");
+ while (domain_token != NULL) {
+ strncpy(domain, domain_token, WHOIS_DOMAIN_LEN);
+ domain_token = strtok(NULL, ".");
+ }
+ int fd = create_and_connect_stream_or_die(WHOIS_HOST, WHOIS_PORT);
+ fdprintf(fd, "%s\r\n", domain);
+
+ fp = xfdopen_for_read(fd);
+ while (fgets(buf, sizeof(buf), fp)) {
+ char *p = strpbrk(buf, "\r\n");
+ if (p) {
+ *p = '\0';
+ }
+ if (strstr(buf,"whois:") != NULL) {
+ char *whois_token = strtok(buf, " ");
+ whois_token = strtok(NULL, " ");
+ strncpy(host, whois_token, WHOIS_HOST_LEN);
+ }
+ }
+ fclose(fp);
+ free(str_token);
+}
+
 int whois_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int whois_main(int argc UNUSED_PARAM, char **argv)
 {
+
+ char *host = malloc(WHOIS_HOST_LEN);
  int port = 43;
- const char *host = "whois-servers.net";

  opt_complementary = "-1:p+";
  getopt32(argv, "h:p:", &host, &port);
-
  argv += optind;
- do {
- int fd = create_and_connect_stream_or_die(host, port);
- fdprintf(fd, "%s\r\n", *argv);
- pipe_out(fd);
+
+ if (strlen(host) < 1) {
+ do {
+ if (strlen(*argv) >= 67) {
+ dprintf(1, "Invalid request: %s\n", *argv);
+ return EXIT_FAILURE;
+ }
+ whois_host(host, *argv);
+ int fd = create_and_connect_stream_or_die(host, port);
+ fdprintf(fd, "%s\r\n", *argv);
+ pipe_out(fd);
+ }
+ while (*++argv);
+ free(host);
+ } else {
+ do {
+ int fd = create_and_connect_stream_or_die(host, port);
+ fdprintf(fd, "%s\r\n", *argv);
+ pipe_out(fd);
+ }
+ while (*++argv);
  }
- while (*++argv);

  return EXIT_SUCCESS;
 }

On 5 July 2016 at 13:28, Vito Mulè <[email protected]> wrote:

> On 5 July 2016 at 12:36, Bernhard Reutner-Fischer <[email protected]>
> wrote:
> On Tue, Jul 05, 2016 at 12:48:36PM +0200, Bernhard Reutner-Fischer wrote:
> > On July 5, 2016 12:26:07 PM GMT+02:00, "Vito Mulè" <[email protected]>
> wrote:
> >
> >
> > Care to send an updated patch, including bloat-o-meter output?
> Is this ok ?
> Thanks
>
>
>
> Signed-off-by: Vito Mule' <[email protected]>
>
> function                                             old     new   delta
> whois_main                                       133   286    +153
> whois_host                                         -       141    +141
>
> ------------------------------------------------------------------------------
> (add/remove: 1/0 grow/shrink: 1/0 up/down: 294/0)             Total: 294
> bytes
>
> ---
>  networking/whois.c | 57
> +++++++++++++++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 49 insertions(+), 8 deletions(-)
>
> diff --git a/networking/whois.c b/networking/whois.c
> index bf33033..71e0a1f 100644
> --- a/networking/whois.c
> +++ b/networking/whois.c
> @@ -3,6 +3,7 @@
>   * whois - tiny client for the whois directory service
>   *
>   * Copyright (c) 2011 Pere Orga <[email protected]>
> + * modified by Vito Mule' <[email protected]>
>   * Licensed under GPLv2 or later, see file LICENSE in this source tree.
>   */
>  /* TODO
> @@ -28,6 +29,9 @@
>
>  #include "libbb.h"
>
> +#define WHOIS_HOST_LEN  128
> +#define WHOIS_DOMAIN_LEN  32
> +
>  static void pipe_out(int fd)
>  {
>   FILE *fp;
> @@ -40,26 +43,63 @@ static void pipe_out(int fd)
>   *p = '\0';
>   puts(buf);
>   }
> -
>   fclose(fp); /* closes fd too */
>  }
>
> +/* Gets tld from NAME to create whois sever, e.g. tld.whois-servers.net
> . */
> +/* Called only from main for each NAME*/
> +void whois_host(char* host, char *argv_host, const char *unqualified_host)
> +{
> + char domain[WHOIS_DOMAIN_LEN];
> + char* token;
> + char *str_token = strdup(argv_host);
> +
> + if (strlen(host) >= 1) {
> + memset(&host[0], 0, WHOIS_HOST_LEN);
> + }
> + token = strtok(str_token, ".");
> + while (token != NULL) {
> + strncpy(domain, token, WHOIS_DOMAIN_LEN);
> + token = strtok(NULL, ".");
> + }
> + strncpy(host, domain, WHOIS_HOST_LEN);
> + strncat(host, unqualified_host, WHOIS_HOST_LEN);
> + free(str_token);
> +}
> +
>  int whois_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
>  int whois_main(int argc UNUSED_PARAM, char **argv)
>  {
> +
> + char *host = malloc(WHOIS_HOST_LEN);
>   int port = 43;
> - const char *host = "whois-servers.net";
> + const char *unqualified_host = ".whois-servers.net";
>
>   opt_complementary = "-1:p+";
>   getopt32(argv, "h:p:", &host, &port);
> -
>   argv += optind;
> - do {
> - int fd = create_and_connect_stream_or_die(host, port);
> - fdprintf(fd, "%s\r\n", *argv);
> - pipe_out(fd);
> +
> + if (strlen(host) < 1) {
> + do {
> + if (strlen(*argv) >= 67) {
> + dprintf(1, "Invalid request: %s\n", *argv);
> + return EXIT_FAILURE;
> + }
> + whois_host(host, *argv, unqualified_host);
> + int fd = create_and_connect_stream_or_die(host, port);
> + fdprintf(fd, "%s\r\n", *argv);
> + pipe_out(fd);
> + }
> + while (*++argv);
> + free(host);
> + } else {
> + do {
> + int fd = create_and_connect_stream_or_die(host, port);
> + fdprintf(fd, "%s\r\n", *argv);
> + pipe_out(fd);
> + }
> + while (*++argv);
>   }
> - while (*++argv);
>
>   return EXIT_SUCCESS;
>  }
>
> On 5 July 2016 at 12:40, Vito Mulè <[email protected]> wrote:
>
>> On 5 July 2016 at 12:36, Bernhard Reutner-Fischer <[email protected]>
>> wrote:
>> > On Tue, Jul 05, 2016 at 12:48:36PM +0200, Bernhard Reutner-Fischer
>> wrote:
>> > On July 5, 2016 12:26:07 PM GMT+02:00, "Vito Mulè" <[email protected]>
>> wrote:
>> >
>> >
>> > Care to send an updated patch, including bloat-o-meter output?
>>
>> How do I do that?
>> Thanks
>>
>> On 5 July 2016 at 12:36, Bernhard Reutner-Fischer <[email protected]>
>> wrote:
>>
>>> On Tue, Jul 05, 2016 at 12:48:36PM +0200, Bernhard Reutner-Fischer wrote:
>>> > On July 5, 2016 12:26:07 PM GMT+02:00, "Vito Mulè" <
>>> [email protected]> wrote:
>>> >
>>> > Please do not top-post.
>>> >
>>> > >Yep that would be even better, but at least this patch fixes a broken
>>> > >whois
>>> > >applet.
>>> > >The data is not taken from a random registrar:
>>> > >
>>> > >"The name tld.whois-servers.net is a CNAME to the appropriate
>>> > >whois-server.
>>> > >Somewhat unclear who actually maintains this but it seems pretty
>>> > >popular as
>>> > >it's very easy to use this with pretty much any whois client (and some
>>> > >clients default to using this service)."
>>> >
>>> > IIRC whois-servers.net belongs to Tucows. Iana-servers.net is the
>>> thing from godaddy etc, etc. See respective whois records..
>>> >
>>> > All of those are not authoritative and can go away any time or return
>>> stale or otherwise wrong data, fwiw.
>>>
>>> See e.g.:
>>> $ whois nic.ikano
>>> No whois server is known for this kind of object.
>>>
>>> versus the "proper":
>>>
>>> $ whois -h $(whois -h whois.iana.org ikano | awk '/^whois:/{print $2}')
>>> nic.ikano
>>>
>>> but either way.
>>> Care to send an updated patch, including bloat-o-meter output?
>>>
>>> TIA,
>>> >
>>> > HTH,
>>> > >
>>> > >TODO in the future as you suggested could be to query whois.iana.org
>>> > >for
>>> > >the whois server to then query for the name.
>>> > >
>>> > >On 5 July 2016 at 11:17, Bernhard Reutner-Fischer
>>> > ><[email protected]>
>>> > >wrote:
>>> > >
>>> > >> On Tue, Jul 05, 2016 at 10:47:07AM +0200, walter harms wrote:
>>> > >>
>>> > >> > please add a comment what whois_host() is supposed to do
>>> > >> >
>>> > >> >
>>> > >> > > +void whois_host(char* host, char *argv_host, const char
>>> > >> *unqualified_host)
>>> > >>
>>> > >> Apart from that, using the data from a random registrar is not
>>> > >reliable
>>> > >> (as you can see).
>>> > >>
>>> > >> AFAIU whois(1) is supposed to:
>>> > >>
>>> > >> 1) ask whois.iana.org for the TLD
>>> > >>    e.g. whois -h whois.iana.org wien
>>> > >> 2) use the "^whois:" server of that answer for the full domain
>>> > >>    e.g. whois -h whois.nic.wien ccc.wien
>>> > >>
>>> > >> HTH,
>>> > >> _______________________________________________
>>> > >> busybox mailing list
>>> > >> [email protected]
>>> > >> http://lists.busybox.net/mailman/listinfo/busybox
>>> > >>
>>> >
>>> >
>>>
>>
>>
>
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to