Пример #1
0
int main(int argc, char *argv[]){
	disk_info_t *disk_info, *disk_list;
	partition_info_t *partition_info;
	char buf[PATH_MAX];

	usb_dbg("%d: Using myself to get information:\n", VERSION);

	if(argc == 3){
		get_mount_path("sdb1", buf, PATH_MAX);
		printf("buf=%s.\n", buf);
	}
	else if(argc == 2){
		if(is_disk_name(argv[1])){ // Disk
			usb_dbg("%d: Get disk(%s)'s information:\n", VERSION, argv[1]);

			create_disk(argv[1], &disk_info);

			print_disk(disk_info);

			free_disk_data(&disk_info);
		}
		else{
			usb_dbg("%d: Get partition(%s)'s information:\n", VERSION, argv[1]);

			create_partition(argv[1], &partition_info);

			print_partition(partition_info);

			free_partition_data(&partition_info);
		}
	}
	else{
		usb_dbg("%d: Get all Disk information:\n", VERSION);

		disk_list = read_disk_data();

		print_disks(disk_list);

		free_disk_data(&disk_list);
	}

	return 0;
}
Пример #2
0
int main(int argc, char *argv[]) {
	disk_info_t *follow_disk, *disks_info = read_disk_data();
	partition_info_t *follow_partition;
	
	for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
		csprintf("	      tag: %s.\n", follow_disk->tag);
		csprintf("	   vendor: %s.\n", follow_disk->vendor);
		csprintf("	    model: %s.\n", follow_disk->model);
		csprintf("	   device: %s.\n", follow_disk->device);
		csprintf("	    major: %u.\n", follow_disk->major);
		csprintf("	    minor: %u.\n", follow_disk->minor);
		csprintf("   mounted_number: %u.\n", follow_disk->mounted_number);
		csprintf("     device_order: %u.\n", follow_disk->device_order);
		csprintf("size_in_kilobytes: %llu.\n", follow_disk->size_in_kilobytes);
		if (follow_disk->partitions == NULL) {
			csprintf("\n");
			continue;
		}
		
		for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
			csprintf("     Partition %u:\n", follow_partition->partition_number);
			csprintf("parent disk's tag: %s.\n", follow_partition->disk->tag);
			csprintf("	   device: %s.\n", follow_partition->device);
			csprintf("      mount_point: %s.\n", follow_partition->mount_point);
			csprintf("      file_system: %s.\n", follow_partition->file_system);
			csprintf("size_in_kilobytes: %llu.\n", follow_partition->size_in_kilobytes);
			csprintf("   used_kilobytes: %llu.\n", follow_partition->used_kilobytes);
		}
		
		csprintf("\n");
	}//*/
	
	free_disk_data(&disks_info);
	
	return 0;
}
Пример #3
0
int main(int argc, char *argv[]) {
	FILE *fp;
	int n=0;
	char *p_computer_name = NULL;
	disk_info_t *follow_disk, *disks_info = NULL;
	partition_info_t *follow_partition;
	char *mount_folder;
	int result, node_layer, samba_right;
	int sh_num;
	char **folder_list = NULL;
	int acc_num;
	char **account_list;
	char tmp[128];
	
	unlink("/var/log.samba");
	
	if ((fp=fopen(SAMBA_CONF, "r"))) {
		fclose(fp);
		unlink(SAMBA_CONF);
	}
	
	if((fp = fopen(SAMBA_CONF, "w")) == NULL)
		goto confpage;
	
	fprintf(fp, "[global]\n");
	//if (nvram_safe_get("st_samba_workgroup"))
	if(!tcapi_get("Samba_Entry", "st_samba_workgroup", tmp))
		//fprintf(fp, "workgroup = %s\n", nvram_safe_get("st_samba_workgroup"));
		fprintf(fp, "workgroup = %s\n", tmp);

#if 0
	if (nvram_safe_get("computer_name")) {
		fprintf(fp, "netbios name = %s\n", nvram_safe_get("computer_name"));
		fprintf(fp, "server string = %s\n", nvram_safe_get("computer_name"));
	}
#else
	//p_computer_name = nvram_get("computer_name") && is_valid_hostname(nvram_get("computer_name")) ? nvram_get("computer_name") : nvram_safe_get("productid");
	tcapi_get("Samba_Entry", "NetBiosName", tmp);	//check NetBiosName in web page
	p_computer_name = tmp;
	if (p_computer_name) {
		fprintf(fp, "netbios name = %s\n", p_computer_name);
		fprintf(fp, "server string = %s\n", p_computer_name);
	}
#endif

	fprintf(fp, "unix charset = UTF8\n");		// ASUS add
	fprintf(fp, "display charset = UTF8\n");	// ASUS add
	fprintf(fp, "log file = /var/log.samba\n");
	fprintf(fp, "log level = 0\n");
	fprintf(fp, "max log size = 5\n");
	
	/* share mode */
	tcapi_get("Samba_Entry", "st_samba_mode", tmp);
	if (!strcmp(tmp, "1") || !strcmp(tmp, "3")) {
	//if (!strcmp(nvram_safe_get("st_samba_mode"), "1") || !strcmp(nvram_safe_get("st_samba_mode"), "3")) {
		fprintf(fp, "security = SHARE\n");
		fprintf(fp, "guest only = yes\n");
	}
	//else if (!strcmp(nvram_safe_get("st_samba_mode"), "2") || !strcmp(nvram_safe_get("st_samba_mode"), "4")) {
	else if (!strcmp(tmp, "2") || !strcmp(tmp, "4")) {
		fprintf(fp, "security = USER\n");
		fprintf(fp, "guest ok = no\n");
		fprintf(fp, "map to guest = Bad User\n");
	}
	else{
		usb_dbg("samba mode: no\n");
		goto confpage;
	}
	
	fprintf(fp, "encrypt passwords = yes\n");
	fprintf(fp, "pam password change = no\n");
	fprintf(fp, "null passwords = yes\n");		// ASUS add
	
	fprintf(fp, "force directory mode = 0777\n");
	fprintf(fp, "force create mode = 0777\n");
	
	/* max users */
	if (!tcapi_get("Samba_Entry", "st_max_user", tmp))
		fprintf(fp, "max connections = %s\n", tmp);
	//if (strcmp(nvram_safe_get("st_max_user"), "") != 0)
		//fprintf(fp, "max connections = %s\n", nvram_safe_get("st_max_user"));

	fprintf(fp, "socket options = TCP_NODELAY SO_KEEPALIVE SO_RCVBUF=65536 SO_SNDBUF=65536\n");
	fprintf(fp, "use sendfile = no\n");
	fprintf(fp, "obey pam restrictions = no\n");
	fprintf(fp, "use spne go = no\n");		// ASUS add
	fprintf(fp, "client use spnego = no\n");	// ASUS add
	fprintf(fp, "disable spoolss = yes\n");		// ASUS add
	fprintf(fp, "host msdfs = no\n");		// ASUS add
	fprintf(fp, "strict allocate = No\n");		// ASUS add
//	fprintf(fp, "mangling method = hash2\n");	// ASUS add
	fprintf(fp, "bind interfaces only = yes\n");	// ASUS add
	fprintf(fp, "interfaces = lo br0\n");
	//fprintf(fp, "interfaces = lo br0 %s\n", (!nvram_match("sw_mode", "3") ? nvram_safe_get("wan0_ifname") : ""));
//	fprintf(fp, "dns proxy = no\n");				// J--

//	fprintf(fp, "domain master = no\n");				// J++
//	fprintf(fp, "wins support = no\n");				// J++
//	fprintf(fp, "printable = no\n");				// J++
//	fprintf(fp, "browseable = yes\n");				// J++
//	fprintf(fp, "security mask = 0777\n");				// J++
//	fprintf(fp, "force security mode = 0\n");			// J++
//	fprintf(fp, "directory security mask = 0777\n");		// J++
//	fprintf(fp, "force directory security mode = 0\n");		// J++

	fprintf(fp, "map archive = no\n");
	fprintf(fp, "map hidden = no\n");
	fprintf(fp, "map read only = no\n");
	fprintf(fp, "map system = no\n");
	fprintf(fp, "store dos attributes = yes\n");
	fprintf(fp, "dos filemode = yes\n");
	fprintf(fp, "dos filetimes = yes\n");
	fprintf(fp, "dos filetime resolution = yes\n");

	disks_info = read_disk_data();
	if (disks_info == NULL) {
		usb_dbg("Couldn't get disk list when writing smb.conf!\n");
		goto confpage;
	}

	/* share */
	tcapi_get("Samba_Entry", "st_samba_mode", tmp);
	if (!strcmp(tmp, "0")) {
	//if (!strcmp(nvram_safe_get("st_samba_mode"), "0") || !strcmp(nvram_safe_get("st_samba_mode"), "")) {
		;
	}
	else if (!strcmp(tmp, "1")) {
	//else if (!strcmp(nvram_safe_get("st_samba_mode"), "1")) {
		usb_dbg("samba mode: share\n");
		
		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;
				
				mount_folder = strrchr(follow_partition->mount_point, '/')+1;
				
				fprintf(fp, "[%s]\n", mount_folder);
				fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder);
				fprintf(fp, "veto files = /.__*.txt*/asusware*/asus_lighttpdpasswd/\n");
				fprintf(fp, "path = %s\n", follow_partition->mount_point);
				fprintf(fp, "writeable = yes\n");
			}
		}
	}
	else if (!strcmp(tmp, "2")) {
	//else if (!strcmp(nvram_safe_get("st_samba_mode"), "2")) {
		usb_dbg("samba mode: share\n");
		
		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;
				
				mount_folder = strrchr(follow_partition->mount_point, '/')+1;
				
				node_layer = get_permission(NULL, follow_partition->mount_point, NULL, "cifs");
				if(node_layer == 3){
					fprintf(fp, "[%s]\n", mount_folder);
					fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder);
					fprintf(fp, "path = %s\n", follow_partition->mount_point);
					fprintf(fp, "writeable = yes\n");
				}
				else{
					//result = get_all_folder(follow_partition->mount_point, &sh_num, &folder_list);
					result = get_folder_list(follow_partition->mount_point, &sh_num, &folder_list);
					if (result < 0){
						free_2_dimension_list(&sh_num, &folder_list);
						continue;
					}
					
					for (n = 0; n < sh_num; ++n){
						samba_right = get_permission(NULL, follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 0 || samba_right > 3)
							samba_right = DEFAULT_SAMBA_RIGHT;
						
						if(samba_right > 0){
							fprintf(fp, "[%s (at %s)]\n", folder_list[n], mount_folder);
							fprintf(fp, "comment = %s's %s in %s\n", mount_folder, folder_list[n], follow_disk->tag);
							fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]);
							if(samba_right == 3)
								fprintf(fp, "writeable = yes\n");
							else
								fprintf(fp, "writeable = no\n");
						}
					}
					
					free_2_dimension_list(&sh_num, &folder_list);
				}
			}
		}
	}
	else if (!strcmp(tmp, "3")) {
	//else if (!strcmp(nvram_safe_get("st_samba_mode"), "3")) {
		usb_dbg("samba mode: user\n");
		
		// get the account list
		if (get_account_list(&acc_num, &account_list) < 0) {
			usb_dbg("Can't read the account list.\n");
			free_2_dimension_list(&acc_num, &account_list);
			goto confpage;
		}
		
		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;
				
				mount_folder = strrchr(follow_partition->mount_point, '/')+1;
				
				// 1. get the folder list
				if (get_folder_list(follow_partition->mount_point, &sh_num, &folder_list) < 0) {
					free_2_dimension_list(&sh_num, &folder_list);
				}
				
				// 2. start to get every share
				for (n = -1; n < sh_num; ++n) {
					int i, first;
					
					if(n == -1){
						fprintf(fp, "[%s]\n", mount_folder);
						fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder);
						fprintf(fp, "path = %s\n", follow_partition->mount_point);
					}
					else{
						fprintf(fp, "[%s (at %s)]\n", folder_list[n], mount_folder);
						fprintf(fp, "comment = %s's %s in %s\n", mount_folder, folder_list[n], follow_disk->tag);
						fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]);
					}
					
					fprintf(fp, "valid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");
						
						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
					
					fprintf(fp, "invalid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right >= 1)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");
						
						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
					
					fprintf(fp, "read list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 1)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");
						
						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
					
					fprintf(fp, "write list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 2)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");
						
						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
				}
				
				free_2_dimension_list(&sh_num, &folder_list);
			}
		}
		
		free_2_dimension_list(&acc_num, &account_list);
	}
	else if (!strcmp(tmp, "4")) {
	//else if (!strcmp(nvram_safe_get("st_samba_mode"), "4")) {
		usb_dbg("samba mode: user\n");
		
		// get the account list
		if (get_account_list(&acc_num, &account_list) < 0) {
			usb_dbg("Can't read the account list.\n");
			free_2_dimension_list(&acc_num, &account_list);
			goto confpage;
		}
		
		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;
				
				mount_folder = strrchr(follow_partition->mount_point, '/')+1;
				
				// 1. get the folder list
				if (get_folder_list(follow_partition->mount_point, &sh_num, &folder_list) < 0) {
					free_2_dimension_list(&sh_num, &folder_list);
				}
				
				// 2. start to get every share
				for (n = 0; n < sh_num; ++n) {
					int i, first;
					
					fprintf(fp, "[%s (at %s)]\n", folder_list[n], mount_folder);
					fprintf(fp, "comment = %s's %s in %s\n", mount_folder, folder_list[n], follow_disk->tag);
					fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]);
					
					fprintf(fp, "valid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");
						
						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
					
					fprintf(fp, "invalid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right >= 1)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");
						
						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
					
					fprintf(fp, "read list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 1)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");
						
						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
					
					fprintf(fp, "write list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 2)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");
						
						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
				}
				
				free_2_dimension_list(&sh_num, &folder_list);
			}
		}
		
		free_2_dimension_list(&acc_num, &account_list);
	}
	
