static void cxacru_upload_firmware(struct cxacru_data *instance, const struct firmware *fw, const struct firmware *bp) { int ret; struct usbatm_data *usbatm = instance->usbatm; struct usb_device *usb_dev = usbatm->usb_dev; __le16 signature[] = { usb_dev->descriptor.idVendor, usb_dev->descriptor.idProduct }; __le32 val; usb_dbg(usbatm, "%s\n", __func__); /* FirmwarePllFClkValue */ val = cpu_to_le32(instance->modem_type->pll_f_clk); ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4); if (ret) { usb_err(usbatm, "FirmwarePllFClkValue failed: %d\n", ret); return; } /* FirmwarePllBClkValue */ val = cpu_to_le32(instance->modem_type->pll_b_clk); ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4); if (ret) { usb_err(usbatm, "FirmwarePllBClkValue failed: %d\n", ret); return; } /* Enable SDRAM */ val = cpu_to_le32(SDRAM_ENA); ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4); if (ret) { usb_err(usbatm, "Enable SDRAM failed: %d\n", ret); return; } /* Firmware */ usb_info(usbatm, "loading firmware\n"); ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size); if (ret) { usb_err(usbatm, "Firmware upload failed: %d\n", ret); return; } /* Boot ROM patch */ if (instance->modem_type->boot_rom_patch) { usb_info(usbatm, "loading boot ROM patch\n"); ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size); if (ret) { usb_err(usbatm, "Boot ROM patching failed: %d\n", ret); return; } } /* Signature */ ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) signature, 4); if (ret) { usb_err(usbatm, "Signature storing failed: %d\n", ret); return; } usb_info(usbatm, "starting device\n"); if (instance->modem_type->boot_rom_patch) { val = cpu_to_le32(BR_ADDR); ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4); } else { ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0); } if (ret) { usb_err(usbatm, "Passing control to firmware failed: %d\n", ret); return; } /* Delay to allow firmware to start up. */ msleep_interruptible(1000); usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD)); usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_CMD)); usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_DATA)); usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_DATA)); ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0); if (ret < 0) { usb_err(usbatm, "modem failed to initialize: %d\n", ret); return; } }
static int speedtch_upload_firmware(struct speedtch_instance_data *instance, const struct firmware *fw1, const struct firmware *fw2) { unsigned char *buffer; struct usbatm_data *usbatm = instance->usbatm; struct usb_device *usb_dev = usbatm->usb_dev; int actual_length; int ret = 0; int offset; usb_dbg(usbatm, "%s entered\n", __func__); if (!(buffer = (unsigned char *)__get_free_page(GFP_KERNEL))) { ret = -ENOMEM; usb_dbg(usbatm, "%s: no memory for buffer!\n", __func__); goto out; } if (!usb_ifnum_to_if(usb_dev, 2)) { ret = -ENODEV; usb_dbg(usbatm, "%s: interface not found!\n", __func__); goto out_free; } /* URB 7 */ if (dl_512_first) { /* some modems need a read before writing the firmware */ ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), buffer, 0x200, &actual_length, 2000); if (ret < 0 && ret != -ETIMEDOUT) usb_warn(usbatm, "%s: read BLOCK0 from modem failed (%d)!\n", __func__, ret); else usb_dbg(usbatm, "%s: BLOCK0 downloaded (%d bytes)\n", __func__, ret); } /* URB 8 : both leds are static green */ for (offset = 0; offset < fw1->size; offset += PAGE_SIZE) { int thislen = min_t(int, PAGE_SIZE, fw1->size - offset); memcpy(buffer, fw1->data + offset, thislen); ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE), buffer, thislen, &actual_length, DATA_TIMEOUT); if (ret < 0) { usb_err(usbatm, "%s: write BLOCK1 to modem failed (%d)!\n", __func__, ret); goto out_free; } usb_dbg(usbatm, "%s: BLOCK1 uploaded (%zu bytes)\n", __func__, fw1->size); } /* USB led blinking green, ADSL led off */ /* URB 11 */ ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), buffer, 0x200, &actual_length, DATA_TIMEOUT); if (ret < 0) { usb_err(usbatm, "%s: read BLOCK2 from modem failed (%d)!\n", __func__, ret); goto out_free; } usb_dbg(usbatm, "%s: BLOCK2 downloaded (%d bytes)\n", __func__, actual_length); /* URBs 12 to 139 - USB led blinking green, ADSL led off */ for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) { int thislen = min_t(int, PAGE_SIZE, fw2->size - offset); memcpy(buffer, fw2->data + offset, thislen); ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE), buffer, thislen, &actual_length, DATA_TIMEOUT); if (ret < 0) { usb_err(usbatm, "%s: write BLOCK3 to modem failed (%d)!\n", __func__, ret); goto out_free; } } usb_dbg(usbatm, "%s: BLOCK3 uploaded (%zu bytes)\n", __func__, fw2->size); /* USB led static green, ADSL led static red */ /* URB 142 */ ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), buffer, 0x200, &actual_length, DATA_TIMEOUT); if (ret < 0) { usb_err(usbatm, "%s: read BLOCK4 from modem failed (%d)!\n", __func__, ret); goto out_free; } /* success */ usb_dbg(usbatm, "%s: BLOCK4 downloaded (%d bytes)\n", __func__, actual_length); /* Delay to allow firmware to start up. We can do this here because we're in our own kernel thread anyway. */ msleep_interruptible(1000); if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, instance->params.altsetting)) < 0) { usb_err(usbatm, "%s: setting interface to %d failed (%d)!\n", __func__, instance->params.altsetting, ret); goto out_free; } /* Enable software buffering, if requested */ if (sw_buffering) speedtch_set_swbuff(instance, 1); /* Magic spell; don't ask us what this does */ speedtch_test_sequence(instance); ret = 0; out_free: free_page((unsigned long)buffer); out: return ret; }
disk_info_t *read_disk_data(){ disk_info_t *disk_info_list = NULL, *new_disk_info, **follow_disk_info_list; char *partition_info = read_whole_file(PARTITION_FILE); char *follow_info; char line[64], device_name[16]; u32 major; disk_info_t *parent_disk_info; partition_info_t *new_partition_info, **follow_partition_list; u64 device_size; if(partition_info == NULL){ usb_dbg("Failed to open \"%s\"!!\n", PARTITION_FILE); return disk_info_list; } follow_info = partition_info; memset(device_name, 0, 16); while(get_line_from_buffer(follow_info, line, 64) != NULL){ follow_info += strlen(line); if(sscanf(line, "%u %*u %llu %[^\n ]", &major, &device_size, device_name) != 3) continue; if(major != USB_DISK_MAJOR) continue; if(device_size == 1) // extend partition. continue; if(is_disk_name(device_name)){ // Disk follow_disk_info_list = &disk_info_list; while(*follow_disk_info_list != NULL) follow_disk_info_list = &((*follow_disk_info_list)->next); new_disk_info = create_disk(device_name, follow_disk_info_list); } else if(is_partition_name(device_name, NULL)){ // Partition // Found a partition device. // Find the parent disk. parent_disk_info = disk_info_list; while(1){ if(parent_disk_info == NULL){ usb_dbg("Error while parsing %s: found " "partition '%s' but haven't seen the disk device " "of which it is a part.\n", PARTITION_FILE, device_name); free(partition_info); return disk_info_list; } if(!strncmp(device_name, parent_disk_info->device, 3)) break; parent_disk_info = parent_disk_info->next; } follow_partition_list = &(parent_disk_info->partitions); while(*follow_partition_list != NULL){ if((*follow_partition_list)->partition_order == 0){ free_partition_data(follow_partition_list); parent_disk_info->partitions = NULL; follow_partition_list = &(parent_disk_info->partitions); } else follow_partition_list = &((*follow_partition_list)->next); } new_partition_info = create_partition(device_name, follow_partition_list); if(new_partition_info != NULL) new_partition_info->disk = parent_disk_info; } } free(partition_info); return disk_info_list; }
static int parse_configuration(struct libusb_context *ctx, struct libusb_config_descriptor *config, unsigned char *buffer, int host_endian) { int i; int r; int size; size_t tmp; struct usb_descriptor_header header; struct libusb_interface *usb_interface; usb_parse_descriptor(buffer, "bbwbbbbb", config, host_endian); size = config->wTotalLength; if (config->bNumInterfaces > USB_MAXINTERFACES) { usb_err(ctx, "too many interfaces (%d)", config->bNumInterfaces); return LIBUSB_ERROR_IO; } tmp = config->bNumInterfaces * sizeof(struct libusb_interface); usb_interface = malloc(tmp); config->interface = usb_interface; if (!config->interface) return LIBUSB_ERROR_NO_MEM; memset(usb_interface, 0, tmp); buffer += config->bLength; size -= config->bLength; config->extra = NULL; config->extra_length = 0; for (i = 0; i < config->bNumInterfaces; i++) { int len; unsigned char *begin; /* Skip over the rest of the Class Specific or Vendor */ /* Specific descriptors */ begin = buffer; while (size >= DESC_HEADER_LENGTH) { usb_parse_descriptor(buffer, "bb", &header, 0); if ((header.bLength > size) || (header.bLength < DESC_HEADER_LENGTH)) { usb_err(ctx, "invalid descriptor length of %d", header.bLength); r = LIBUSB_ERROR_IO; goto err; } /* If we find another "proper" descriptor then we're done */ if ((header.bDescriptorType == LIBUSB_DT_ENDPOINT) || (header.bDescriptorType == LIBUSB_DT_INTERFACE) || (header.bDescriptorType == LIBUSB_DT_CONFIG) || (header.bDescriptorType == LIBUSB_DT_DEVICE)) break; usb_dbg("skipping descriptor 0x%x\n", header.bDescriptorType); buffer += header.bLength; size -= header.bLength; } /* Copy any unknown descriptors into a storage area for */ /* drivers to later parse */ len = (int)(buffer - begin); if (len) { /* FIXME: We should realloc and append here */ if (!config->extra_length) { config->extra = malloc(len); if (!config->extra) { r = LIBUSB_ERROR_NO_MEM; goto err; } memcpy((unsigned char *) config->extra, begin, len); config->extra_length = len; } } r = parse_interface(ctx, usb_interface + i, buffer, size, host_endian); if (r < 0) goto err; buffer += r; size -= r; } return size; err: clear_configuration(config); return r; }
int read_mount_data(const char *device_name , char *mount_point, int mount_len , char *type, int type_len , char *right, int right_len ){ char *mount_info = read_whole_file(MOUNT_FILE); char *start, line[PATH_MAX]; char target[8]; if(mount_point == NULL || mount_len <= 0 || type == NULL || type_len <= 0 || right == NULL || right_len <= 0 ){ usb_dbg("Bad input!!\n"); return 0; } if(mount_info == NULL){ usb_dbg("Failed to open \"%s\"!!\n", MOUNT_FILE); return 0; } memset(target, 0, 8); sprintf(target, "%s ", device_name); if((start = strstr(mount_info, target)) == NULL){ //usb_dbg("disk_initial:: %s: Failed to execute strstr()!\n", device_name); free(mount_info); return 0; } start += strlen(target); if(get_line_from_buffer(start, line, PATH_MAX) == NULL){ usb_dbg("%s: Failed to execute get_line_from_buffer()!\n", device_name); free(mount_info); return 0; } memset(mount_point, 0, mount_len); memset(type, 0, type_len); memset(right, 0, right_len); if(sscanf(line, "%s %s %[^\n ]", mount_point, type, right) != 3){ usb_dbg("%s: Failed to execute sscanf()!\n", device_name); free(mount_info); return 0; } if(!strcmp(type, "ufsd")){ char full_dev[16]; memset(full_dev, 0, 16); sprintf(full_dev, "/dev/%s", device_name); memset(type, 0, type_len); strcpy(type, detect_fs_type(full_dev)); } right[2] = 0; free(mount_info); return 1; }
void print_partition(const partition_info_t *const partition_info){ if(partition_info == NULL){ usb_dbg("No partition!\n"); return; } usb_dbg("Partition:\n"); if(partition_info->disk != NULL) usb_dbg(" Parent disk: %s.\n", partition_info->disk->device); usb_dbg(" device: %s.\n", partition_info->device); usb_dbg(" label: %s.\n", partition_info->label); usb_dbg(" partition_order: %u.\n", partition_info->partition_order); usb_dbg(" mount_point: %s.\n", partition_info->mount_point); usb_dbg(" file_system: %s.\n", partition_info->file_system); usb_dbg(" permission: %s.\n", partition_info->permission); usb_dbg("size_in_kilobytes: %llu.\n", partition_info->size_in_kilobytes); usb_dbg(" used_kilobytes: %llu.\n", partition_info->used_kilobytes); }
static ssize_t chaoskey_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) { struct chaoskey *dev; ssize_t read_count = 0; int this_time; int result = 0; unsigned long remain; dev = file->private_data; if (dev == NULL || !dev->present) return -ENODEV; usb_dbg(dev->interface, "read %zu", count); while (count > 0) { /* Grab the rng_lock briefly to ensure that the hwrng interface * gets priority over other user access */ result = mutex_lock_interruptible(&dev->rng_lock); if (result) goto bail; mutex_unlock(&dev->rng_lock); result = mutex_lock_interruptible(&dev->lock); if (result) goto bail; if (dev->valid == dev->used) { result = _chaoskey_fill(dev); if (result < 0) { mutex_unlock(&dev->lock); goto bail; } } this_time = dev->valid - dev->used; if (this_time > count) this_time = count; remain = copy_to_user(buffer, dev->buf + dev->used, this_time); if (remain) { result = -EFAULT; /* Consume the bytes that were copied so we don't leak * data to user space */ dev->used += this_time - remain; mutex_unlock(&dev->lock); goto bail; } count -= this_time; read_count += this_time; buffer += this_time; dev->used += this_time; mutex_unlock(&dev->lock); } bail: if (read_count) { usb_dbg(dev->interface, "read %zu bytes", read_count); return read_count; } usb_dbg(dev->interface, "empty read, result %d", result); if (result == -ETIMEDOUT) result = -EAGAIN; return result; }
int mdev_tty_main(int argc, char **argv) { FILE *fp; int isLock, devnum, has_int_pipe; char usb_port_id[64], usb_interface_id[64], node_fname[64]; const char *device_name, *action; if(argc != 3){ printf("Usage: %s [device_name] [action]\n", argv[0]); return 0; } device_name = argv[1]; action = argv[2]; usb_dbg("(%s): action=%s.\n", device_name, action); if (!isSerialNode(device_name) && !isACMNode(device_name)) return 0; sprintf(node_fname, "%s/%s", MODEM_NODE_DIR, device_name); // Check Lock. if((isLock = file_lock((char *)device_name)) == -1) return 0; // If remove the device? if(!check_hotplug_action(action)){ unlink(node_fname); if (get_usb_modem_wan(0)) notify_rc("on_unplug_usb_modem"); usb_dbg("(%s): Remove the modem node\n", device_name); goto out_unlock; } // Get DevNum devnum = 0; has_int_pipe = 0; usb_port_id[0] = 0; if (get_interface_by_device(device_name, usb_interface_id, sizeof(usb_interface_id))) { has_int_pipe = get_interface_Int_endpoint(usb_interface_id); if (get_usb_port_by_interface_string(usb_interface_id, usb_port_id, sizeof(usb_port_id))) devnum = get_usb_devnum(usb_port_id); } // Write node file. mkdir_if_none(MODEM_NODE_DIR); fp = fopen(node_fname, "w+"); if (fp) { fprintf(fp, "pref=%d\n", (has_int_pipe) ? 1 : 0); fprintf(fp, "devnum=%d\n", devnum); fprintf(fp, "portid=%s\n", usb_port_id); fclose(fp); } if (nvram_invmatch("modem_arun", "0") && nvram_match("modem_rule", "1") && nvram_invmatch("modem_type", "3")) notify_rc("on_hotplug_usb_modem"); usb_dbg("(%s): Success!\n", device_name); out_unlock: file_unlock(isLock); return 1; }
static int chaoskey_probe(struct usb_interface *interface, const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(interface); struct usb_host_interface *altsetting = interface->cur_altsetting; struct usb_endpoint_descriptor *epd; int in_ep; struct chaoskey *dev; int result = -ENOMEM; int size; int res; usb_dbg(interface, "probe %s-%s", udev->product, udev->serial); /* Find the first bulk IN endpoint and its packet size */ res = usb_find_bulk_in_endpoint(altsetting, &epd); if (res) { usb_dbg(interface, "no IN endpoint found"); return res; } in_ep = usb_endpoint_num(epd); size = usb_endpoint_maxp(epd); /* Validate endpoint and size */ if (size <= 0) { usb_dbg(interface, "invalid size (%d)", size); return -ENODEV; } if (size > CHAOSKEY_BUF_LEN) { usb_dbg(interface, "size reduced from %d to %d\n", size, CHAOSKEY_BUF_LEN); size = CHAOSKEY_BUF_LEN; } /* Looks good, allocate and initialize */ dev = kzalloc(sizeof(struct chaoskey), GFP_KERNEL); if (dev == NULL) goto out; dev->buf = kmalloc(size, GFP_KERNEL); if (dev->buf == NULL) goto out; dev->urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->urb) goto out; usb_fill_bulk_urb(dev->urb, udev, usb_rcvbulkpipe(udev, in_ep), dev->buf, size, chaos_read_callback, dev); /* Construct a name using the product and serial values. Each * device needs a unique name for the hwrng code */ if (udev->product && udev->serial) { dev->name = kmalloc(strlen(udev->product) + 1 + strlen(udev->serial) + 1, GFP_KERNEL); if (dev->name == NULL) goto out; strcpy(dev->name, udev->product); strcat(dev->name, "-"); strcat(dev->name, udev->serial); } dev->interface = interface; dev->in_ep = in_ep; if (le16_to_cpu(udev->descriptor.idVendor) != ALEA_VENDOR_ID) dev->reads_started = 1; dev->size = size; dev->present = 1; init_waitqueue_head(&dev->wait_q); mutex_init(&dev->lock); mutex_init(&dev->rng_lock); usb_set_intfdata(interface, dev); result = usb_register_dev(interface, &chaoskey_class); if (result) { usb_err(interface, "Unable to allocate minor number."); goto out; } dev->hwrng.name = dev->name ? dev->name : chaoskey_driver.name; dev->hwrng.read = chaoskey_rng_read; dev->hwrng.quality = 1024; dev->hwrng_registered = (hwrng_register(&dev->hwrng) == 0); if (!dev->hwrng_registered) usb_err(interface, "Unable to register with hwrng"); usb_enable_autosuspend(udev); usb_dbg(interface, "chaoskey probe success, size %d", dev->size); return 0; out: usb_set_intfdata(interface, NULL); chaoskey_free(dev); return result; }
/* Fill the buffer. Called with dev->lock held */ static int _chaoskey_fill(struct chaoskey *dev) { DEFINE_WAIT(wait); int result; bool started; usb_dbg(dev->interface, "fill"); /* Return immediately if someone called before the buffer was * empty */ if (dev->valid != dev->used) { usb_dbg(dev->interface, "not empty yet (valid %d used %d)", dev->valid, dev->used); return 0; } /* Bail if the device has been removed */ if (!dev->present) { usb_dbg(dev->interface, "device not present"); return -ENODEV; } /* Make sure the device is awake */ result = usb_autopm_get_interface(dev->interface); if (result) { usb_dbg(dev->interface, "wakeup failed (result %d)", result); return result; } dev->reading = true; result = usb_submit_urb(dev->urb, GFP_KERNEL); if (result < 0) { result = usb_translate_errors(result); dev->reading = false; goto out; } /* The first read on the Alea takes a little under 2 seconds. * Reads after the first read take only a few microseconds * though. Presumably the entropy-generating circuit needs * time to ramp up. So, we wait longer on the first read. */ started = dev->reads_started; dev->reads_started = true; result = wait_event_interruptible_timeout( dev->wait_q, !dev->reading, (started ? NAK_TIMEOUT : ALEA_FIRST_TIMEOUT) ); if (result < 0) goto out; if (result == 0) result = -ETIMEDOUT; else result = dev->valid; out: /* Let the device go back to sleep eventually */ usb_autopm_put_interface(dev->interface); usb_dbg(dev->interface, "read %d bytes", dev->valid); return result; }
static int chaoskey_probe(struct usb_interface *interface, const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(interface); struct usb_host_interface *altsetting = interface->cur_altsetting; int i; int in_ep = -1; struct chaoskey *dev; int result; int size; usb_dbg(interface, "probe %s-%s", udev->product, udev->serial); /* Find the first bulk IN endpoint and its packet size */ for (i = 0; i < altsetting->desc.bNumEndpoints; i++) { if (usb_endpoint_is_bulk_in(&altsetting->endpoint[i].desc)) { in_ep = usb_endpoint_num(&altsetting->endpoint[i].desc); size = usb_endpoint_maxp(&altsetting->endpoint[i].desc); break; } } /* Validate endpoint and size */ if (in_ep == -1) { usb_dbg(interface, "no IN endpoint found"); return -ENODEV; } if (size <= 0) { usb_dbg(interface, "invalid size (%d)", size); return -ENODEV; } if (size > CHAOSKEY_BUF_LEN) { usb_dbg(interface, "size reduced from %d to %d\n", size, CHAOSKEY_BUF_LEN); size = CHAOSKEY_BUF_LEN; } /* Looks good, allocate and initialize */ dev = kzalloc(sizeof(struct chaoskey), GFP_KERNEL); if (dev == NULL) return -ENOMEM; dev->buf = kmalloc(size, GFP_KERNEL); if (dev->buf == NULL) { kfree(dev); return -ENOMEM; } /* Construct a name using the product and serial values. Each * device needs a unique name for the hwrng code */ if (udev->product && udev->serial) { dev->name = kmalloc(strlen(udev->product) + 1 + strlen(udev->serial) + 1, GFP_KERNEL); if (dev->name == NULL) { kfree(dev->buf); kfree(dev); return -ENOMEM; } strcpy(dev->name, udev->product); strcat(dev->name, "-"); strcat(dev->name, udev->serial); } dev->interface = interface; dev->in_ep = in_ep; dev->size = size; dev->present = 1; init_waitqueue_head(&dev->wait_q); mutex_init(&dev->lock); mutex_init(&dev->rng_lock); usb_set_intfdata(interface, dev); result = usb_register_dev(interface, &chaoskey_class); if (result) { usb_err(interface, "Unable to allocate minor number."); usb_set_intfdata(interface, NULL); chaoskey_free(dev); return result; } dev->hwrng.name = dev->name ? dev->name : chaoskey_driver.name; dev->hwrng.read = chaoskey_rng_read; /* Set the 'quality' metric. Quality is measured in units of * 1/1024's of a bit ("mills"). This should be set to 1024, * but there is a bug in the hwrng core which masks it with * 1023. * * The patch that has been merged to the crypto development * tree for that bug limits the value to 1024 at most, so by * setting this to 1024 + 1023, we get 1023 before the fix is * merged and 1024 afterwards. We'll patch this driver once * both bits of code are in the same tree. */ dev->hwrng.quality = 1024 + 1023; dev->hwrng_registered = (hwrng_register(&dev->hwrng) == 0); if (!dev->hwrng_registered) usb_err(interface, "Unable to register with hwrng"); usb_enable_autosuspend(udev); usb_dbg(interface, "chaoskey probe success, size %d", dev->size); return 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; }
static int parse_endpoint(struct libusb_context *ctx, struct libusb_endpoint_descriptor *endpoint, unsigned char *buffer, int size, int host_endian) { struct usb_descriptor_header header; unsigned char *extra; unsigned char *begin; int parsed = 0; int len; usb_parse_descriptor(buffer, "bb", &header, 0); /* Everything should be fine being passed into here, but we sanity */ /* check JIC */ if (header.bLength > size) { usb_err(ctx, "ran out of descriptors parsing"); return -1; } if (header.bDescriptorType != LIBUSB_DT_ENDPOINT) { usb_err(ctx, "unexpected descriptor %x (expected %x)", header.bDescriptorType, LIBUSB_DT_ENDPOINT); return parsed; } if (header.bLength >= ENDPOINT_AUDIO_DESC_LENGTH) usb_parse_descriptor(buffer, "bbbbwbbb", endpoint, host_endian); else if (header.bLength >= ENDPOINT_DESC_LENGTH) usb_parse_descriptor(buffer, "bbbbwb", endpoint, host_endian); buffer += header.bLength; size -= header.bLength; parsed += header.bLength; /* Skip over the rest of the Class Specific or Vendor Specific */ /* descriptors */ begin = buffer; while (size >= DESC_HEADER_LENGTH) { usb_parse_descriptor(buffer, "bb", &header, 0); if (header.bLength < 2) { usb_err(ctx, "invalid descriptor length %d", header.bLength); return -1; } /* If we find another "proper" descriptor then we're done */ if ((header.bDescriptorType == LIBUSB_DT_ENDPOINT) || (header.bDescriptorType == LIBUSB_DT_INTERFACE) || (header.bDescriptorType == LIBUSB_DT_CONFIG) || (header.bDescriptorType == LIBUSB_DT_DEVICE)) break; usb_dbg("skipping descriptor %x", header.bDescriptorType); buffer += header.bLength; size -= header.bLength; parsed += header.bLength; } /* Copy any unknown descriptors into a storage area for drivers */ /* to later parse */ len = (int)(buffer - begin); if (!len) { endpoint->extra = NULL; endpoint->extra_length = 0; return parsed; } extra = malloc(len); endpoint->extra = extra; if (!extra) { endpoint->extra_length = 0; return LIBUSB_ERROR_NO_MEM; } memcpy(extra, begin, len); endpoint->extra_length = len; return parsed; }
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; }
static int chaoskey_suspend(struct usb_interface *interface, pm_message_t message) { usb_dbg(interface, "suspend"); return 0; }
int mdev_sd_main(int argc, char **argv) { char aidisk_cmd[64]; int isLock, mount_result; const char *device_name, *action; if(argc != 3){ printf("Usage: %s [device_name] [action]\n", argv[0]); return 0; } device_name = argv[1]; action = argv[2]; usb_dbg("(%s): action=%s.\n", device_name, action); if(get_device_type_by_device(device_name) != DEVICE_TYPE_DISK){ usb_dbg("(%s): The device is not a sd device.\n", device_name); return 0; } // Check Lock. if((isLock = file_lock((char *)device_name)) == -1){ usb_dbg("(%s): Can't set the file lock!\n", device_name); return 0; } // If remove the device? if(!check_hotplug_action(action)){ if (device_name[3] != '\0') detach_swap_partition((char*)device_name); else notify_rc("on_unplug_usb_storage"); file_unlock(isLock); return 0; } memset(aidisk_cmd, 0, sizeof(aidisk_cmd)); if (device_name[3] == '\0') // sda, sdb, sdc... { system("/sbin/hddtune.sh $MDEV"); if (!check_root_partition(device_name)) { sprintf(aidisk_cmd, "/sbin/automount.sh $MDEV AiDisk_%c%c", device_name[2], '1'); } else goto No_Need_To_Mount; } else { sprintf(aidisk_cmd, "/sbin/automount.sh $MDEV AiDisk_%c%c", device_name[2], device_name[3]); } umask(0000); mount_result = system(aidisk_cmd); if (mount_result == 0) { notify_rc("on_hotplug_usb_storage"); } usb_dbg("(%s): Success!\n", device_name); file_unlock(isLock); return 1; No_Need_To_Mount: usb_dbg("(%s): No need to mount!\n", device_name); file_unlock(isLock); return 0; }
static int chaoskey_resume(struct usb_interface *interface) { usb_dbg(interface, "resume"); return 0; }
partition_info_t *create_partition(const char *device_name, partition_info_t **new_part_info){ partition_info_t *follow_part_info; char label[128]; u32 partition_order = 0; u64 size_in_kilobytes = 0, total_kilobytes = 0, used_kilobytes = 0; char buf1[PATH_MAX], buf2[64], buf3[PATH_MAX]; // options of mount info needs more buffer size. int len; if(new_part_info == NULL){ usb_dbg("Bad input!!\n"); return NULL; } *new_part_info = NULL; // initial value. if(device_name == NULL || get_device_type_by_device(device_name) != DEVICE_TYPE_DISK) return NULL; if(!is_disk_name(device_name) && !is_partition_name(device_name, &partition_order)) return NULL; if(initial_part_data(&follow_part_info) == NULL){ usb_dbg("No memory!!(follow_part_info)\n"); return NULL; } len = strlen(device_name); follow_part_info->device = (char *)malloc(len+1); if(follow_part_info->device == NULL){ usb_dbg("No memory!!(follow_part_info->device)\n"); free_partition_data(&follow_part_info); return NULL; } strncpy(follow_part_info->device, device_name, len); follow_part_info->device[len] = 0; if(find_partition_label(device_name, label)){ strntrim(label); len = strlen(label); follow_part_info->label = (char *)malloc(len+1); if(follow_part_info->label == NULL){ usb_dbg("No memory!!(follow_part_info->label)\n"); free_partition_data(&follow_part_info); return NULL; } strncpy(follow_part_info->label, label, len); follow_part_info->label[len] = 0; } follow_part_info->partition_order = partition_order; if(read_mount_data(device_name, buf1, PATH_MAX, buf2, 64, buf3, PATH_MAX)){ len = strlen(buf1); follow_part_info->mount_point = (char *)malloc(len+1); if(follow_part_info->mount_point == NULL){ usb_dbg("No memory!!(follow_part_info->mount_point)\n"); free_partition_data(&follow_part_info); return NULL; } strncpy(follow_part_info->mount_point, buf1, len); follow_part_info->mount_point[len] = 0; len = strlen(buf2); follow_part_info->file_system = (char *)malloc(len+1); if(follow_part_info->file_system == NULL){ usb_dbg("No memory!!(follow_part_info->file_system)\n"); free_partition_data(&follow_part_info); return NULL; } strncpy(follow_part_info->file_system, buf2, len); follow_part_info->file_system[len] = 0; len = strlen(buf3); follow_part_info->permission = (char *)malloc(len+1); if(follow_part_info->permission == NULL){ usb_dbg("No memory!!(follow_part_info->permission)\n"); free_partition_data(&follow_part_info); return NULL; } strncpy(follow_part_info->permission, buf3, len); follow_part_info->permission[len] = 0; if(get_mount_size(follow_part_info->mount_point, &total_kilobytes, &used_kilobytes)){ follow_part_info->size_in_kilobytes = total_kilobytes; follow_part_info->used_kilobytes = used_kilobytes; } } else{ /*if(is_disk_name(device_name)){ // Disk free_partition_data(&follow_part_info); return NULL; } else{//*/ len = strlen(PARTITION_TYPE_UNKNOWN); follow_part_info->file_system = (char *)malloc(len+1); if(follow_part_info->file_system == NULL){ usb_dbg("No memory!!(follow_part_info->file_system)\n"); free_partition_data(&follow_part_info); return NULL; } strncpy(follow_part_info->file_system, PARTITION_TYPE_UNKNOWN, len); follow_part_info->file_system[len] = 0; get_partition_size(device_name, &size_in_kilobytes); follow_part_info->size_in_kilobytes = size_in_kilobytes; //} } *new_part_info = follow_part_info; return *new_part_info; }
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; }
void print_disk(const disk_info_t *const disk_info){ if(disk_info == NULL){ usb_dbg("No disk!\n"); return; } usb_dbg("Disk:\n"); usb_dbg(" tag: %s.\n", disk_info->tag); usb_dbg(" vendor: %s.\n", disk_info->vendor); usb_dbg(" model: %s.\n", disk_info->model); usb_dbg(" device: %s.\n", disk_info->device); usb_dbg(" major: %u.\n", disk_info->major); usb_dbg(" minor: %u.\n", disk_info->minor); usb_dbg(" port: %s.\n", disk_info->port); usb_dbg(" partition_number: %u.\n", disk_info->partition_number); usb_dbg(" mounted_number: %u.\n", disk_info->mounted_number); usb_dbg("size_in_kilobytes: %llu.\n", disk_info->size_in_kilobytes); print_partitions(disk_info->partitions); }
static int cxacru_bind(struct usbatm_data *usbatm_instance, struct usb_interface *intf, const struct usb_device_id *id) { struct cxacru_data *instance; struct usb_device *usb_dev = interface_to_usbdev(intf); struct usb_host_endpoint *cmd_ep = usb_dev->ep_in[CXACRU_EP_CMD]; int ret; /* instance init */ instance = kzalloc(sizeof(*instance), GFP_KERNEL); if (!instance) return -ENOMEM; instance->usbatm = usbatm_instance; instance->modem_type = (struct cxacru_modem_type *) id->driver_info; mutex_init(&instance->poll_state_serialize); instance->poll_state = CXPOLL_STOPPED; instance->line_status = -1; instance->adsl_status = -1; mutex_init(&instance->adsl_state_serialize); instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL); if (!instance->rcv_buf) { usb_dbg(usbatm_instance, "cxacru_bind: no memory for rcv_buf\n"); ret = -ENOMEM; goto fail; } instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL); if (!instance->snd_buf) { usb_dbg(usbatm_instance, "cxacru_bind: no memory for snd_buf\n"); ret = -ENOMEM; goto fail; } instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL); if (!instance->rcv_urb) { ret = -ENOMEM; goto fail; } instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL); if (!instance->snd_urb) { ret = -ENOMEM; goto fail; } if (!cmd_ep) { usb_dbg(usbatm_instance, "cxacru_bind: no command endpoint\n"); ret = -ENODEV; goto fail; } if ((cmd_ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) { usb_fill_int_urb(instance->rcv_urb, usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD), instance->rcv_buf, PAGE_SIZE, cxacru_blocking_completion, &instance->rcv_done, 1); usb_fill_int_urb(instance->snd_urb, usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD), instance->snd_buf, PAGE_SIZE, cxacru_blocking_completion, &instance->snd_done, 4); } else { usb_fill_bulk_urb(instance->rcv_urb, usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_CMD), instance->rcv_buf, PAGE_SIZE, cxacru_blocking_completion, &instance->rcv_done); usb_fill_bulk_urb(instance->snd_urb, usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD), instance->snd_buf, PAGE_SIZE, cxacru_blocking_completion, &instance->snd_done); } mutex_init(&instance->cm_serialize); INIT_DELAYED_WORK(&instance->poll_work, cxacru_poll_status); usbatm_instance->driver_data = instance; usbatm_instance->flags = (cxacru_card_status(instance) ? 0 : UDSL_SKIP_HEAVY_INIT); return 0; fail: free_page((unsigned long) instance->snd_buf); free_page((unsigned long) instance->rcv_buf); usb_free_urb(instance->snd_urb); usb_free_urb(instance->rcv_urb); kfree(instance); return ret; }
char *get_usb_node_by_device(const char *device_name, char *buf, const int buf_size) { int device_type = get_device_type_by_device(device_name); char device_path[128], usb_path[PATH_MAX]; char disk_name[4]; if(device_type == DEVICE_TYPE_UNKNOWN) return NULL; memset(device_path, 0, 128); memset(usb_path, 0, PATH_MAX); #ifdef RTCONFIG_USB if(device_type == DEVICE_TYPE_DISK){ memset(disk_name, 0, 4); strncpy(disk_name, device_name, 3); sprintf(device_path, "%s/%s/device", SYS_BLOCK, disk_name); if(realpath(device_path, usb_path) == NULL){ usb_dbg("(%s): Fail to get link: %s.\n", device_name, device_path); return NULL; } } else #endif #ifdef RTCONFIG_USB_PRINTER if(device_type == DEVICE_TYPE_PRINTER){ sprintf(device_path, "%s/%s/device", SYS_USB, device_name); if(realpath(device_path, usb_path) == NULL){ usb_dbg("(%s): Fail to get link: %s.\n", device_name, device_path); return NULL; } } else #endif #ifdef RTCONFIG_USB_MODEM if(device_type == DEVICE_TYPE_SG){ sprintf(device_path, "%s/%s/device", SYS_SG, device_name); if(realpath(device_path, usb_path) == NULL){ usb_dbg("(%s): Fail to get link: %s.\n", device_name, device_path); return NULL; } } else if(device_type == DEVICE_TYPE_CD){ sprintf(device_path, "%s/%s/device", SYS_BLOCK, device_name); if(realpath(device_path, usb_path) == NULL){ usb_dbg("(%s): Fail to get link: %s.\n", device_name, device_path); return NULL; } } else if(device_type == DEVICE_TYPE_MODEM){ sprintf(device_path, "%s/%s/device", SYS_TTY, device_name); if(realpath(device_path, usb_path) == NULL){ sleep(1); // Sometimes link would be built slowly, so try again. if(realpath(device_path, usb_path) == NULL){ usb_dbg("(%s)(2/2): Fail to get link: %s.\n", device_name, device_path); return NULL; } } } else #endif #ifdef RTCONFIG_USB_BECEEM if(device_type == DEVICE_TYPE_BECEEM){ sprintf(device_path, "%s/%s/device", SYS_USB, device_name); if(realpath(device_path, usb_path) == NULL){ if(realpath(device_path, usb_path) == NULL){ usb_dbg("(%s)(2/2): Fail to get link: %s.\n", device_name, device_path); return NULL; } } } else #endif return NULL; if(get_usb_node_by_string(usb_path, buf, buf_size) == NULL){ usb_dbg("(%s): Fail to get usb port: %s.\n", device_name, usb_path); return NULL; } return buf; }
static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm, u8 *wdata, int wsize, u8 *rdata, int rsize) { int ret, actlen; int offb, offd; const int stride = CMD_PACKET_SIZE - 4; u8 *wbuf = instance->snd_buf; u8 *rbuf = instance->rcv_buf; int wbuflen = ((wsize - 1) / stride + 1) * CMD_PACKET_SIZE; int rbuflen = ((rsize - 1) / stride + 1) * CMD_PACKET_SIZE; if (wbuflen > PAGE_SIZE || rbuflen > PAGE_SIZE) { if (printk_ratelimit()) usb_err(instance->usbatm, "requested transfer size too large (%d, %d)\n", wbuflen, rbuflen); ret = -ENOMEM; goto err; } mutex_lock(&instance->cm_serialize); /* submit reading urb before the writing one */ init_completion(&instance->rcv_done); ret = usb_submit_urb(instance->rcv_urb, GFP_KERNEL); if (ret < 0) { if (printk_ratelimit()) usb_err(instance->usbatm, "submit of read urb for cm %#x failed (%d)\n", cm, ret); goto fail; } memset(wbuf, 0, wbuflen); /* handle wsize == 0 */ wbuf[0] = cm; for (offb = offd = 0; offd < wsize; offd += stride, offb += CMD_PACKET_SIZE) { wbuf[offb] = cm; memcpy(wbuf + offb + 4, wdata + offd, min_t(int, stride, wsize - offd)); } instance->snd_urb->transfer_buffer_length = wbuflen; init_completion(&instance->snd_done); ret = usb_submit_urb(instance->snd_urb, GFP_KERNEL); if (ret < 0) { if (printk_ratelimit()) usb_err(instance->usbatm, "submit of write urb for cm %#x failed (%d)\n", cm, ret); goto fail; } ret = cxacru_start_wait_urb(instance->snd_urb, &instance->snd_done, NULL); if (ret < 0) { if (printk_ratelimit()) usb_err(instance->usbatm, "send of cm %#x failed (%d)\n", cm, ret); goto fail; } ret = cxacru_start_wait_urb(instance->rcv_urb, &instance->rcv_done, &actlen); if (ret < 0) { if (printk_ratelimit()) usb_err(instance->usbatm, "receive of cm %#x failed (%d)\n", cm, ret); goto fail; } if (actlen % CMD_PACKET_SIZE || !actlen) { if (printk_ratelimit()) usb_err(instance->usbatm, "invalid response length to cm %#x: %d\n", cm, actlen); ret = -EIO; goto fail; } /* check the return status and copy the data to the output buffer, if needed */ for (offb = offd = 0; offd < rsize && offb < actlen; offb += CMD_PACKET_SIZE) { if (rbuf[offb] != cm) { if (printk_ratelimit()) usb_err(instance->usbatm, "wrong cm %#x in response to cm %#x\n", rbuf[offb], cm); ret = -EIO; goto fail; } if (rbuf[offb + 1] != CM_STATUS_SUCCESS) { if (printk_ratelimit()) usb_err(instance->usbatm, "response to cm %#x failed: %#x\n", cm, rbuf[offb + 1]); ret = -EIO; goto fail; } if (offd >= rsize) break; memcpy(rdata + offd, rbuf + offb + 4, min_t(int, stride, rsize - offd)); offd += stride; } ret = offd; usb_dbg(instance->usbatm, "cm %#x\n", cm); fail: mutex_unlock(&instance->cm_serialize); err: return ret; }
disk_info_t *create_disk(const char *device_name, disk_info_t **new_disk_info){ disk_info_t *follow_disk_info; u32 major, minor; u64 size_in_kilobytes = 0; int len; char usb_node[32], port_path[8]; char buf[64], *port, *vendor = NULL, *model = NULL, *ptr; partition_info_t *new_partition_info, **follow_partition_list; if(new_disk_info == NULL){ usb_dbg("Bad input!!\n"); return NULL; } *new_disk_info = NULL; // initial value. if(device_name == NULL || !is_disk_name(device_name)) return NULL; if(initial_disk_data(&follow_disk_info) == NULL){ usb_dbg("No memory!!(follow_disk_info)\n"); return NULL; } len = strlen(device_name); follow_disk_info->device = (char *)malloc(len+1); if(follow_disk_info->device == NULL){ usb_dbg("No memory!!(follow_disk_info->device)\n"); free_disk_data(&follow_disk_info); return NULL; } strcpy(follow_disk_info->device, device_name); follow_disk_info->device[len] = 0; if(!get_disk_major_minor(device_name, &major, &minor)){ usb_dbg("Fail to get disk's major and minor: %s.\n", device_name); free_disk_data(&follow_disk_info); return NULL; } follow_disk_info->major = major; follow_disk_info->minor = minor; if(!get_disk_size(device_name, &size_in_kilobytes)){ usb_dbg("Fail to get disk's size_in_kilobytes: %s.\n", device_name); free_disk_data(&follow_disk_info); return NULL; } follow_disk_info->size_in_kilobytes = size_in_kilobytes; if(!strncmp(device_name, "sd", 2)){ // Get USB node. if(get_usb_node_by_device(device_name, usb_node, 32) == NULL){ usb_dbg("(%s): Fail to get usb node.\n", device_name); free_disk_data(&follow_disk_info); return NULL; } if(get_path_by_node(usb_node, port_path, 8) == NULL){ usb_dbg("(%s): Fail to get usb path.\n", usb_node); free_disk_data(&follow_disk_info); return NULL; } // Get USB port. if(get_usb_port_by_string(usb_node, buf, 64) == NULL){ usb_dbg("Fail to get usb port: %s.\n", usb_node); free_disk_data(&follow_disk_info); return NULL; } len = strlen(buf); if(len > 0){ port = (char *)malloc(8); if(port == NULL){ usb_dbg("No memory!!(port)\n"); free_disk_data(&follow_disk_info); return NULL; } memset(port, 0, 8); strncpy(port, port_path, 8); follow_disk_info->port = port; } // start get vendor. if(get_disk_vendor(device_name, buf, 64) == NULL){ usb_dbg("Fail to get disk's vendor: %s.\n", device_name); free_disk_data(&follow_disk_info); return NULL; } len = strlen(buf); if(len > 0){ vendor = (char *)malloc(len+1); if(vendor == NULL){ usb_dbg("No memory!!(vendor)\n"); free_disk_data(&follow_disk_info); return NULL; } strncpy(vendor, buf, len); vendor[len] = 0; strntrim(vendor); follow_disk_info->vendor = vendor; } // start get model. if(get_disk_model(device_name, buf, 64) == NULL){ usb_dbg("Fail to get disk's model: %s.\n", device_name); free_disk_data(&follow_disk_info); return NULL; } len = strlen(buf); if(len > 0){ model = (char *)malloc(len+1); if(model == NULL){ usb_dbg("No memory!!(model)\n"); free_disk_data(&follow_disk_info); return NULL; } strncpy(model, buf, len); model[len] = 0; strntrim(model); follow_disk_info->model = model; } // get USB's tag memset(buf, 0, 64); len = 0; ptr = buf; if(vendor != NULL){ len += strlen(vendor); strcpy(ptr, vendor); ptr += len; } if(model != NULL){ if(len > 0){ ++len; // Add a space between vendor and model. strcpy(ptr, " "); ++ptr; } len += strlen(model); strcpy(ptr, model); ptr += len; } if(len > 0){ follow_disk_info->tag = (char *)malloc(len+1); if(follow_disk_info->tag == NULL){ usb_dbg("No memory!!(follow_disk_info->tag)\n"); free_disk_data(&follow_disk_info); return NULL; } strcpy(follow_disk_info->tag, buf); follow_disk_info->tag[len] = 0; } else{ len = strlen(DEFAULT_USB_TAG); follow_disk_info->tag = (char *)malloc(len+1); if(follow_disk_info->tag == NULL){ usb_dbg("No memory!!(follow_disk_info->tag)\n"); free_disk_data(&follow_disk_info); return NULL; } strcpy(follow_disk_info->tag, DEFAULT_USB_TAG); follow_disk_info->tag[len] = 0; } follow_partition_list = &(follow_disk_info->partitions); while(*follow_partition_list != NULL) follow_partition_list = &((*follow_partition_list)->next); new_partition_info = create_partition(device_name, follow_partition_list); if(new_partition_info != NULL){ new_partition_info->disk = follow_disk_info; ++(follow_disk_info->partition_number); ++(follow_disk_info->mounted_number); if(!strcmp(new_partition_info->device, follow_disk_info->device)) new_partition_info->size_in_kilobytes = follow_disk_info->size_in_kilobytes-4; } } if(!strcmp(follow_disk_info->device, follow_disk_info->partitions->device)) get_disk_partitionnumber(device_name, &(follow_disk_info->partition_number), &(follow_disk_info->mounted_number)); *new_disk_info = follow_disk_info; return *new_disk_info; }
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; }