Exemple #1
0
static void get_credentials_file(const char *file, struct user_auth_info *info) 
{
	XFILE *auth;
	fstring buf;
	uint16 len = 0;
	char *ptr, *val, *param;

	if ((auth=x_fopen(file, O_RDONLY, 0)) == NULL)
	{
		/* fail if we can't open the credentials file */
		d_printf("ERROR: Unable to open credentials file!\n");
		exit(-1);
	}

	while (!x_feof(auth))
	{
		/* get a line from the file */
		if (!x_fgets(buf, sizeof(buf), auth))
			continue;
		len = strlen(buf);

		if ((len) && (buf[len-1]=='\n'))
		{
			buf[len-1] = '\0';
			len--;
		}
		if (len == 0)
			continue;

		/* break up the line into parameter & value.
		 * will need to eat a little whitespace possibly */
		param = buf;
		if (!(ptr = strchr_m (buf, '=')))
			continue;

		val = ptr+1;
		*ptr = '\0';

		/* eat leading white space */
		while ((*val!='\0') && ((*val==' ') || (*val=='\t')))
			val++;

		if (strwicmp("password", param) == 0)
		{
			pstrcpy(info->password, val);
			info->got_pass = True;
		}
		else if (strwicmp("username", param) == 0)
			pstrcpy(info->username, val);
		else if (strwicmp("domain", param) == 0)
			set_global_myworkgroup(val);
		memset(buf, 0, sizeof(buf));
	}
	x_fclose(auth);
}
static void complete_sync(struct sync_record *s)
{
	XFILE *f;
	char *server;
	char *type_str;
	unsigned type;
	char *comment;
	char line[1024];
	const char *ptr;
	int count=0;

	f = x_fopen(s->fname,O_RDONLY, 0);

	if (!f)
		return;

	while (!x_feof(f)) {
		TALLOC_CTX *frame = NULL;

		if (!fgets_slash(line,sizeof(line),f))
			continue;

		ptr = line;

		frame = talloc_stackframe();
		if (!next_token_talloc(frame,&ptr,&server,NULL) ||
		    !next_token_talloc(frame,&ptr,&type_str,NULL) ||
		    !next_token_talloc(frame,&ptr,&comment,NULL)) {
			TALLOC_FREE(frame);
			continue;
		}

		sscanf(type_str, "%X", &type);

		complete_one(s, server, type, comment);

		count++;
		TALLOC_FREE(frame);
	}
	x_fclose(f);

	unlink(s->fname);

	DEBUG(2,("sync with %s(%s) for workgroup %s completed (%d records)\n",
		 s->server, inet_ntoa(s->ip), s->workgroup, count));
}
Exemple #3
0
bool getlmhostsent(TALLOC_CTX *ctx, XFILE *fp, char **pp_name, int *name_type,
		struct sockaddr_storage *pss)
{
	char line[1024];

	*pp_name = NULL;

	while(!x_feof(fp) && !x_ferror(fp)) {
		char *ip = NULL;
		char *flags = NULL;
		char *extra = NULL;
		char *name = NULL;
		const char *ptr;
		char *ptr1 = NULL;
		int count = 0;

		*name_type = -1;

		if (!fgets_slash(line,sizeof(line),fp)) {
			continue;
		}

		if (*line == '#') {
			continue;
		}

		ptr = line;

		if (next_token_talloc(ctx, &ptr, &ip, NULL))
			++count;
		if (next_token_talloc(ctx, &ptr, &name, NULL))
			++count;
		if (next_token_talloc(ctx, &ptr, &flags, NULL))
			++count;
		if (next_token_talloc(ctx, &ptr, &extra, NULL))
			++count;

		if (count <= 0)
			continue;

		if (count > 0 && count < 2) {
			DEBUG(0,("getlmhostsent: Ill formed hosts line [%s]\n",
						line));
			continue;
		}

		if (count >= 4) {
			DEBUG(0,("getlmhostsent: too many columns "
				"in lmhosts file (obsolete syntax)\n"));
			continue;
		}

		if (!flags) {
			flags = talloc_strdup(ctx, "");
			if (!flags) {
				continue;
			}
		}

		DEBUG(4, ("getlmhostsent: lmhost entry: %s %s %s\n",
					ip, name, flags));

		if (strchr_m(flags,'G') || strchr_m(flags,'S')) {
			DEBUG(0,("getlmhostsent: group flag "
				"in lmhosts ignored (obsolete)\n"));
			continue;
		}

		if (!interpret_string_addr(pss, ip, AI_NUMERICHOST)) {
			DEBUG(0,("getlmhostsent: invalid address "
				"%s.\n", ip));
		}

		/* Extra feature. If the name ends in '#XX',
		 * where XX is a hex number, then only add that name type. */
		if((ptr1 = strchr_m(name, '#')) != NULL) {
			char *endptr;
      			ptr1++;

			*name_type = (int)strtol(ptr1, &endptr, 16);
			if(!*ptr1 || (endptr == ptr1)) {
				DEBUG(0,("getlmhostsent: invalid name "
					"%s containing '#'.\n", name));
				continue;
			}

			*(--ptr1) = '\0'; /* Truncate at the '#' */
		}

		*pp_name = talloc_strdup(ctx, name);
		if (!*pp_name) {
			return false;
		}
		return true;
	}