confpage:
	if(fp != NULL)
		fclose(fp);
	free_disk_data(&disks_info);
	return 0;
}
Пример #4
0
int
safe_remove_usb_device(int port, const char *dev_name, int do_spindown)
{
	int modem_devnum = 0;

	if (dev_name && strncmp(dev_name, "sd", 2) != 0) {
		modem_devnum = atoi(dev_name);
		if (modem_devnum < 0) modem_devnum = 0;
	}

	if (port == 1 || port == 2) {
		if (modem_devnum) {
			usb_info_t *usb_info, *follow_usb;
			int has_modem_port = 0;
			
			usb_info = get_usb_info();
			for (follow_usb = usb_info; follow_usb != NULL; follow_usb = follow_usb->next) {
				if ((follow_usb->port_root == port) &&
				    (follow_usb->id_devnum == modem_devnum) &&
				    (follow_usb->dev_type == DEVICE_TYPE_MODEM_TTY ||
				     follow_usb->dev_type == DEVICE_TYPE_MODEM_ETH))
					has_modem_port |= 1;
			}
			free_usb_info(usb_info);
			
			if (has_modem_port) {
				if ( get_usb_modem_dev_wan(0, modem_devnum) ) {
					safe_remove_usb_modem();
					try_wan_reconnect(0, 0);
				}
			}
		} else {
			int has_mounted_port = 0;
			disk_info_t *disks_info, *follow_disk;
			
			disks_info = read_disk_data();
			for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
				if (follow_disk->port_root == port && follow_disk->mounted_number > 0)
					has_mounted_port |= 1;
			}
			if (has_mounted_port) {
				stop_usb_apps();
				umount_usb_path(disks_info, port, dev_name, do_spindown);
				umount_ejected();
				if (count_sddev_mountpoint())
					start_usb_apps();
#if defined(APP_NFSD)
				else
					unload_nfsd();
#endif
			}
			free_disk_data(disks_info);
		}
		
	} else if (port == 0) {
		disk_info_t *disks_info;
		
		stop_usb_apps();
		disks_info = read_disk_data();
		umount_usb_path(disks_info, 0, NULL, do_spindown);
		free_disk_data(disks_info);
		umount_sddev_all();
		umount_ejected();
#if defined(APP_NFSD)
		unload_nfsd();
#endif
	}

	return 0;
}
Пример #5
0
int main(int argc, char *argv[])
{
	FILE *fp;
	char *nv;
	int n=0;
	char *p_computer_name = NULL;
	disk_info_t *follow_disk, *disks_info = NULL;
	partition_info_t *follow_partition;
	char *mount_folder;
	int result, node_layer, samba_right;
	int sh_num;
	char **folder_list = NULL;
	int acc_num;
	char **account_list;
	int dup, same_m_pt = 0;
	char unique_share_name[PATH_MAX];

	unlink("/var/log.samba");

	if ((fp=fopen(SAMBA_CONF, "r"))) {
		fclose(fp);
		unlink(SAMBA_CONF);
	}

	if((fp = fopen(SAMBA_CONF, "w")) == NULL)
		goto confpage;

	fprintf(fp, "[global]\n");
	if (nvram_safe_get("st_samba_workgroup"))
		fprintf(fp, "workgroup = %s\n", nvram_safe_get("st_samba_workgroup"));
#if 0
	if (nvram_safe_get("computer_name")) {
		fprintf(fp, "netbios name = %s\n", nvram_safe_get("computer_name"));
		fprintf(fp, "server string = %s\n", nvram_safe_get("computer_name"));
	}
#else
	p_computer_name = nvram_get("computer_name") && is_valid_netbios_name(nvram_get("computer_name")) ? nvram_get("computer_name") : get_productid();
	if (p_computer_name) {
		fprintf(fp, "netbios name = %s\n", p_computer_name);
		fprintf(fp, "server string = %s\n", p_computer_name);
	}
#endif

	fprintf(fp, "unix charset = UTF8\n");		// ASUS add
	fprintf(fp, "display charset = UTF8\n");	// ASUS add
	fprintf(fp, "log file = /var/log.samba\n");
	fprintf(fp, "log level = 0\n");
	fprintf(fp, "max log size = 5\n");

	// account mode
	if(nvram_match("st_samba_mode", "2") || nvram_match("st_samba_mode", "4")
			|| (nvram_match("st_samba_mode", "1") && nvram_get("st_samba_force_mode") == NULL)
			){
		fprintf(fp, "security = USER\n");
		fprintf(fp, "guest ok = no\n");
		fprintf(fp, "map to guest = Bad User\n");
	}
	// share mode
	else if (nvram_match("st_samba_mode", "1") || nvram_match("st_samba_mode", "3")) {
#if 0
//#if defined(RTCONFIG_TFAT) || defined(RTCONFIG_TUXERA_NTFS) || defined(RTCONFIG_TUXERA_HFS)
		if(nvram_get_int("enable_samba_tuxera") == 1){
			fprintf(fp, "auth methods = guest\n");
			fprintf(fp, "guest account = admin\n");
			fprintf(fp, "map to guest = Bad Password\n");
			fprintf(fp, "guest ok = yes\n");
		}
		else{
			fprintf(fp, "security = SHARE\n");
			fprintf(fp, "guest only = yes\n");
		}
#else
		fprintf(fp, "security = SHARE\n");
		fprintf(fp, "guest only = yes\n");
#endif
	}
	else{
		usb_dbg("samba mode: no\n");
		goto confpage;
	}

	fprintf(fp, "encrypt passwords = yes\n");
	fprintf(fp, "pam password change = no\n");
	fprintf(fp, "null passwords = yes\n");		// ASUS add
#ifdef RTCONFIG_SAMBA_MODERN
	if (nvram_get_int("smbd_enable_smb2"))
		fprintf(fp, "max protocol = SMB2\n");
	else
		fprintf(fp, "max protocol = NT1\n");

	fprintf(fp, "passdb backend = smbpasswd\n");
	fprintf(fp, "smb encrypt = disabled\n");
	fprintf(fp, "smb passwd file = /etc/samba/smbpasswd\n");
#endif
#if 0
#ifdef RTCONFIG_RECVFILE
	fprintf(fp, "use recvfile = yes\n");
#endif
#endif
	fprintf(fp, "force directory mode = 0777\n");
	fprintf(fp, "force create mode = 0777\n");

	/* max users */
	if (strcmp(nvram_safe_get("st_max_user"), "") != 0)
		fprintf(fp, "max connections = %s\n", nvram_safe_get("st_max_user"));

        /* remove socket options due to NIC compatible issue */
	if(!nvram_get_int("stop_samba_speedup")){
#ifdef RTCONFIG_BCMARM
#ifdef RTCONFIG_BCM_7114
		fprintf(fp, "socket options = IPTOS_LOWDELAY TCP_NODELAY SO_RCVBUF=131072 SO_SNDBUF=131072\n");
#endif
#else
		fprintf(fp, "socket options = TCP_NODELAY SO_KEEPALIVE SO_RCVBUF=65536 SO_SNDBUF=65536\n");
#endif
	}
	fprintf(fp, "obey pam restrictions = no\n");
	fprintf(fp, "use spnego = no\n");		// ASUS add
	fprintf(fp, "client use spnego = no\n");	// ASUS add
//	fprintf(fp, "client use spnego = yes\n");  // ASUS add
	fprintf(fp, "disable spoolss = yes\n");		// ASUS add
	fprintf(fp, "host msdfs = no\n");		// ASUS add
	fprintf(fp, "strict allocate = No\n");		// ASUS add
//	fprintf(fp, "mangling method = hash2\n");	// ASUS add
	fprintf(fp, "bind interfaces only = yes\n");    // ASUS add

#ifndef RTCONFIG_BCMARM
	fprintf(fp, "interfaces = lo br0 %s\n", (is_routing_enabled() && nvram_get_int("smbd_wanac")) ? nvram_safe_get("wan0_ifname") : "");
#else
	fprintf(fp, "interfaces = br0 %s/%s %s\n", nvram_safe_get("lan_ipaddr"), nvram_safe_get("lan_netmask"), (is_routing_enabled() && nvram_get_int("smbd_wanac")) ? nvram_safe_get("wan0_ifname") : "");
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
	fprintf(fp, "use sendfile = no\n");
#else
	fprintf(fp, "use sendfile = yes\n");
#endif
	if (!strcmp(nvram_safe_get("smbd_wins"), "1")) {
		fprintf(fp, "wins support = yes\n");
	}

	if (!strcmp(nvram_safe_get("smbd_master"), "1")) {
		fprintf(fp, "os level = 255\n");
		fprintf(fp, "domain master = yes\n");
		fprintf(fp, "local master = yes\n");
		fprintf(fp, "preferred master = yes\n");
	}

	fprintf(fp, "map archive = no\n");
	fprintf(fp, "map hidden = no\n");
	fprintf(fp, "map read only = no\n");
	fprintf(fp, "map system = no\n");
	fprintf(fp, "store dos attributes = yes\n");
	fprintf(fp, "dos filemode = yes\n");
	fprintf(fp, "oplocks = yes\n");
	fprintf(fp, "level2 oplocks = yes\n");
	fprintf(fp, "kernel oplocks = no\n");
	fprintf(fp, "wide links = no\n");

	// If we only want name services then skip share definition
	if (nvram_match("enable_samba", "0"))
		goto confpage;

	disks_info = read_disk_data();
	if (disks_info == NULL) {
		usb_dbg("Couldn't get disk list when writing smb.conf!\n");
		goto confpage;
	}

	/* share */
	if (nvram_match("st_samba_mode", "0") || !strcmp(nvram_safe_get("st_samba_mode"), "")) {
		;
	}
	else if (nvram_match("st_samba_mode", "1") && nvram_match("st_samba_force_mode", "1")) {
		usb_dbg("samba mode: share\n");

		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;
				
				strcpy(unique_share_name, follow_partition->mount_point);
				do {
					dup = check_mount_point_icase(disks_info, follow_partition, follow_disk, follow_partition->partition_order, unique_share_name);
					if (dup)
						sprintf(unique_share_name, "%s(%d)", follow_partition->mount_point, ++same_m_pt);
				} while (dup);
				mount_folder = strrchr(unique_share_name, '/')+1;

				fprintf(fp, "[%s]\n", mount_folder);
				fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder);
				fprintf(fp, "veto files = /.__*.txt*/asus_lighttpdpasswd/\n");
				fprintf(fp, "path = %s\n", follow_partition->mount_point);
				fprintf(fp, "writeable = yes\n");

				fprintf(fp, "dos filetimes = yes\n");
				fprintf(fp, "fake directory create times = yes\n");
			}
		}
	}
	else if (nvram_match("st_samba_mode", "2")) {
		usb_dbg("samba mode: share\n");

		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;

				strcpy(unique_share_name, follow_partition->mount_point);
				do {
					dup = check_mount_point_icase(disks_info, follow_partition, follow_disk, follow_partition->partition_order, unique_share_name);
					if (dup)
						sprintf(unique_share_name, "%s(%d)", follow_partition->mount_point, ++same_m_pt);
				} while (dup);
				mount_folder = strrchr(unique_share_name, '/')+1;

				node_layer = get_permission(NULL, follow_partition->mount_point, NULL, "cifs");
				if(node_layer == 3){
					fprintf(fp, "[%s]\n", mount_folder);
					fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder);
					fprintf(fp, "path = %s\n", follow_partition->mount_point);
					fprintf(fp, "writeable = yes\n");

					fprintf(fp, "dos filetimes = yes\n");
					fprintf(fp, "fake directory create times = yes\n");
				}
				else{
					//result = get_all_folder(follow_partition->mount_point, &sh_num, &folder_list);
					result = get_folder_list(follow_partition->mount_point, &sh_num, &folder_list);
					if (result < 0){
						free_2_dimension_list(&sh_num, &folder_list);
						continue;
					}

					for (n = 0; n < sh_num; ++n){
						samba_right = get_permission(NULL, follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 0 || samba_right > 3)
							samba_right = DEFAULT_SAMBA_RIGHT;

						if(samba_right > 0){
							int count = get_list_strings_count(folder_list, sh_num, folder_list[n]);
							if ((!strcmp(nvram_safe_get("smbd_simpler_naming"), "1")) && (count <= 1)) {
								fprintf(fp, "[%s]\n", folder_list[n]);
							} else {
								fprintf(fp, "[%s (at %s)]\n", folder_list[n], mount_folder);
							}
							fprintf(fp, "comment = %s's %s in %s\n", mount_folder, folder_list[n], follow_disk->tag);
							fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]);
							if(samba_right == 3)
								fprintf(fp, "writeable = yes\n");
							else
								fprintf(fp, "writeable = no\n");

							fprintf(fp, "dos filetimes = yes\n");
							fprintf(fp, "fake directory create times = yes\n");
						}
					}

					free_2_dimension_list(&sh_num, &folder_list);
				}
			}
		}
	}
	else if (nvram_match("st_samba_mode", "3")) {
		usb_dbg("samba mode: user\n");

		// get the account list
		if (get_account_list(&acc_num, &account_list) < 0) {
			usb_dbg("Can't read the account list.\n");
			free_2_dimension_list(&acc_num, &account_list);
			goto confpage;
		}

		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;

				mount_folder = strrchr(follow_partition->mount_point, '/')+1;

				// 1. get the folder list
				if (get_folder_list(follow_partition->mount_point, &sh_num, &folder_list) < 0) {
					free_2_dimension_list(&sh_num, &folder_list);
				}

				// 2. start to get every share
				for (n = -1; n < sh_num; ++n) {
					int i, first;

					if(n == -1){
						fprintf(fp, "[%s]\n", mount_folder);
						fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder);
						fprintf(fp, "path = %s\n", follow_partition->mount_point);
					}
					else{
						int count = get_list_strings_count(folder_list, sh_num, folder_list[n]);
						if ((!strcmp(nvram_safe_get("smbd_simpler_naming"), "1")) && (count <= 1)) {
							fprintf(fp, "[%s]\n", folder_list[n]);
						} else {
							fprintf(fp, "[%s (at %s)]\n", folder_list[n], mount_folder);
						}
						fprintf(fp, "comment = %s's %s in %s\n", mount_folder, folder_list[n], follow_disk->tag);
						fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]);
					}

					fprintf(fp, "dos filetimes = yes\n");
					fprintf(fp, "fake directory create times = yes\n");

					fprintf(fp, "valid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");

					fprintf(fp, "invalid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right >= 1)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");

					fprintf(fp, "read list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 1)
							continue;

						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");

					fprintf(fp, "write list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 2)
							continue;

						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
				}

				free_2_dimension_list(&sh_num, &folder_list);
			}
		}

		free_2_dimension_list(&acc_num, &account_list);
	}
	else if (nvram_match("st_samba_mode", "4")
			|| (nvram_match("st_samba_mode", "1") && nvram_get("st_samba_force_mode") == NULL)
			) {
		usb_dbg("samba mode: user\n");

		// get the account list
		if (get_account_list(&acc_num, &account_list) < 0) {
			usb_dbg("Can't read the account list.\n");
			free_2_dimension_list(&acc_num, &account_list);
			goto confpage;
		}

		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;

				mount_folder = strrchr(follow_partition->mount_point, '/')+1;

				// 1. get the folder list
				if (get_folder_list(follow_partition->mount_point, &sh_num, &folder_list) < 0) {
					free_2_dimension_list(&sh_num, &folder_list);
				}

				// 2. start to get every share
				for (n = 0; n < sh_num; ++n) {
					int i, first;

					int count = get_list_strings_count(folder_list, sh_num, folder_list[n]);
					if ((!strcmp(nvram_safe_get("smbd_simpler_naming"), "1")) && (count <= 1)) {
						fprintf(fp, "[%s]\n", folder_list[n]);
					} else {
						fprintf(fp, "[%s (at %s)]\n", folder_list[n], mount_folder);
					}
					fprintf(fp, "comment = %s's %s in %s\n", mount_folder, folder_list[n], follow_disk->tag);
					fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]);

					fprintf(fp, "dos filetimes = yes\n");
					fprintf(fp, "fake directory create times = yes\n");

					fprintf(fp, "valid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						if(n == -1)
							samba_right = get_permission(account_list[i], follow_partition->mount_point, NULL, "cifs");
						else
							samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");

					fprintf(fp, "invalid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right >= 1)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");

					fprintf(fp, "read list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 1)
							continue;

						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");

					fprintf(fp, "write list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						samba_right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (samba_right < 2)
							continue;

						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");

						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
				}

				free_2_dimension_list(&sh_num, &folder_list);
			}
		}

		free_2_dimension_list(&acc_num, &account_list);
	}

