~ubuntu-branches/ubuntu/dapper/curl/dapper-security

« back to all changes in this revision

Viewing changes to lib/netrc.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-03-23 18:41:29 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050323184129-le70d05a0hk5w62j
Tags: 7.12.3-2ubuntu3
Fix the version numbers internal to debian/rules.  Closes; #8088

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
 *                                  _   _ ____  _     
3
 
 *  Project                     ___| | | |  _ \| |    
4
 
 *                             / __| | | | |_) | |    
5
 
 *                            | (__| |_| |  _ <| |___ 
 
2
 *                                  _   _ ____  _
 
3
 *  Project                     ___| | | |  _ \| |
 
4
 *                             / __| | | | |_) | |
 
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
8
 * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
12
12
 * are also available at http://curl.haxx.se/docs/copyright.html.
13
 
 * 
 
13
 *
14
14
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
15
 * copies of the Software, and permit persons to whom the Software is
16
16
 * furnished to do so, under the terms of the COPYING file.
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: netrc.c,v 1.31 2004/03/23 15:30:12 bagder Exp $
 
21
 * $Id: netrc.c,v 1.33 2004/10/06 07:50:18 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
45
45
 
46
46
#include "strequal.h"
47
47
#include "strtok.h"
 
48
#include "memory.h"
48
49
 
49
50
#define _MPRINTF_REPLACE /* use our functions only */
50
51
#include <curl/mprintf.h>
51
52
 
52
53
/* The last #include file should be: */
53
 
#ifdef CURLDEBUG
54
54
#include "memdebug.h"
55
 
#endif
56
55
 
57
56
/* Debug this single source file with:
58
57
   'make netrc' then run './netrc'!
84
83
  FILE *file;
85
84
  int retcode=1;
86
85
  int specific_login = (login[0] != 0);
87
 
  char *home = NULL; 
 
86
  char *home = NULL;
88
87
  bool home_alloc = FALSE;
89
88
  bool netrc_alloc = FALSE;
90
89
  int state=NOTHING;
120
119
      struct passwd *pw;
121
120
      pw= getpwuid(geteuid());
122
121
      if (pw) {
123
 
#ifdef  VMS
 
122
#ifdef  VMS
124
123
        home = decc$translate_vms(pw->pw_dir);
125
124
#else
126
125
        home = pw->pw_dir;
157
156
          break;
158
157
        }
159
158
 
160
 
        switch(state) {
161
 
        case NOTHING:
162
 
          if(strequal("machine", tok)) {
163
 
            /* the next tok is the machine name, this is in itself the
164
 
               delimiter that starts the stuff entered for this machine,
165
 
               after this we need to search for 'login' and
166
 
               'password'. */
167
 
            state=HOSTFOUND;
168
 
          }
169
 
          break;
170
 
        case HOSTFOUND:
171
 
          if(strequal(host, tok)) {
172
 
            /* and yes, this is our host! */
173
 
            state=HOSTVALID;
 
159
        switch(state) {
 
160
        case NOTHING:
 
161
          if(strequal("machine", tok)) {
 
162
            /* the next tok is the machine name, this is in itself the
 
163
               delimiter that starts the stuff entered for this machine,
 
164
               after this we need to search for 'login' and
 
165
               'password'. */
 
166
            state=HOSTFOUND;
 
167
          }
 
168
          break;
 
169
        case HOSTFOUND:
 
170
          if(strequal(host, tok)) {
 
171
            /* and yes, this is our host! */
 
172
            state=HOSTVALID;
174
173
#ifdef _NETRC_DEBUG
175
 
            printf("HOST: %s\n", tok);
 
174
            printf("HOST: %s\n", tok);
176
175
#endif
177
 
            retcode=0; /* we did find our host */
178
 
          }
179
 
          else
180
 
            /* not our host */
181
 
            state=NOTHING;
182
 
          break;
183
 
        case HOSTVALID:
184
 
          /* we are now parsing sub-keywords concerning "our" host */
185
 
          if(state_login) {
 
176
            retcode=0; /* we did find our host */
 
177
          }
 
178
          else
 
179
            /* not our host */
 
180
            state=NOTHING;
 
181
          break;
 
182
        case HOSTVALID:
 
183
          /* we are now parsing sub-keywords concerning "our" host */
 
184
          if(state_login) {
186
185
            if (specific_login) {
187
186
              state_our_login = strequal(login, tok);
188
187
            }
189
188
            else {
190
189
              strncpy(login, tok, LOGINSIZE-1);
191
190
#ifdef _NETRC_DEBUG
192
 
              printf("LOGIN: %s\n", login);
 
191
              printf("LOGIN: %s\n", login);
193
192
#endif
194
193
            }
195
 
            state_login=0;
196
 
          }
197
 
          else if(state_password) {
 
194
            state_login=0;
 
195
          }
 
196
          else if(state_password) {
198
197
            if (state_our_login || !specific_login) {
199
198
              strncpy(password, tok, PASSWORDSIZE-1);
200
199
#ifdef _NETRC_DEBUG
201
200
              printf("PASSWORD: %s\n", password);
202
201
#endif
203
202
            }
204
 
            state_password=0;
205
 
          }
206
 
          else if(strequal("login", tok))
207
 
            state_login=1;
208
 
          else if(strequal("password", tok))
209
 
            state_password=1;
210
 
          else if(strequal("machine", tok)) {
211
 
            /* ok, there's machine here go => */
212
 
            state = HOSTFOUND;
 
203
            state_password=0;
 
204
          }
 
205
          else if(strequal("login", tok))
 
206
            state_login=1;
 
207
          else if(strequal("password", tok))
 
208
            state_password=1;
 
209
          else if(strequal("machine", tok)) {
 
210
            /* ok, there's machine here go => */
 
211
            state = HOSTFOUND;
213
212
            state_our_login = FALSE;
214
 
          }
215
 
          break;
216
 
        } /* switch (state) */
 
213
          }
 
214
          break;
 
215
        } /* switch (state) */
217
216
 
218
 
        tok = strtok_r(NULL, " \t\n", &tok_buf);
 
217
        tok = strtok_r(NULL, " \t\n", &tok_buf);
219
218
      } /* while (tok) */
220
219
    } /* while fgets() */
221
220
 
241
240
 
242
241
  if(0 == ParseNetrc(argv[1], login, password)) {
243
242
    printf("HOST: %s LOGIN: %s PASSWORD: %s\n",
244
 
           argv[1], login, password);
 
243
           argv[1], login, password);
245
244
  }
246
245
}
247
246