~ubuntu-branches/ubuntu/saucy/curl/saucy-201307251546

« back to all changes in this revision

Viewing changes to lib/netrc.c

  • Committer: Bazaar Package Importer
  • Author(s): Ramakrishnan Muthukrishnan
  • Date: 2011-02-28 19:35:36 UTC
  • mto: (3.6.1 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: james.westby@ubuntu.com-20110228193536-p3a9jawxxofcsz7o
Tags: upstream-7.21.4
ImportĀ upstreamĀ versionĀ 7.21.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
/* The last #include file should be: */
51
51
#include "memdebug.h"
52
52
 
53
 
/* Debug this single source file with:
54
 
   'make netrc' then run './netrc'!
55
 
 
56
 
   Oh, make sure you have a .netrc file too ;-)
57
 
 */
58
 
 
59
53
/* Get user and password from .netrc when given a machine name */
60
54
 
61
 
enum {
 
55
enum host_lookup_state {
62
56
  NOTHING,
63
57
  HOSTFOUND,    /* the 'machine' keyword was found */
64
58
  HOSTCOMPLETE, /* the machine name following the keyword was found too */
67
61
  HOSTEND /* LAST enum */
68
62
};
69
63
 
70
 
/* make sure we have room for at least this size: */
71
 
#define LOGINSIZE 64
72
 
#define PASSWORDSIZE 64
73
 
 
74
 
/* returns -1 on failure, 0 if the host is found, 1 is the host isn't found */
75
64
int Curl_parsenetrc(const char *host,
76
65
                    char *login,
77
66
                    char *password,
83
72
  char *home = NULL;
84
73
  bool home_alloc = FALSE;
85
74
  bool netrc_alloc = FALSE;
86
 
  int state=NOTHING;
 
75
  enum host_lookup_state state=NOTHING;
87
76
 
88
77
  char state_login=0;      /* Found a login keyword */
89
78
  char state_password=0;   /* Found a password keyword */
210
199
            state_our_login = FALSE;
211
200
          }
212
201
          break;
 
202
        case HOSTCOMPLETE:
 
203
        case HOSTEND:
 
204
            /* Should not be reached. */
 
205
            DEBUGASSERT(0);
213
206
        } /* switch (state) */
214
207
 
215
208
        tok = strtok_r(NULL, " \t\n", &tok_buf);
226
219
 
227
220
  return retcode;
228
221
}
229
 
 
230
 
#ifdef _NETRC_DEBUG
231
 
int main(int argc, argv_item_t argv[])
232
 
{
233
 
  char login[64]="";
234
 
  char password[64]="";
235
 
 
236
 
  if(argc<2)
237
 
    return -1;
238
 
 
239
 
  if(0 == ParseNetrc(argv[1], login, password)) {
240
 
    printf("HOST: %s LOGIN: %s PASSWORD: %s\n",
241
 
           argv[1], login, password);
242
 
  }
243
 
}
244
 
 
245
 
#endif