confpage:
	if(fp != NULL) {

		append_custom_config("smb.conf", fp);
		fclose(fp);

		use_custom_config("smb.conf", SAMBA_CONF);
		run_postconf("smb", SAMBA_CONF);
	}

	free_disk_data(&disks_info);
	return 0;
}
Пример #6
0
int
write_smb_conf(void)
{
	FILE *fp;
	int i_maxuser, i_smb_mode;
	disk_info_t *follow_disk, *disks_info = NULL;
	partition_info_t *follow_partition;

	i_smb_mode = nvram_get_int("st_samba_mode");

	fp = write_smb_conf_header();
	if (!fp)
		return -1;

	/* share mode */
	if (i_smb_mode == 1 || i_smb_mode == 3) {
		char *rootnm = nvram_safe_get("http_username");
		if (!(*rootnm)) rootnm = "admin";
		
		fprintf(fp, "security = %s\n", "SHARE");
		fprintf(fp, "guest ok = %s\n", "yes");
		fprintf(fp, "guest only = yes\n");
		fprintf(fp, "guest account = %s\n", rootnm);
	} else if (i_smb_mode == 4) {
		fprintf(fp, "security = %s\n", "USER");
		fprintf(fp, "guest ok = %s\n", "no");
		fprintf(fp, "map to guest = Bad User\n");
		fprintf(fp, "hide unreadable = yes\n");
	} else {
		goto confpage;
	}

	fprintf(fp, "writeable = yes\n");
	fprintf(fp, "directory mode = 0777\n");
	fprintf(fp, "create mask = 0777\n");
	fprintf(fp, "force directory mode = 0777\n");

	/* max users */
	i_maxuser = nvram_get_int("st_max_user");
	if (i_maxuser < 1) i_maxuser = 1;
	if (i_maxuser > MAX_CLIENTS_NUM) i_maxuser = MAX_CLIENTS_NUM;

	fprintf(fp, "max connections = %d\n", i_maxuser);
	fprintf(fp, "use spnego = no\n");		// ASUS add
	fprintf(fp, "client use spnego = no\n");	// ASUS add
	fprintf(fp, "null passwords = yes\n");		// ASUS add
	fprintf(fp, "strict allocate = no\n");		// ASUS add
	fprintf(fp, "use sendfile = yes\n");
	fprintf(fp, "dos filemode = yes\n");
	fprintf(fp, "dos filetimes = yes\n");
	fprintf(fp, "dos filetime resolution = yes\n");
	fprintf(fp, "\n");

	disks_info = read_disk_data();
	if (!disks_info) {
		goto confpage;
	}

	/* share */
	if (i_smb_mode == 1) {
		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				char *mount_folder;
				
				if (follow_partition->mount_point == NULL)
					continue;
				
				mount_folder = strrchr(follow_partition->mount_point, '/')+1;
				
				fprintf(fp, "[%s]\n", mount_folder);
				fprintf(fp, "comment = %s's %s\n", follow_disk->tag, mount_folder);
				fprintf(fp, "path = %s\n", follow_partition->mount_point);
				fprintf(fp, "guest ok = yes\n");
				fprintf(fp, "writeable = yes\n");
				fprintf(fp, "directory mode = 0777\n");
				fprintf(fp, "create mask = 0777\n");
				fprintf(fp, "map archive = no\n");
				fprintf(fp, "map hidden = no\n");
				fprintf(fp, "map read only = no\n");
				fprintf(fp, "map system = no\n");
				fprintf(fp, "store dos attributes = yes\n\n");
			}
		}
	} else if (i_smb_mode == 3) {
		fprintf(fp, "[%s]\n", "Media");
		fprintf(fp, "comment = %s\n", "Root share for all media");
		fprintf(fp, "path = %s\n", POOL_MOUNT_ROOT);
		fprintf(fp, "guest ok = yes\n");
		fprintf(fp, "writeable = yes\n");
		fprintf(fp, "directory mode = 0777\n");
		fprintf(fp, "create mask = 0777\n");
		fprintf(fp, "map archive = no\n");
		fprintf(fp, "map hidden = no\n");
		fprintf(fp, "map read only = no\n");
		fprintf(fp, "map system = no\n");
		fprintf(fp, "store dos attributes = yes\n\n");
	} else {
		int n, acc_num = 0, sh_num=0;
		char **account_list;
		
		// get the account list
		if (get_account_list(&acc_num, &account_list) < 0) {
			usb_dbg("Can't read the account list.\n");
			free_2_dimension_list(&acc_num, &account_list);
			goto confpage;
		}
		
		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;
				
				char **folder_list;
				
				// 1. get the folder list
				if (get_folder_list_in_mount_path(follow_partition->mount_point, &sh_num, &folder_list) < 0) {
					usb_dbg("Can't read the folder list in %s.\n", follow_partition->mount_point);
					free_2_dimension_list(&sh_num, &folder_list);
					continue;
				}
				
				// 2. start to get every share
				for (n = 0; n < sh_num; ++n) {
					int i, right, first;
					char share[256];
					
					memset(share, 0, 256);
					strcpy(share, folder_list[n]);
					
					fclose(fp);
					
					if(check_existed_share(share)){
						i = 1;
						memset(share, 0, 256);
						sprintf(share, "%s(%d)", folder_list[n], i);
						while(check_existed_share(share)){
							++i;
							memset(share, 0, 256);
							sprintf(share, "%s(%d)", folder_list[n], i);
						}
					}
					
					if((fp = fopen(SAMBA_CONF, "a")) == NULL)
						goto confpage;
					fprintf(fp, "[%s]\n", share);
					fprintf(fp, "comment = %s\n", folder_list[n]);
					fprintf(fp, "path = %s/%s\n", follow_partition->mount_point, folder_list[n]);
					fprintf(fp, "writeable = no\n");
					
					fprintf(fp, "valid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");
						
						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
					
					fprintf(fp, "invalid users = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (right >= 1)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");
						
						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
					
					fprintf(fp, "read list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (right < 1)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");
						
						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
					
					fprintf(fp, "write list = ");
					first = 1;
					for (i = 0; i < acc_num; ++i) {
						right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "cifs");
						if (right < 2)
							continue;
						
						if (first == 1)
							first = 0;
						else
							fprintf(fp, ", ");
						
						fprintf(fp, "%s", account_list[i]);
					}
					fprintf(fp, "\n");
				}
				
				free_2_dimension_list(&sh_num, &folder_list);
			}
		}
		
		free_2_dimension_list(&acc_num, &account_list);
	}

