ReactOS  0.4.12-dev-721-g03c3dd5
ruserpass.c File Reference
#include "precomp.h"
Include dependency graph for ruserpass.c:

Go to the source code of this file.

Classes

struct  toktab
 

Macros

#define MAXHOSTNAMELEN   64
 
#define DEFAULT   1
 
#define LOGIN   2
 
#define PASSWD   3
 
#define ACCOUNT   4
 
#define MACDEF   5
 
#define ID   10
 
#define MACH   11
 

Functions

struct utmp * getutmp ()
 
static int token (void)
 
int ruserpass (const char *host, char **aname, char **apass, char **aacct)
 

Variables

static char sccsid [] = "@(#)ruserpass.c 5.1 (Berkeley) 3/1/89"
 
static FILEcfile
 
static char tokval [100]
 
static struct toktab toktab []
 
charhostname
 

Macro Definition Documentation

◆ ACCOUNT

#define ACCOUNT   4

Definition at line 34 of file ruserpass.c.

◆ DEFAULT

#define DEFAULT   1

Definition at line 31 of file ruserpass.c.

◆ ID

#define ID   10

Definition at line 36 of file ruserpass.c.

◆ LOGIN

#define LOGIN   2

Definition at line 32 of file ruserpass.c.

◆ MACDEF

#define MACDEF   5

Definition at line 35 of file ruserpass.c.

◆ MACH

#define MACH   11

Definition at line 37 of file ruserpass.c.

◆ MAXHOSTNAMELEN

#define MAXHOSTNAMELEN   64

Definition at line 28 of file ruserpass.c.

◆ PASSWD

#define PASSWD   3

Definition at line 33 of file ruserpass.c.

Function Documentation

◆ getutmp()

struct utmp* getutmp ( )

◆ ruserpass()

int ruserpass ( const char host,
char **  aname,
char **  apass,
char **  aacct 
)

Definition at line 58 of file ruserpass.c.

