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; }
int main(int argc, char *argv[]){ char *command; int i, num; char **list; int layer, right; char *mount_path, *share; int result; if((command = rindex(argv[0], '/')) != NULL) ++command; else command = argv[0]; if(!strcmp(command, "get_account_list")){ if(get_account_list(&num, &list) <= 0) usb_dbg("Can't get account list.\n"); else{ for(i = 0; i < num; ++i) usb_dbg("%dth account: %s.\n", i+1, list[i]); free_2_dimension_list(&num, &list); } } else if(!strcmp(command, "get_folder_list")){ if(argc != 2) usb_dbg("Usage: get_folder_list mount_path\n"); else if(get_folder_list(argv[1], &num, &list) < 0) usb_dbg("Can't get folder list.\n"); else{ for(i = 0; i < num; ++i) usb_dbg("%dth folder: %s.\n", i+1, list[i]); free_2_dimension_list(&num, &list); } } else if(!strcmp(command, "get_all_folder")){ if(argc != 2) usb_dbg("Usage: get_all_folder mount_path\n"); else if(get_all_folder(argv[1], &num, &list) < 0) usb_dbg("Can't get all folder.\n"); else{ for(i = 0; i < num; ++i) usb_dbg("%dth folder: %s.\n", i+1, list[i]); free_2_dimension_list(&num, &list); } } else if(!strcmp(command, "get_var_file_name")){ char *file_name; if(argc != 3) usb_dbg("Usage: get_var_file_name account mount_path\n"); else if(get_var_file_name(argv[1], argv[2], &file_name)) usb_dbg("Can't get the var file name with %s in %s.\n", argv[1], argv[2]); else{ usb_dbg("done: %s.\n", file_name); free(file_name); } } else if(!strcmp(command, "initial_folder_list")){ if(argc != 2) usb_dbg("Usage: initial_folder_list mount_path\n"); else if(initial_folder_list(argv[1]) < 0) usb_dbg("Can't initial folder list in %s.\n", argv[1]); else usb_dbg("done.\n"); } else if(!strcmp(command, "initial_var_file")){ char *target_acc = NULL; if(argc != 3){ usb_dbg("Usage: initial_var_file account mount_path\n"); return -1; } if(strcmp(argv[1], "NULL")) target_acc = argv[1]; if(initial_var_file(target_acc, argv[2]) < 0){ if(target_acc == NULL) usb_dbg("Can't initial share's var file in %s.\n", argv[2]); else usb_dbg("Can't initial %s's var file in %s.\n", target_acc, argv[2]); } else usb_dbg("done.\n"); } else if(!strcmp(command, "initial_all_var_file")){ if(argc != 2) usb_dbg("Usage: initial_all_var_file mount_path\n"); else if(initial_all_var_file(argv[1]) < 0) usb_dbg("Can't initial all var file in %s.\n", argv[1]); else usb_dbg("done.\n"); } else if(!strcmp(command, "test_of_var_files")){ if(argc != 2) usb_dbg("Usage: test_of_var_files mount_path\n"); else if(test_of_var_files(argv[1]) < 0) usb_dbg("Can't test_of_var_files in %s.\n", argv[1]); else usb_dbg("done.\n"); } else if(!strcmp(command, "create_if_no_var_files")){ if(argc != 2) usb_dbg("Usage: create_if_no_var_files mount_path\n"); else if(create_if_no_var_files(argv[1]) < 0) usb_dbg("Can't create var files in %s.\n", argv[1]); else usb_dbg("done.\n"); } else if(!strcmp(command, "modify_if_exist_new_folder")){ if(argc != 3) usb_dbg("Usage: modify_if_exist_new_folder account mount_path\n"); else if(modify_if_exist_new_folder(argv[1], argv[2]) < 0) usb_dbg("Can't fix %s's var files in %s.\n", argv[1], argv[2]); else usb_dbg("done.\n"); } else if(!strcmp(command, "get_permission")){ if(argc != 5) usb_dbg("Usage: get_permission account mount_path folder [cifs|ftp|dms]\n"); else if((right = get_permission(argv[1], argv[2], argv[3], argv[4])) < 0) usb_dbg("%s can't get %s's %s permission in %s.\n", argv[1], argv[3], argv[4], argv[2]); else usb_dbg("done: %d.\n", right); } else if(!strcmp(command, "set_permission")){ if(argc != 6) usb_dbg("Usage: set_permission account mount_path folder [cifs|ftp|dms] [0~3]\n"); else if(set_permission(argv[1], argv[2], argv[3], argv[4], atoi(argv[5])) < 0) usb_dbg("%s can't set %s's %s permission to be %s in %s.\n", argv[1], argv[3], argv[4], argv[5], argv[2]); else usb_dbg("done.\n"); } else if(!strcmp(command, "add_account")){ if(argc != 3) usb_dbg("Usage: add_account account password\n"); else if(add_account(argv[1], argv[2]) < 0) usb_dbg("Can't add account(%s:%s).\n", argv[1], argv[2]); else usb_dbg("done.\n"); } else if(!strcmp(command, "del_account")){ if(argc != 2) usb_dbg("Usage: del_account account\n"); else if(del_account(argv[1]) < 0) usb_dbg("Can't del account(%s).\n", argv[1]); else usb_dbg("done.\n"); } else if(!strcmp(command, "mod_account")){ if(argc != 4) usb_dbg("Usage: mod_account account new_account new_password\n"); else if(mod_account(argv[1], argv[2], argv[3]) < 0) usb_dbg("Can't mod account(%s) to (%s:%s).\n", argv[1], argv[2], argv[3]); else usb_dbg("done.\n"); } else if(!strcmp(command, "test_if_exist_account")){ if(argc != 2) usb_dbg("Usage: test_if_exist_account account\n"); else if(test_if_exist_account(argv[1]) < 0) usb_dbg("Can't test if %s is existed.\n", argv[1]); else usb_dbg("done.\n"); } else if(!strcmp(command, "add_folder")){ if(argc != 4){ usb_dbg("Usage: add_folder account mount_path folder\n"); return 0; } if(!strcmp(argv[1], "NULL")) result = add_folder(NULL, argv[2], argv[3]); else result = add_folder(argv[1], argv[2], argv[3]); if(result < 0) usb_dbg("Can't add folder(%s) in %s.\n", argv[3], argv[2]); else usb_dbg("done.\n"); } else if(!strcmp(command, "del_folder")){ if(argc != 3) usb_dbg("Usage: del_folder mount_path folder\n"); else if(del_folder(argv[1], argv[2]) < 0) usb_dbg("Can't del folder(%s) in %s.\n", argv[2], argv[1]); else usb_dbg("done.\n"); } else if(!strcmp(command, "mod_folder")){ if(argc != 4) usb_dbg("Usage: mod_folder mount_path folder new_folder\n"); else if(mod_folder(argv[1], argv[2], argv[3]) < 0) usb_dbg("Can't mod folder(%s) to (%s) in %s.\n", argv[2], argv[3], argv[1]); else usb_dbg("done.\n"); } else if(!strcmp(command, "test_if_exist_share")){ if(argc != 3) usb_dbg("Usage: test_if_exist_share mount_path folder\n"); else if(test_if_exist_share(argv[1], argv[2])) usb_dbg("%s is existed in %s.\n", argv[2], argv[1]); else usb_dbg("%s is NOT existed in %s.\n", argv[2], argv[1]); } else if(!strcmp(command, "how_many_layer")){ if(argc != 2) usb_dbg("Usage: how_many_layer path\n"); else if((layer = how_many_layer(argv[1], &mount_path, &share)) < 0) usb_dbg("Can't count the layer with %s.\n", argv[1]); else usb_dbg("done: %d layers, share=%s, mount_path=%s.\n", layer, share, mount_path); } else usb_dbg("test_share(ver. %d): Need to link the command name from test_share first.\n", VERSION); return 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; }
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; }