confpage:
	fclose(fp);
	free_disk_data(disks_info);
	return 0;
}
int main(int argc, char *argv[]) {
	FILE *fp;
	int n=0, sh_num=0;
	disk_info_t *follow_disk, *disks_info = NULL;
	partition_info_t *follow_partition;
	
	/* 
		st_webdav_mpde = 1 => share mode (default)
		st_webdav_mode = 2 => account mode
	*/

	/* write /tmp/lighttpd.conf */
	if ((fp=fopen(WEBDAV_CONF, "r"))) {
		fclose(fp);
		unlink(WEBDAV_CONF);
	}
	
	fp = fopen(WEBDAV_CONF, "w");
	if (fp==NULL) return;
	
	/* Load modules */
	fprintf(fp, "server.modules+=(\"mod_alias\")\n");
	fprintf(fp, "server.modules+=(\"mod_userdir\")\n");
	fprintf(fp, "server.modules+=(\"mod_aidisk_access\")\n");
	fprintf(fp, "server.modules+=(\"mod_sharelink\")\n");
	fprintf(fp, "server.modules+=(\"mod_create_captcha_image\")\n");
	fprintf(fp, "server.modules+=(\"mod_webdav\")\n");
	fprintf(fp, "server.modules+=(\"mod_smbdav\")\n");
	fprintf(fp, "server.modules+=(\"mod_redirect\")\n");
	fprintf(fp, "server.modules+=(\"mod_compress\")\n");
	fprintf(fp, "server.modules+=(\"mod_usertrack\")\n");
	fprintf(fp, "server.modules+=(\"mod_rewrite\")\n");
	
	if (nvram_match("st_webdav_mode", "2")){
		fprintf(fp, "server.modules+=(\"mod_access\")\n");
		fprintf(fp, "server.modules+=(\"mod_auth\")\n");
	}

	/* Basic setting */
	fprintf(fp, "server.port=%s\n",get_webdav_http_port()); // defult setting, but no use
//	fprintf(fp, "server.port=8999\n"); // defult setting, but no use
//	fprintf(fp, "server.document-root=\"/mnt/\"\n");
	fprintf(fp, "server.document-root=\"/tmp/lighttpd/www\"\n");
	fprintf(fp, "server.upload-dirs=(\"/tmp/lighttpd/uploads\")\n");
	fprintf(fp, "server.errorlog=\"/tmp/lighttpd/err.log\"\n");
	fprintf(fp, "server.pid-file=\"/tmp/lighttpd/lighttpd.pid\"\n");
	fprintf(fp, "server.arpping-interface=\"br0\"\n");
	fprintf(fp, "server.errorfile-prefix=\"/usr/css/status-\"\n");
	fprintf(fp, "dir-listing.activate=\"enable\"\n");
    fprintf(fp, "server.syslog=\"/tmp/lighttpd/syslog.log\"\n");

	//	**** Minetype setting **** //	
	fprintf(fp, "mimetype.assign = (\n");
	fprintf(fp, "\".html\" => \"text/html\",\n");
	fprintf(fp, "\".htm\" => \"text/html\",\n");
	fprintf(fp, "\".css\" => \"text/css\",\n");
	fprintf(fp, "\".js\" => \"text/javascript\",\n");
	
	fprintf(fp, "\".swf\" => \"application/x-shockwave-flash\",\n");
	//fprintf(fp, "\".txt\" => \"text/plain\",\n");
	//fprintf(fp, "\".jpg\" => \"image/jpeg\",\n");
	//fprintf(fp, "\".gif\" => \"image/gif\",\n");
	//fprintf(fp, "\".png\" => \"image/png\",\n");
	//fprintf(fp, "\".pdf\" => \"application/pdf\",\n");
	//fprintf(fp, "\".mp4\" => \"video/mp4\",\n");
	//fprintf(fp, "\".m4v\" => \"video/mp4\",\n");
	//fprintf(fp, "\".wmv\" => \"video/wmv\",\n");
	//fprintf(fp, "\".mp3\" => \"audio/mpeg\",\n");
	//fprintf(fp, "\".avi\" => \"video/avi\",\n");
	//fprintf(fp, "\".mov\" => \"video/mov\"");
	fprintf(fp, "\"\" => \"application/x-octet-stream\"");
	fprintf(fp, ")\n");

	// **** Index file names **** //
	fprintf(fp, "index-file.names = ( \"index.php\", \"index.html\",\n");
	fprintf(fp, "\"index.htm\", \"default.htm\",\n");
	fprintf(fp, " \" index.lighttpd.html\" )\n");

	// **** url access deny
	fprintf(fp, " url.access-deny             = ( \"~\", \".inc\" )\n");

	// **** static-file.exclude extensions
	fprintf(fp," static-file.exclude-extensions = ( \".php\", \".pl\", \".fcgi\" )\n");

	// ****
	fprintf(fp, "compress.cache-dir          = \"/tmp/lighttpd/compress/\"\n");
	fprintf(fp, "compress.filetype           = ( \"application/x-javascript\", \"text/css\", \"text/html\", \"text/plain\" )\n");
	
	// **** SambaDav setting
	fprintf(fp, "$SERVER[\"socket\"]==\":%s\"{\n", get_webdav_http_port());
//	fprintf(fp, "$SERVER[\"socket\"]==\":8999\"{\n");
//	fprintf(fp, "	alias.url=(\"/webdav\"=>\"/mnt/\")\n");
//	fprintf(fp, "   $HTTP[\"url\"]=~\"^/usbdisk($|/)\"{\n");
	fprintf(fp, "   $HTTP[\"url\"]=~\"^/%s($|/)\"{\n",get_productid());
    fprintf(fp, "       server.document-root = \"/\"\n");
//	fprintf(fp, "       alias.url=(\"/usbdisk\"=>\"/mnt\")\n");
	fprintf(fp, "       alias.url=(\"/%s\"=>\"/mnt\")\n", get_productid());
    fprintf(fp, "       webdav.activate=\"enable\"\n");
    fprintf(fp, "       webdav.is-readonly=\"disable\"\n");
    fprintf(fp, "       webdav.sqlite-db-name=\"/tmp/lighttpd/webdav.db\"\n");
    fprintf(fp, "   }\n");
	fprintf(fp, "	else $HTTP[\"url\"]=~\"^/smb($|/)\"{\n");
	fprintf(fp, "		server.document-root = \"/\"\n");
	fprintf(fp, "		alias.url=(\"/smb\"=>\"/usr\")\n");
	fprintf(fp, "		smbdav.auth_ntlm = (\"Microsoft-WebDAV\",\"xxBitKinex\",\"WebDrive\")\n");
	fprintf(fp, "		webdav.activate=\"enable\"\n");
	fprintf(fp, "		webdav.is-readonly=\"disable\"\n");
//	fprintf(fp, "		webdav.sqlite-db-name=\"/tmp/lighttpd/webdav.db\"\n");
	fprintf(fp, "	}\n");
	fprintf(fp, "	else $HTTP[\"url\"] =~ \"^/favicon.ico$\"{\n");
    fprintf(fp, "		server.document-root = \"/\"\n");
    fprintf(fp, "		alias.url = ( \"/favicon.ico\" => \"/usr/css/favicon.ico\" ) \n"); 
    fprintf(fp, "		webdav.activate = \"enable\" \n");
    fprintf(fp, "		webdav.is-readonly = \"enable\"\n");
	fprintf(fp, "	}\n");
	fprintf(fp, "	else $HTTP[\"url\"] !~ \"^/smb($|/)\" { \n");
	fprintf(fp, "	    server.document-root = \"smb://\" \n");
   	fprintf(fp, "	    smbdav.activate = \"enable\" \n");
    fprintf(fp, "	    smbdav.is-readonly = \"disable\" \n");
    fprintf(fp, "	    smbdav.always-auth = \"enable\" \n");
    fprintf(fp, "	    smbdav.sqlite-db-name = \"/tmp/lighttpd/smbdav.db\" \n");
    fprintf(fp, "	    usertrack.cookie-name = \"SMBSESSID\" \n");
	fprintf(fp, "	}\n");
	fprintf(fp, "}\n");



#if 0
	/*** Webdav_setting ***/
	/* default : http://192.168.1.1:8082/webdav */
	fprintf(fp, "$SERVER[\"socket\"]==\":8082\"{\n");
	fprintf(fp, "	alias.url=(\"/webdav\"=>\"/mnt/\")\n"); 	//mount point
	fprintf(fp, "	$HTTP[\"url\"]=~\"^/webdav($|/)\"{\n");
	fprintf(fp, "		webdav.activate=\"enable\"\n");
	fprintf(fp, "		webdav.is-readonly=\"disable\"\n");
	fprintf(fp, "		webdav.sqlite-db-name=\"/tmp/lighttpd/webdav.db\"\n");
	fprintf(fp, "	}\n");

	fprintf(fp, "	auth.backend=\"plain\"\n");
	fprintf(fp, "	auth.backend.plain.userfile=\"/tmp/lighttpd/permissions\"\n");
	fprintf(fp, "	auth.require= (\"\"=>(\"method\"=>\"basic\",\n");
	fprintf(fp, "				\"realm\"=>\"webdav\",\n");
	fprintf(fp, "				\"require\"=>\"valid-user\"))\n");

	
	disks_info = read_disk_data();
	if (disks_info == NULL) {
		//printf("[webdav] fail in read disk data!!\n");
		usb_dbg("Couldn't get disk list when writing smb.conf!\n");
	//	goto confpage;
		goto WEBDAV_SETTING;
	}

	/* account permissions */
	if (nvram_match("st_webdav_mode", "2")){

		disks_info = read_disk_data();
		if (disks_info == NULL) {
			usb_dbg("Couldn't get disk list when writing lighttpd.conf!\n");
			//	goto confpage;
			goto WEBDAV_SETTING;
		}

		int acc_num;
		char **account_list;
	

		/* folder permissions */
		if (get_account_list(&acc_num, &account_list) < 0) {
			usb_dbg("Can't read the account list.\n");
			//printf("[webdav] fail in get account list\n");
			free_2_dimension_list(&acc_num, &account_list);
//			goto confpage;
			goto WEBDAV_SETTING;
		}

		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;
				
				char **folder_list;
				int i;
				char tmp1[32];
				char *tmp2, *tmp_pre, *tmp_aft;

				strcpy(tmp1, follow_partition->mount_point);

				tmp2 = tmp1;
				for (i=0; i<3; i++){
					tmp_pre = strsep(&tmp2, "/");
					tmp_aft = tmp2;
				}
				//printf("[webdav] tmp1=%s,tmp2=%s,tmp_pre=%s,tmp_aft=%s\n", tmp1, tmp2, tmp_pre, tmp_aft);
				
				// 1. get the folder list
				if (get_folder_list(follow_partition->mount_point, &sh_num, &folder_list) < 0) {
					//printf("[webdav] fail in get folder list\n");
					usb_dbg("Can't read the folder list in %s.\n", follow_partition->mount_point);
					free_2_dimension_list(&sh_num, &folder_list);
					continue;
				}
	
				/* 
					right = 0 => NO
					right = 1 => R
					right = 3 => R/W (default)
				*/
	
				// 2. start to get every share
				for (n = 0; n < sh_num; ++n) {
					int i, right;
					for (i = 0; i < acc_num; ++i) {
						right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "webdav");
	//printf("[webdav] (%d,%d) : right=%d, account=%s, folder=%s, mount=%s, tmp_aft=%s\n", n, i, right, account_list[i], folder_list[n], follow_partition->mount_point, tmp_aft);
						if(right == 0){
							/* forbid to access the folder */
							fprintf(fp, "	$HTTP[\"url\"]=~\"^/webdav/%s/%s($|/)\"{\n", tmp_aft, folder_list[n]);
							fprintf(fp, "		url.access-deny=(\"\")\n"); 
							fprintf(fp, "	}\n");
						}
						else if (right == 1){
							fprintf(fp, "	$HTTP[\"url\"]=~\"^/webdav/%s/%s($|/)\"{\n", tmp_aft, folder_list[n]);
							fprintf(fp, "		webdav.is-readonly=\"enable\"\n");
							fprintf(fp, "	}\n");
						}
					}
				}
				free_2_dimension_list(&sh_num, &folder_list);
			}
		}
		/* folder permissions */
		free_2_dimension_list(&acc_num, &account_list);
	}/* account permissions */
