# [FreeNAS] load libiconv.ko with utf-8 into kernel



## phreak (Nov 11, 2018)

I would like to let user besides root to mount a SMB share. It requires filename conversion with UTF-8 encoding.

In /boot/loader.conf file, I have added:

```
libiconv_load="YES"
```

And /etc/nsmb.conf file

```
[default]
workgroup=WORKGROUP

[server]
addr=1.2.3.4
charsets=UTF-8:UTF-8
```

But mount_smbfs still complains.

```
$ /usr/sbin/mount_smbfs -N -f 666 -d 777 //user@server/shared /mnt/shared
mount_smbfs: can not setup kernel iconv table (ISO8859-1:tolower): syserr = Operation not permitted
Warning: no cfg file(s) found.
```

What is the correct syntax for loading iconv with UTF-8 into kernel in /boot/loader.conf?

Thanks a ton!


----------



## yuripv (Nov 11, 2018)

Try doing the mount as root once, and check which kernel modules are loaded (other than libiconv).


----------



## phreak (Nov 11, 2018)

Thanks for the pointer!
However, I have a hard time knowing the correct syntax from the loaded modules.

I have attached the output of `dmseg -a` and `kldstat -vh`.


----------



## yuripv (Nov 11, 2018)

It looks like you need the libmchain as well: `libmchain_load="YES"`


----------



## phreak (Nov 13, 2018)

Thanks for your help.

I thought when a SMB share was mounted by root, a normal user should be able to mount another since the required libraries have already been loaded into the kernel. However, it gives the following error.

`$ mount_smbfs -N -f 666 -d 777 //user@server/Shared /net/server/shared
Warning: no cfg file(s) found.
mount_smbfs: can not setup kernel iconv table (ISO8859-1:tolower): syserr = Operation not permitted`

Any pointers?


----------



## yuripv (Nov 13, 2018)

OK, some observations.

1.  Warning: no cfg file(s) found.
Trussing mount_smbfs shows the following:

open("/etc/nsmb.conf",O_RDONLY,0666)             ERR#13 'Permission denied'

And indeed:

$ ls -l /etc/nsmb.conf 
-rw-------  1 root  wheel  77 Nov 13 10:20 /etc/nsmb.conf

Try using ~/.nsmbrc.

2. Looking at your /etc/nsmb.conf contents, you need to specify server name uppercase, i.e. [SERVER].

I'm still looking into why it still gives the EPERM though.


----------



## phreak (Nov 14, 2018)

Thank you very much. Sorry for the late reply. I was away from home yesterday.

Yay, the "Warning: no cfg file(s) found." was cleared.
And I was using upper case in the actual file.
Thanks for reminding me.

Any progress on the iconv table permission issue?


----------



## yuripv (Nov 14, 2018)

Sadly, it looks like there's no easy way to "fix" this to be able doing user-mounts as there's a lot of resulting iconv loads in kernel.  Same story e.g. for mount_msdosfs if you specify -D (DOS codepage option).  I wonder if loading libiconv module could just get all tables for all encodings loaded, that doesn't seem to be that big size for today's RAM sizes, but that's really a separate task.  Sadly, for now, I don't see an option to solve this (and I could be very well wrong, of course).


----------



## phreak (Nov 14, 2018)

Yuripv, thanks for your great effort! 
It is definitely shortcoming of BSD.
I heard there is a kiconvtool that may help.

Unfortunately kiconvtool is not on the pkg manager of FreeNAS which I am using.


----------



## yuripv (Nov 14, 2018)

Thanks for kiconvtool, I wasn't aware of it.


----------



## phreak (Feb 19, 2019)

As I was using it on FreeNAS and FreeNAS 11.2-U2 has come out yesterday and added kiconvtool to the kernel, I have tried kiconvtool today to let an unprivileged user to mount a smb share.

I have added the following line to the /boot/loader.conf

```
smbfs_iconv_load="YES"
```

And these lines to /etc/rc.conf

```
# enable kiconv script
kiconv_preload="YES"

# specify local/foreign encodings
kiconv_local_charsets="UFT-8"
kiconv_foreign_charsets="UTF-8"
```

And the ~/.nsmbrc

```
[default]
workgroup=WORKGROUP

[SERVER]
addr=192.168.0.200
charsets=UTF-8:UTF-8
```

And when I execute the following command as an unprivileged user:

```
$ /usr/sbin/mount_smbfs -N -f 666 -d 777 -E UTF-8:UTF-8 //user@server/Media /net/server/media
mount_smbfs: can not setup kernel iconv table (UTF-8:tolower): syserr = Operation not permitted
```

What did I mess up?


----------



## SirDice (Feb 20, 2019)

phreak said:


> As I was using it on FreeNAS and FreeNAS 11.2-U2 has come out yesterday and added kiconvtool to the kernel, I have tried kiconvtool today to let an unprivileged user to mount a smb share.


PC-BSD, FreeNAS, XigmaNAS, and all other FreeBSD Derivatives


----------