59 {
60  const char *hdir, *mydomain;
61  char buf[BUFSIZ], *tmp;
62  char myname[MAXHOSTNAMELEN];
63  int t, i, c, usedefault = 0;
64  struct stat stb;
65 
66  hdir = getenv("HOME");
67  if (hdir == NULL)
68  hdir = ".";
69  (void) sprintf(buf, "%s/.netrc", hdir);
70  cfile = fopen(buf, "r");
71  if (cfile == NULL) {
72  if (errno != ENOENT)
73  perror(buf);
74  return(0);
75  }
76 
77 
78  if (gethostname(myname, sizeof(myname)) < 0)
79  myname[0] = '\0';
80  if ((mydomain = index(myname, '.')) == NULL)
81  mydomain = "";
82 next:
83  while ((t = token())) switch(t) {
84 
85  case DEFAULT:
86  usedefault = 1;
87  /* FALL THROUGH */
88 
89  case MACH:
90  if (!usedefault) {
91  if (token() != ID)
92  continue;
93  /*
94  * Allow match either for user's input host name
95  * or official hostname. Also allow match of
96  * incompletely-specified host in local domain.
97  */
98  if (strcasecmp(host, tokval) == 0)
99  goto match;
100  if (strcasecmp(hostname, tokval) == 0)
101  goto match;
102  if ((tmp = index(hostname, '.')) != NULL &&
103  strcasecmp(tmp, mydomain) == 0 &&
104  strncasecmp(hostname, tokval, tmp - hostname) == 0 &&
105  tokval[tmp - hostname] == '\0')
106  goto match;
107  if ((tmp = index(host, '.')) != NULL &&
108  strcasecmp(tmp, mydomain) == 0 &&
109  strncasecmp(host, tokval, tmp - host) == 0 &&
110  tokval[tmp - host] == '\0')
111  goto match;
112  continue;
113  }
114  match:
115  while ((t = token()) && t != MACH && t != DEFAULT) switch(t) {
116 
117  case LOGIN:
118  if (token()) {
119  if (*aname == 0) {
120  *aname = malloc((unsigned) strlen(tokval) + 1);
121  (void) strcpy(*aname, tokval);
122  } else {
123  if (strcmp(*aname, tokval))
124  goto next;
125  }
126  }
127  break;
128  case PASSWD:
129  if (strcmp(*aname, "anonymous") &&
130  fstat(fileno(cfile), &stb) >= 0 &&
131  (stb.st_mode & 077) != 0) {
132  fprintf(stderr, "Error - .netrc file not correct mode.\n");
133  fprintf(stderr, "Remove password or correct mode.\n");
134  goto bad;
135  }
136  if (token() && *apass == 0) {
137  *apass = malloc((unsigned) strlen(tokval) + 1);
138  (void) strcpy(*apass, tokval);
139  }
140  break;
141  case ACCOUNT:
142  if (fstat(fileno(cfile), &stb) >= 0
143  && (stb.st_mode & 077) != 0) {
144  fprintf(stderr, "Error - .netrc file not correct mode.\n");
145  fprintf(stderr, "Remove account or correct mode.\n");
146  goto bad;
147  }
148  if (token() && *aacct == 0) {
149  *aacct = malloc((unsigned) strlen(tokval) + 1);
150  (void) strcpy(*aacct, tokval);
151  }
152  break;
153  case MACDEF:
154  if (proxy) {
155  (void) fclose(cfile);
156  return(0);
157  }
158  while ((c=getc(cfile)) != EOF && (c == ' ' || c == '\t'));
159  if (c == EOF || c == '\n') {
160  printf("Missing macdef name argument.\n");
161  goto bad;
162  }
163  if (macnum == 16) {
164  printf("Limit of 16 macros have already been defined\n");
165  goto bad;
166  }
167  tmp = macros[macnum].mac_name;
168  *tmp++ = c;
169  for (i=0; i < 8 && (c=getc(cfile)) != EOF &&
170  !isspace(c); ++i) {
171  *tmp++ = c;
172  }
173  if (c == EOF) {
174  printf("Macro definition missing null line terminator.\n");
175  goto bad;
176  }
177  *tmp = '\0';
178  if (c != '\n') {
179  while ((c=getc(cfile)) != EOF && c != '\n');
180  }
181  if (c == EOF) {
182  printf("Macro definition missing null line terminator.\n");
183  goto bad;
184  }
185  if (macnum == 0) {
186  macros[macnum].mac_start = macbuf;
187  }
188  else {
189  macros[macnum].mac_start = macros[macnum-1].mac_end + 1;
190  }
191  tmp = macros[macnum].mac_start;
192  while (tmp != macbuf + 4096) {
193  if ((c=getc(cfile)) == EOF) {
194  printf("Macro definition missing null line terminator.\n");
195  goto bad;
196  }
197  *tmp = c;
198  if (*tmp == '\n') {
199  if (*(tmp-1) == '\0') {
200  macros[macnum++].mac_end = tmp - 1;
201  break;
202  }
203  *tmp = '\0';
204  }
205  tmp++;
206  }
207  if (tmp == macbuf + 4096) {
208  printf("4K macro buffer exceeded\n");
209  goto bad;
210  }
211  break;
212  default:
213  fprintf(stderr, "Unknown .netrc keyword %s\n", tokval);
214  break;
215  }
216  goto done;
217  }
218 done:
219  (void) fclose(cfile);
220  return(0);
221 bad:
222  (void) fclose(cfile);
223  return(-1);
224 }
#define isspace(c)
Definition: acclib.h:69
int proxy
Definition: main.c:67
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:47
#define strcasecmp
Definition: fake.h:9
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static char tokval[100]
Definition: ruserpass.c:39
char * host
Definition: whois.c:55
GLdouble GLdouble t
Definition: gl.h:2047
_Check_return_ _CRTIMP int __cdecl getc(_Inout_ FILE *_File)
#define BUFSIZ
Definition: nsplookup.c:26
int errno
#define LOGIN
Definition: ruserpass.c:32
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define DEFAULT
Definition: ruserpass.c:31
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
INT WSAAPI gethostname(OUT char FAR *name, IN INT namelen)
Definition: getxbyxx.c:397
#define strncasecmp
Definition: fake.h:10
smooth NULL
Definition: ftsmooth.c:416
#define PASSWD
Definition: ruserpass.c:33
struct match match
Definition: match.c:33
#define ACCOUNT
Definition: ruserpass.c:34
char * hostname
Definition: ftp.c:88
_Check_return_ _CRTIMP int __cdecl fileno(_In_ FILE *_File)
const GLubyte * c
Definition: glext.h:8905
#define index(s, c)
Definition: various.h:29
Definition: stat.h:55
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define ID
Definition: ruserpass.c:36
static FILE * cfile
Definition: ruserpass.c:25
#define MACH
Definition: ruserpass.c:37
static unsigned __int64 next
Definition: rand_nt.c:6
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
struct macel macros[16]
Definition: main.c:109
Definition: arc.h:46
static int token(void)
Definition: ruserpass.c:226
#define EOF
Definition: stdio.h:24
#define MACDEF
Definition: ruserpass.c:35
int macnum
Definition: main.c:108
_CRTIMP int __cdecl fstat(int _Desc, struct stat *_Stat)
Definition: stat.h:341
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define c
Definition: ke_i.h:80
FILE * stderr
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define malloc
Definition: debug_ros.c:4
char macbuf[4096]
Definition: main.c:110
#define MAXHOSTNAMELEN
Definition: ruserpass.c:28
#define printf
Definition: config.h:203

