Ejemplo n.º 1
0
Archivo: cwd.c Proyecto: NieHao/R7000
int bftpd_cwd_chdir(char *dir)
{
	/* Foxconn added start pling 10/08/2012 */
	char root_dir[] = "/shares/%s";
	char convert_dir[1024];
	/* Foxconn added end pling 10/08/2012 */

    if (strncmp(dir,"/shares/shares",strlen("/shares/shares"))==0)
    {//jenny
        if (chdir(dir))
        {
            dir = dir+strlen("/shares");
        }
    }
	char *tmp = bftpd_cwd_mappath(dir);

	/* Foxconn added start pling 10/08/2012 */
	/* Handle ReadyShare Cloud connections specially */
	if (readyshareCloud_conn)
	{
		if (strncmp(tmp, "/shares", 7))
		{
			free(tmp);
			sprintf(convert_dir, root_dir, dir);
			tmp = bftpd_cwd_mappath(convert_dir);
		}
	}
	/* Foxconn added end pling 10/08/2012 */

	/* Foxconn added start pling 05/14/2009 */
	/* Sanity check, don't allow user to get outside of the /shares  */
	if (strlen(tmp) == 0 || strcmp(tmp, "/") == 0) {
		free(tmp);
		errno = EACCES;
		return -1;
	}
	/* Foxconn added end pling 05/14/2009 */

	/* Foxconn added start pling 09/02/2012 */
	/* WNDR4500v2 IR45/46/47, don't allow user to access outside /shares */
	if (strncmp(tmp, "/shares", 7) != 0) {
		free(tmp);
		bftpd_log("Block cwd to '%s'\n", tmp);
		errno = EACCES;
		return -1;
	}
	/* Foxconn added end pling 09/02/2012 */

	if (chdir(tmp)) {
		free(tmp);
		return errno;
	}
	cwd = realloc(cwd, strlen(tmp) + 1);
	strcpy(cwd, tmp);
	new_umask();
	free(tmp);
	return 0;
}
Ejemplo n.º 2
0
int bftpd_login(char *password)
{
#if 0	// brcm 
    char str[256];
	char *foo;
	int maxusers;
#endif //brcm
//printf("In bftpd_login password=%s, user=%s\n", password, user); // brcm
	if (!getpwnam(user)) {
        control_printf(SL_FAILURE, "421 Login incorrect.");
		return 1;
    }
    // brcm add local/remote login check
    if ((glbAccessMode == CLI_ACCESS_LOCAL && (strcmp(user, "user") && strcmp(user, "root"))) ||
        (glbAccessMode == CLI_ACCESS_REMOTE && strcmp(user, "support")))
    {
        control_printf(SL_FAILURE, "421 Login incorrect.");
	    return 1;
    }
#if 0 //brcm
	if (strncasecmp(foo = config_getoption("DENY_LOGIN"), "no", 2)) {
		if (foo[0] != '\0') {
			if (strncasecmp(foo, "yes", 3))
				control_printf(SL_FAILURE, "421-Server disabled.\r\n421 Reason: %s", foo);
			else
				control_printf(SL_FAILURE, "421 Login incorrect.");
			bftpd_log("Login as user '%s' failed: Server disabled.\n", user);
			exit(0);
		}
	}
	maxusers = strtoul(config_getoption("USERLIMIT_GLOBAL"), NULL, 10);
	if ((maxusers) && (maxusers == bftpdutmp_usercount("*"))) {
		control_printf(SL_FAILURE, "421 There are already %i users logged in.", maxusers);
		exit(0);
	}
	maxusers = strtoul(config_getoption("USERLIMIT_SINGLEUSER"), NULL, 10);
	if ((maxusers) && (maxusers == bftpdutmp_usercount(user))) {
		control_printf(SL_FAILURE, "421 User %s is already logged in %i times.", user, maxusers);
		exit(0);
	}
#endif //brcm

    if(checkuser() || checkshell()) {
		control_printf(SL_FAILURE, "421 Login incorrect.");
		exit(0);
	}
	if (checkpass(password))
		return 1;
#if 0 //brcm
	if (strcasecmp((char *) config_getoption("RATIO"), "none")) {
		sscanf((char *) config_getoption("RATIO"), "%i/%i",
			   &ratio_send, &ratio_recv);
	}
	strcpy(str, config_getoption("ROOTDIR"));
	if (!str[0])
		strcpy(str, "%h");
	replace(str, "%u", userinfo.pw_name);
	replace(str, "%h", userinfo.pw_dir);
	if (!strcasecmp(config_getoption("RESOLVE_UIDS"), "yes")) {
		passwdfile = fopen("/etc/passwd", "r");
		groupfile = fopen("/etc/group", "r");
	}
#endif //brcm
	setgid(userinfo.pw_gid);

	initgroups(userinfo.pw_name, userinfo.pw_gid);
#if 0 //brcm
	if (strcasecmp(config_getoption("DO_CHROOT"), "no")) {
		if (chroot(str)) {
			control_printf(SL_FAILURE, "421 Unable to change root directory.\r\n%s.",
					strerror(errno));
			exit(0);
		}
		if (bftpd_setuid(userinfo.pw_uid)) {
			control_printf(SL_FAILURE, "421 Unable to change uid.");
			exit(0);
		}
		if (chdir("/")) {
			control_printf(SL_FAILURE, "421 Unable to change working directory.\r\n%s.",
					 strerror(errno));
			exit(0);
		}
	} else {
		if (bftpd_setuid(userinfo.pw_uid)) {
			control_printf(SL_FAILURE, "421 Unable to change uid.");
			exit(0);
		}
		if (chdir(str)) {
			control_printf(SL_FAILURE, "230 Couldn't change cwd to '%s': %s.", str,
					 strerror(errno));
			chdir("/");
		}
	}
    new_umask();
	print_file(230, config_getoption("MOTD_USER"));
#endif //brcm
	
    control_printf(SL_SUCCESS, "230 User logged in.");

#ifdef HAVE_UTMP_H
	bftpd_logwtmp(1);
#endif
#if 0 //brcm
    bftpdutmp_log(1);
	bftpd_log("Successfully logged in as user '%s'.\n", user);

    if (config_getoption("AUTO_CHDIR")[0])
        chdir(config_getoption("AUTO_CHDIR"));
#endif //brcm        
	state = STATE_AUTHENTICATED;
//brcm	bftpd_cwd_init();

	return 0;
}