WEBDAV_SETTING:
	fprintf(fp, "}\n"); /*** Webdav_setting ***/
#endif
	/*** Webdav_SSL ***/
	/* default : https://192.168.1.1:443/webdav */
	fprintf(fp, "$SERVER[\"socket\"]==\":%s\"{\n",get_webdav_https_port());
	fprintf(fp, "	ssl.pemfile=\"/tmp/lighttpd/server.pem\"\n");
	fprintf(fp, "	ssl.engine=\"enable\"\n");
	//fprintf(fp, "	alias.url=(\"/webdav\"=>\"/mnt/\")\n"); 
//	fprintf(fp, "	$HTTP[\"url\"]=~\"^/usbdisk($|/)\"{\n");
	fprintf(fp, "	$HTTP[\"url\"]=~\"^/%s($|/)\"{\n", get_productid());
    fprintf(fp, "       server.document-root = \"/\"\n");
//	fprintf(fp, "       alias.url=(\"/usbdisk\"=>\"/mnt\")\n");	
	fprintf(fp, "       alias.url=(\"/%s\"=>\"/mnt\")\n", get_productid());	
	fprintf(fp, "		webdav.activate=\"enable\"\n");
	fprintf(fp, "		webdav.is-readonly=\"disable\"\n");
	fprintf(fp, "		webdav.sqlite-db-name=\"/tmp/lighttpd/webdav.db\"\n");
	fprintf(fp, "	}\n");
	fprintf(fp, "	else $HTTP[\"url\"]=~\"^/smb($|/)\"{\n");
	fprintf(fp, "		server.document-root = \"/\"\n");
	fprintf(fp, "		alias.url=(\"/smb\"=>\"/usr\")\n");
	fprintf(fp, "		smbdav.auth_ntlm = (\"Microsoft-WebDAV\",\"xxBitKinex\",\"WebDrive\")\n");
	fprintf(fp, "		webdav.activate=\"enable\"\n");
	fprintf(fp, "		webdav.is-readonly=\"disable\"\n");
