예제 #1
0
파일: popt_common.c 프로젝트: OPSF/uClinux
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);
}
예제 #2
0
static BOOL read_target_host(const char *mapfile, pstring targethost)
{
    XFILE *f;
    pstring buf;
    char *s, *space = buf;
    BOOL found = False;

    f = x_fopen(mapfile, O_RDONLY, 0);

    if (f == NULL) {
        DEBUG(0,("can't open IP map %s. Error %s\n",
                 mapfile, strerror(errno) ));
        return False;
    }

    DEBUG(10, ("Scanning mapfile [%s]\n", mapfile));

    while ((s=x_fgets(buf, sizeof(buf), f)) != NULL) {

        if ((strlen(buf) > 0) && (buf[strlen(buf)-1] == '\n'))
            buf[strlen(buf)-1] = '\0';

        DEBUG(10, ("Scanning line [%s]\n", buf));

        space = strchr_m(buf, ' ');

        if (space == NULL) {
            DEBUG(0, ("Ignoring invalid line %s\n", buf));
            continue;
        }

        *space = '\0';

        if (strncmp(client_addr(), buf, strlen(buf)) == 0) {
            found = True;
            break;
        }
    }

    x_fclose(f);

    if (!found)
        return False;

    space += 1;

    while (isspace(*space))
        space += 1;

    pstrcpy(targethost, space);
    return True;
}
예제 #3
0
static char *smb_readline_replacement(const char *prompt, void (*callback)(void),
				char **(completion_fn)(const char *text, int start, int end))
{
	char *line = NULL;
	int fd = x_fileno(x_stdin);
	char *ret;

	/* Prompt might be NULL in non-interactive mode. */
	if (prompt) {
		x_fprintf(x_stdout, "%s", prompt);
		x_fflush(x_stdout);
	}

	line = (char *)malloc(BUFSIZ);
	if (!line) {
		return NULL;
	}

	while (!smb_rl_done) {
		struct pollfd pfd;

		ZERO_STRUCT(pfd);
		pfd.fd = fd;
		pfd.events = POLLIN|POLLHUP;

		if (sys_poll_intr(&pfd, 1, 5000) == 1) {
			ret = x_fgets(line, BUFSIZ, x_stdin);
			if (ret == 0) {
				SAFE_FREE(line);
			}
			return ret;
		}
		if (callback) {
			callback();
		}
	}
	SAFE_FREE(line);
	return NULL;
}
예제 #4
0
static bool read_init_file(TALLOC_CTX *mem_ctx,
			   const char *servicename,
			   struct rcinit_file_information **service_info)
{
	struct rcinit_file_information *info = NULL;
	char *filepath = NULL;
	char str[1024];
	XFILE *f = NULL;
	char *p = NULL;

	info = talloc_zero(mem_ctx, struct rcinit_file_information);
	if (info == NULL) {
		return false;
	}

	/* attempt the file open */

	filepath = talloc_asprintf(mem_ctx,
				   "%s/%s/%s",
				   get_dyn_MODULESDIR(),
				   SVCCTL_SCRIPT_DIR,
				   servicename);
	if (filepath == NULL) {
		return false;
	}
	f = x_fopen( filepath, O_RDONLY, 0 );
	if (f == NULL) {
		DEBUG(0,("read_init_file: failed to open [%s]\n", filepath));
		return false;
	}

	while ((x_fgets(str, sizeof(str) - 1, f)) != NULL) {
		/* ignore everything that is not a full line
		   comment starting with a '#' */

		if (str[0] != '#') {
			continue;
		}

		/* Look for a line like '^#.*Description:' */

		p = strstr(str, "Description:");
		if (p != NULL) {
			char *desc;

			p += strlen( "Description:" ) + 1;
			if (p == NULL) {
				break;
			}

			desc = svcctl_cleanup_string(mem_ctx, p);
			if (desc != NULL) {
				info->description = talloc_strdup(info, desc);
			}
		}
	}

	x_fclose(f);

	if (info->description == NULL) {
		info->description = talloc_strdup(info,
						  "External Unix Service");
		if (info->description == NULL) {
			return false;
		}
	}

	*service_info = info;

	return true;
}