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.

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