//	fprintf(fp, "		webdav.sqlite-db-name=\"/tmp/lighttpd/webdav.db\"\n");
	fprintf(fp, "	}\n");
	fprintf(fp, "	else $HTTP[\"url\"] =~ \"^/favicon.ico$\"{\n");
    fprintf(fp, "		server.document-root = \"/\"\n");
    fprintf(fp, "		alias.url = ( \"/favicon.ico\" => \"/usr/css/favicon.ico\" ) \n"); 
    fprintf(fp, "		webdav.activate = \"enable\" \n");
    fprintf(fp, "		webdav.is-readonly = \"enable\"\n");
	fprintf(fp, "	}\n");
	fprintf(fp, "	else $HTTP[\"url\"] !~ \"^/smb($|/)\" { \n");
	fprintf(fp, "	    server.document-root = \"smb://\" \n");
   	fprintf(fp, "	    smbdav.activate = \"enable\" \n");
    fprintf(fp, "	    smbdav.is-readonly = \"disable\" \n");
    fprintf(fp, "	    smbdav.always-auth = \"enable\" \n");
    fprintf(fp, "	    smbdav.sqlite-db-name = \"/tmp/lighttpd/smbdav.db\" \n");
    fprintf(fp, "	    usertrack.cookie-name = \"SMBSESSID\" \n");
	fprintf(fp, "	}\n");