Referenced by login().

◆ token()

static int token ( void  )
static

Definition at line 226 of file ruserpass.c.

227 {
228  char *cp;
229  int c;
230  struct toktab *t;
231 
232  if (feof(cfile))
233  return (0);
234  while ((c = getc(cfile)) != EOF &&
235  (c == '\r' || c == '\n' || c == '\t' || c == ' ' || c == ','))
236  continue;
237  if (c == EOF)
238  return (0);
239  cp = tokval;
240  if (c == '"') {
241  while ((c = getc(cfile)) != EOF && c != '"') {
242  if (c == '\\')
243  c = getc(cfile);
244  *cp++ = c;
245  }
246  } else {
247  *cp++ = c;
248  while ((c = getc(cfile)) != EOF
249  && c != '\n' && c != '\t' && c != ' ' && c != ',' && c != '\r') {
250  if (c == '\\')
251  c = getc(cfile);
252  *cp++ = c;
253  }
254  }
255  *cp = 0;
256  if (tokval[0] == 0)
257  return (0);
258  for (t = toktab; t->tokstr; t++)
259  if (!strcmp(t->tokstr, tokval))
260  return (t->tval);
261  return (ID);
262 }
const char * tokstr
Definition: ruserpass.c:42
static char tokval[100]
Definition: ruserpass.c:39
GLdouble GLdouble t
Definition: gl.h:2047
_Check_return_ _CRTIMP int __cdecl getc(_Inout_ FILE *_File)
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
const GLubyte * c
Definition: glext.h:8905
#define ID
Definition: ruserpass.c:36
static FILE * cfile
Definition: ruserpass.c:25
#define EOF
Definition: stdio.h:24
POINT cp
Definition: magnifier.c:60
#define c
Definition: ke_i.h:80
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469

Referenced by ruserpass().

Variable Documentation

◆ cfile

FILE* cfile
static

Definition at line 25 of file ruserpass.c.

Referenced by ruserpass(), test_LZRead(), and token().

◆ hostname

char* hostname

Definition at line 88 of file ftp.c.

Referenced by getreply(), hookup(), pswitch(), and ruserpass().

◆ sccsid

char sccsid[] = "@(#)ruserpass.c 5.1 (Berkeley) 3/1/89"
static

Definition at line 21 of file ruserpass.c.

◆ toktab

struct toktab toktab[]
static
Initial value:
= {
{"default", DEFAULT},
{"login", LOGIN},
{"password", PASSWD},
{"passwd", PASSWD},
{"account", ACCOUNT},
{"machine", MACH},
{"macdef", MACDEF},
{0, 0}
}
#define LOGIN
Definition: ruserpass.c:32
#define DEFAULT
Definition: ruserpass.c:31
#define PASSWD
Definition: ruserpass.c:33
#define ACCOUNT
Definition: ruserpass.c:34
#define MACH
Definition: ruserpass.c:37
#define MACDEF
Definition: ruserpass.c:35

◆ tokval

char tokval[100]
static

Definition at line 39 of file ruserpass.c.

Referenced by ruserpass(), and token().