]> Pileus Git - ~andy/fetchmail/blobdiff - netrc.c
Initial revision
[~andy/fetchmail] / netrc.c
diff --git a/netrc.c b/netrc.c
index 7228e3372adc6da3f33e9ca13556ffe7726581b8..70f3361db6472a378a87a922b3d454e4762bcb84 100644 (file)
--- a/netrc.c
+++ b/netrc.c
@@ -23,6 +23,8 @@
 /* Normally defined in xmalloc.c */
 # define xmalloc malloc
 # define xrealloc realloc
+
+char *program_name = "netrc";
 #endif
 
 /* Maybe add NEWENTRY to the account information list, LIST.  NEWENTRY is
@@ -112,10 +114,12 @@ parse_netrc (file)
 
        /* If the line is empty... */
        if (!*p)
+       {
            if (last_token == tok_macdef)       /* end of macro */
                last_token = tok_nothing;
            else
                continue;                       /* otherwise ignore it */
+       }
 
        /* If we are defining macros, then skip parsing the line. */
        while (*p && last_token != tok_macdef)
@@ -289,20 +293,17 @@ parse_netrc (file)
 /* Return the netrc entry from LIST corresponding to HOST.  NULL is
    returned if no such entry exists. */
 netrc_entry *
-search_netrc (list, host)
+search_netrc (list, host, account)
      netrc_entry *list;
-     char *host;
+     char *host, *account;
 {
     /* Look for the HOST in LIST. */
     while (list)
     {
-       if (!list->host)
-           /* We hit the default entry. */
-           break;
-
-       else if (!strcmp (list->host, host))
-           /* We found a matching entry. */
-           break;
+       if (list->host && !strcmp(list->host, host))
+           if (!list->account || !strcmp(list->account, account))
+               /* We found a matching entry. */
+               break;
 
        list = list->next;
     }
@@ -324,18 +325,13 @@ main (argc, argv)
      char **argv;
 {
     struct stat sb;
-    char *program_name, *file, *target;
+    char *program_name, *file, *host, *account;
     netrc_entry *head, *a;
 
-    if (argc < 2)
-    {
-       fprintf (stderr, "Usage: %s NETRC [HOSTNAME]...\n", argv[0]);
-       exit (1);
-    }
-
     program_name = argv[0];
     file = argv[1];
-    target = argv[2];
+    host = argv[2];
+    account = argv[3];
 
     if (stat (file, &sb))
     {
@@ -351,32 +347,25 @@ main (argc, argv)
        exit (1);
     }
 
-    if (argc > 2)
+    if (host && account)
     {
        int i, status;
        status = 0;
-       for (i = 2; i < argc; i++)
-       {
-           /* Print out the host that we are checking for. */
-           fputs (argv[i], stdout);
 
-           a = search_netrc (head, argv[i]);
-           if (a)
+       printf("Host: %s, Account: %s\n", host, account);
+           
+       a = search_netrc (head, host, account);
+       if (a)
+       {
+           /* Print out the password (if any). */
+           if (a->password)
            {
-               /* Print out the account and password (if any). */
                fputc (' ', stdout);
-               fputs (a->account, stdout);
-               if (a->password)
-               {
-                   fputc (' ', stdout);
-                   fputs (a->password, stdout);
-               }
+               fputs (a->password, stdout);
            }
-           else
-               status = 1;
-
-           fputc ('\n', stdout);
        }
+       fputc ('\n', stdout);
+
        exit (status);
     }