You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
3.9 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=98
  3. USE_PROCD=1
  4. CIFSD_IFACE=""
  5. smb_header()
  6. {
  7. config_get CIFSD_IFACE $1 interface "lan"
  8. # resolve interfaces
  9. local interfaces
  10. interfaces=$(
  11. . /lib/functions/network.sh
  12. local net
  13. for net in $CIFSD_IFACE; do
  14. local device
  15. network_is_up $net || continue
  16. network_get_device device "$net"
  17. echo -n "${device:-$net} "
  18. done
  19. )
  20. local workgroup description
  21. local hostname
  22. hostname="$(cat /proc/sys/kernel/hostname)"
  23. config_get workgroup $1 workgroup "WORKGROUP"
  24. config_get description $1 description "Cifsd on OpenWrt"
  25. sed -e "s#|NAME|#$hostname#g" \
  26. -e "s#|WORKGROUP|#$workgroup#g" \
  27. -e "s#|DESCRIPTION|#$description#g" \
  28. -e "s#|INTERFACES|#$interfaces#g" \
  29. /etc/cifs/smb.conf.template > /var/etc/cifs/smb.conf
  30. [ -e /etc/cifs/smb.conf ] || ln -nsf /var/etc/cifs/smb.conf /etc/cifs/smb.conf
  31. if [ ! -L /etc/cifs/smb.conf ]; then
  32. logger -t 'cifsd' "Local custom /etc/cifs/smb.conf file detected, all UCI/Luci config settings are ignored!"
  33. fi
  34. }
  35. smb_add_share()
  36. {
  37. local name
  38. local path
  39. local comment
  40. local users
  41. local create_mask
  42. local dir_mask
  43. local browseable
  44. local read_only
  45. local writeable
  46. local guest_ok
  47. local force_root
  48. local write_list
  49. local read_list
  50. local hide_dot_files
  51. local veto_files
  52. config_get name $1 name
  53. config_get path $1 path
  54. config_get comment $1 comment
  55. config_get users $1 users
  56. config_get create_mask $1 create_mask
  57. config_get dir_mask $1 dir_mask
  58. config_get browseable $1 browseable
  59. config_get read_only $1 read_only
  60. config_get writeable $1 writeable
  61. config_get guest_ok $1 guest_ok
  62. config_get_bool force_root $1 force_root 0
  63. config_get write_list $1 write_list
  64. config_get read_list $1 read_list
  65. config_get_bool hide_dot_files $1 hide_dot_files 0
  66. config_get veto_files $1 veto_files
  67. [ -z "$name" ] || [ -z "$path" ] && return
  68. {
  69. printf "\n[%s]\n\tpath = %s\n" "$name" "$path"
  70. [ -n "$comment" ] && printf "\tcomment = %s\n" "$comment"
  71. if [ "$force_root" -eq 1 ]; then
  72. printf "\tforce user = %s\n" "root"
  73. printf "\tforce group = %s\n" "root"
  74. else
  75. [ -n "$users" ] && printf "\tvalid users = %s\n" "$users"
  76. fi
  77. [ -n "$create_mask" ] && printf "\tcreate mask = %s\n" "$create_mask"
  78. [ -n "$dir_mask" ] && printf "\tdirectory mask = %s\n" "$dir_mask"
  79. [ -n "$browseable" ] && printf "\tbrowseable = %s\n" "$browseable"
  80. [ -n "$read_only" ] && printf "\tread only = %s\n" "$read_only"
  81. [ -n "$writeable" ] && printf "\twriteable = %s\n" "$writeable"
  82. [ -n "$guest_ok" ] && printf "\tguest ok = %s\n" "$guest_ok"
  83. [ -n "$write_list" ] && printf "\twrite list = %s\n" "$write_list"
  84. [ -n "$read_list" ] && printf "\tread list = %s\n" "$read_list"
  85. [ "$hide_dot_files" -eq 1 ] && printf "\thide dot files = %s\n" "yes"
  86. [ -n "$veto_files" ] && printf "\tveto files = %s\n" "$veto_files"
  87. } >> /var/etc/cifs/smb.conf
  88. }
  89. init_config()
  90. {
  91. mkdir -p /var/etc/cifs
  92. config_load cifsd
  93. # allow copy&paste from samba UCI configs (we dont have a cifsd wiki yet)
  94. config_foreach smb_header globals
  95. config_foreach smb_header samba
  96. config_foreach smb_add_share share
  97. config_foreach smb_add_share sambashare
  98. }
  99. service_triggers()
  100. {
  101. PROCD_RELOAD_DELAY=2000
  102. procd_add_reload_trigger "dhcp" "system" "cifsd"
  103. local i
  104. for i in $CIFSD_IFACE; do
  105. procd_add_reload_interface_trigger $i
  106. done
  107. }
  108. start_service()
  109. {
  110. init_config
  111. if [ ! -e /etc/cifs/smb.conf ]; then
  112. logger -t 'cifsd' "missing config /etc/cifs/smb.conf, needs to-be created manually!"
  113. exit 1
  114. fi
  115. [ -f /tmp/cifsd.lock ] && rm /tmp/cifsd.lock
  116. # try remove again before start
  117. [ -e /sys/module/cifsd ] && rmmod cifsd > /dev/null 2>&1
  118. modprobe cifsd 2> /dev/null
  119. if [ ! -e /sys/module/cifsd ]; then
  120. logger -t 'cifsd' "modprobe of cifsd module failed, can\'t start cifsd!"
  121. exit 1
  122. fi
  123. logger -t 'cifsd' "Starting CIFS/SMB userspace service."
  124. procd_open_instance
  125. procd_set_param command /usr/sbin/cifsd --n
  126. procd_close_instance
  127. }