#if 0
	/* account permissions */
	if (nvram_match("st_webdav_mode", "2")){
			fprintf(stderr,"=================================================>st mod =2");

		disks_info = read_disk_data();
		if (disks_info == NULL) {
			usb_dbg("Couldn't get disk list when writing lighttpd.conf!\n");
			fprintf(stderr, "=========================================================>error1");
			goto confpage;
		}

		int acc_num;
		char **account_list;
	
		fprintf(fp, "	auth.backend=\"plain\"\n");
		fprintf(fp, "	auth.backend.plain.userfile=\"/tmp/lighttpd/permissions\"\n");
		fprintf(fp, "	auth.require= (\"\"=>(\"method\"=>\"basic\",\n");
		fprintf(fp, "				\"realm\"=>\"webdav\",\n");
		fprintf(fp, "				\"require\"=>\"valid-user\"))\n");

		/* folder permissions */
		if (get_account_list(&acc_num, &account_list) < 0) {
			//usb_dbg("Can't read the account list.\n");
			//printf("[webdav] fail in get account list\n");
			free_2_dimension_list(&acc_num, &account_list);
			fprintf(stderr, "================================================================>error2");
			goto confpage;
		}

		for (follow_disk = disks_info; follow_disk != NULL; follow_disk = follow_disk->next) {
			for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
				if (follow_partition->mount_point == NULL)
					continue;
				
				char **folder_list;
				int i;
				//charles: dont init the size of tmp1, the name of share foler may exceed the buffer.
//				char tmp1[32];
				char *tmp1;
				char *tmp2, *tmp_pre, *tmp_aft;
				
				int tmp1_size=0;
				tmp1_size = strlen(follow_partition->mount_point)+1;
				tmp1 = malloc(tmp1_size); memset(tmp1, 0, tmp1_size);
				strcpy(tmp1, follow_partition->mount_point);

				tmp2 = tmp1;
				for (i=0; i<3; i++){
					tmp_pre = strsep(&tmp2, "/");
					tmp_aft = tmp2;
				}
				
				// 1. get the folder list
				if (get_folder_list(follow_partition->mount_point, &sh_num, &folder_list) < 0) {
					//printf("[webdav] fail in get folder list\n");
					usb_dbg("Can't read the folder list in %s.\n", follow_partition->mount_point);
					free_2_dimension_list(&sh_num, &folder_list);
					if(tmp1) free(tmp1);
					fprintf(stderr,"====================================================================>get folder list error");
					continue;
				}
	
				// 2. start to get every share
				for (n = 0; n < sh_num; ++n) {
					int i, right;
					for (i = 0; i < acc_num; ++i) {
						right = get_permission(account_list[i], follow_partition->mount_point, folder_list[n], "webdav");
	fprintf(stderr,"[webdav] (%d,%d) : right=%d, account=%s, folder=%s, mount=%s, tmp_aft=%s\n", n, i, right, account_list[i], folder_list[n], follow_partition->mount_point, tmp_aft);
						if(right == 0){
							/* forbid to access the folder */
							fprintf(fp, "	$HTTP[\"url\"]=~\"^/webdav/%s/%s($|/)\"{\n", tmp_aft, folder_list[n]);
							fprintf(fp, "		url.access-deny=(\"\")\n"); 
							fprintf(fp, "	}\n");
						}
						else if (right == 1){
						fprintf(fp, "	$HTTP[\"url\"]=~\"^/webdav/%s/%s($|/)\"{\n", tmp_aft, folder_list[n]);
							fprintf(fp, "		webdav.is-readonly=\"enable\"\n");
							fprintf(fp, "	}\n");
						}
					}
				}
				free_2_dimension_list(&sh_num, &folder_list);
				if(tmp1) free(tmp1);
			}
		}
		/* folder permissions */
		free_2_dimension_list(&acc_num, &account_list);
	}/* account permissions */