	return false;
}
Exemple #4
0
/**
read a line from a file with possible \ continuation chars.
Blanks at the start or end of a line are stripped.
The string will be allocated if s2 is NULL
**/
_PUBLIC_ char *fgets_slash(char *s2,int maxlen,XFILE *f)
{
  char *s=s2;
  int len = 0;
  int c;
  bool start_of_line = true;

  if (x_feof(f))
    return(NULL);

  if (maxlen <2) return(NULL);

  if (!s2)
    {
      maxlen = MIN(maxlen,8);
      s = (char *)malloc(maxlen);
    }

  if (!s) return(NULL);

  *s = 0;

  while (len < maxlen-1)
    {
      c = x_getc(f);
      switch (c)
	{
	case '\r':
	  break;
	case '\n':
	  while (len > 0 && s[len-1] == ' ')
	    {
	      s[--len] = 0;
	    }
	  if (len > 0 && s[len-1] == '\\')
	    {
	      s[--len] = 0;
	      start_of_line = true;
	      break;
	    }
	  return(s);
	case EOF:
	  if (len <= 0 && !s2)
	    SAFE_FREE(s);
	  return(len>0?s:NULL);
	case ' ':
	  if (start_of_line)
	    break;
	  /* fall through */
	default:
	  start_of_line = false;
	  s[len++] = c;
	  s[len] = 0;
	}
      if (!s2 && len > maxlen-3)
	{
	  char *t;

	  maxlen *= 2;
	  t = realloc_p(s, char, maxlen);
	  if (!t) {
	    DEBUG(0,("fgets_slash: failed to expand buffer!\n"));
	    SAFE_FREE(s);
	    return(NULL);
	  } else s = t;
	}
    }
Exemple #5
0
char *fgets_slash(char *s2,int maxlen,XFILE *f)
{
    char *s=s2;
    int len = 0;
    int c;
    BOOL start_of_line = True;

    if (x_feof(f)) {
        return(NULL);
    }

    if (maxlen <2) {
        return(NULL);
    }

    if (!s2) {
        maxlen = MIN(maxlen,8);
        s = (char *)SMB_MALLOC(maxlen);
    }

    if (!s) {
        return(NULL);
    }

    *s = 0;

    while (len < maxlen-1) {
        c = x_getc(f);
        switch (c) {
        case '\r':
            break;
        case '\n':
            while (len > 0 && s[len-1] == ' ') {
                s[--len] = 0;
            }
            if (len > 0 && s[len-1] == '\\') {
                s[--len] = 0;
                start_of_line = True;
                break;
            }
            return(s);
        case EOF:
            if (len <= 0 && !s2)  {
                SAFE_FREE(s);
            }
            return(len>0?s:NULL);
        case ' ':
            if (start_of_line) {
                break;
            }
        default:
            start_of_line = False;
            s[len++] = c;
            s[len] = 0;
        }

        if (!s2 && len > maxlen-3) {
            maxlen *= 2;
            s = (char *)SMB_REALLOC(s,maxlen);
            if (!s) {
                DEBUG(0,("fgets_slash: failed to expand buffer!\n"));
                return(NULL);
            }
        }
    }
    return(s);
}