#endif
	
	goto confpage;

confpage:
	fprintf(fp, "}\n"); /*** Webdav_SSL ***/

	/* debugging */
	fprintf(fp, "debug.log-request-header=\"disable\"\n");
	fprintf(fp, "debug.log-response-header=\"disable\"\n");
	fprintf(fp, "debug.log-request-handling=\"disable\"\n");
	fprintf(fp, "debug.log-file-not-found=\"disable\"\n");
	fprintf(fp, "debug.log-condition-handling=\"disable\"\n");

	fclose(fp);
	free_disk_data(&disks_info);
	return 0;
}
Пример #8
0
// "new_account" can be the same with "account"!
int mod_account(const char *const account, const char *const new_account, const char *const new_password) {
	disk_info_t *disk_list, *follow_disk;
	partition_info_t *follow_partition;
	int i, acc_num = 0;
	char **account_list = NULL;
	char nvram_name[16];
	int account_order = -1;
	char var_file[256], new_var_file[256];
	
	if (account == NULL || strlen(account) <= 0) {
		return -1;
	}
	if ((new_account == NULL || strlen(new_account) <= 0) &&
			(new_password == NULL || strlen(new_password) <= 0)) {
		return -1;
	}
	
	// 1. check if can modify the account
	get_account_list(&acc_num, &account_list);
	
	for (i = 0; i < acc_num; ++i) {
		if (new_account != NULL && strcmp(new_account, account) && strlen(new_account) > 0) {
			if (!strcmp(account_list[i], new_account)) {
				free_2_dimension_list(&acc_num, &account_list);
				
				return -1;
			}
		}
		
		if (!strcmp(account, account_list[i]))
			account_order = i;
	}
	free_2_dimension_list(&acc_num, &account_list);
	
	if (account_order == -1) {
		return -1;
	}
	
	if (!strcmp(new_account, FTP_ANONYMOUS_USER)) {
		return -1;
	}
	
	// 2. modify nvram value about the new account
	if (new_account != NULL && strcmp(new_account, account) && strlen(new_account) > 0) {
		sprintf(nvram_name, "acc_username%d", account_order);
		nvram_set(nvram_name, new_account);
	}
	
	if (new_password != NULL && strlen(new_password) > 0) {
		sprintf(nvram_name, "acc_password%d", account_order);
		nvram_set(nvram_name, new_password);
	}
	
	nvram_commit_safe();
	
	// 3. find every pool
	if (new_account == NULL || strlen(new_account) <= 0/* ||
			(new_account != NULL && !strcmp(new_account, account))*/)
		return 0;

	if ((new_account != NULL && !strcmp(new_account, account)))
		goto rerun;

	disk_list = read_disk_data();
	if (!disk_list)
		return 0;
	
	for (follow_disk = disk_list; follow_disk != NULL; follow_disk = follow_disk->next) {
		for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
			if (follow_partition->mount_point == NULL)
				continue;
			
			// get the var_file and new_var_file
			snprintf(var_file, sizeof(var_file), "%s/.__%s_var.txt", follow_partition->mount_point, account);
			snprintf(new_var_file, sizeof(new_var_file), "%s/.__%s_var.txt", follow_partition->mount_point, new_account);
			
			// rename the var file
			rename(var_file, new_var_file);
		}
	}
rerun:
	// 6. re-run ftp and samba
	system("/sbin/run_ftpsamba");
	
	return 0;
}
Пример #9
0
int del_account(const char *const account) {
	disk_info_t *disk_list, *follow_disk;
	partition_info_t *follow_partition;
	int acc_num = 0, target;
	char **account_list = NULL;
	int result, i;
	char nvram_name[16], nvram_value[128];
	char var_file[256];
	
	if (account == NULL || strlen(account) <= 0) {
		return -1;
	}
	
	// 1. check if can create the account
	get_account_list(&acc_num, &account_list);
	if (acc_num <= 0)
		return -1;
	
	result = 0;
	for (i = 0; i < acc_num; ++i)
		if (!strcmp(account_list[i], account)) {
			result = 1;
			target = i;
			break;
		}
	if (result == 0) {
		free_2_dimension_list(&acc_num, &account_list);
		return -1;
	}
	
	// 2. delete the nvram value about the deleted account
	--acc_num;
	nvram_set_int("acc_num", acc_num);
	
	for (i = target; i < acc_num; ++i) {
		sprintf(nvram_name, "acc_username%d", i);
		nvram_set(nvram_name, account_list[i+1]);
		
		sprintf(nvram_value, "acc_password%d", i+1);
		
		sprintf(nvram_name, "acc_password%d", i);
		nvram_set(nvram_name, nvram_safe_get(nvram_value));
	}
	
	// 3. change to the share mode when no account
	if (acc_num < 1) {
		int i_mode;
		
		i_mode = nvram_get_int("st_samba_mode");
		if (i_mode != 1 && i_mode != 3)
			nvram_set_int("st_samba_mode", 1);
		
		i_mode = nvram_get_int("st_ftp_mode");
		if (i_mode != 1 && i_mode != 3)
			nvram_set_int("st_ftp_mode", 1);
	}
	
	nvram_commit_safe();
	
	free_2_dimension_list(&acc_num, &account_list);
	
	// 4. find every pool
	disk_list = read_disk_data();
	if (!disk_list)
		return 0;
	
	for (follow_disk = disk_list; follow_disk != NULL; follow_disk = follow_disk->next) {
		for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
			if (follow_partition->mount_point == NULL)
				continue;
			
			// 5. delete the var file of the deleted account
			snprintf(var_file, sizeof(var_file), "%s/.__%s_var.txt", follow_partition->mount_point, account);
			
			unlink(var_file);
		}
	}
	free_disk_data(disk_list);
	
	// 6. re-run ftp and samba
	system("/sbin/run_ftpsamba");
	
	return 0;
}
Пример #10
0
int add_account(const char *const account, const char *const password) {
	disk_info_t *disk_list, *follow_disk;
	partition_info_t *follow_partition;
	int i, acc_num = 0;
	char **account_list = NULL;
	char nvram_name[32];
	
	if (account == NULL || strlen(account) <= 0) {
		return -1;
	}
	if (password == NULL || strlen(password) <= 0) {
		return -1;
	}
	
	// 1. check if can create the account
	get_account_list(&acc_num, &account_list);
	if (acc_num >= MAX_ACCOUNT_NUM) {
		free_2_dimension_list(&acc_num, &account_list);
		return -1;
	}
	
	for (i = 0; i < acc_num; ++i)
		if (!strcmp(account, account_list[i])) {
			free_2_dimension_list(&acc_num, &account_list);
			return -1;
		}
	
	if (!strcmp(account, FTP_ANONYMOUS_USER)) {
		free_2_dimension_list(&acc_num, &account_list);
		return -1;
	}
	
	// 2. create nvram value about the new account
	nvram_set_int("acc_num", acc_num+1);
	
	sprintf(nvram_name, "acc_username%d", acc_num);
	nvram_set(nvram_name, account);
	
	sprintf(nvram_name, "acc_password%d", acc_num);
	nvram_set(nvram_name, password);
	
	nvram_commit_safe();
	
	free_2_dimension_list(&acc_num, &account_list);
	
	// 3. find every pool
	disk_list = read_disk_data();
	if (!disk_list)
		return 0;
	
	for (follow_disk = disk_list; follow_disk != NULL; follow_disk = follow_disk->next) {			
		for (follow_partition = follow_disk->partitions; follow_partition != NULL; follow_partition = follow_partition->next) {
			if (follow_partition->mount_point == NULL)
				continue;
			
			// 4. initial the var file of the account
			initial_one_var_file_in_mount_path(account, follow_partition->mount_point);
		}
	}
	free_disk_data(disk_list);
	
	// 6. re-run samba
	system("/sbin/run_samba");
	
	return 0;
}