Managing SMB shares through freenas-v1.db updates

AlcSi

Dabbler
Joined
Sep 20, 2019
Messages
41
I'm trying to create a script to automatically open a list of SMB shares from the command-line.
The script uses sqlite3 to update the 'sharing_cifs_share' table in freenas-v1.db, as stated by a veteran forum user here :

It works : the updates I do immediatey appear in the UI.

But the actual shares are not affected (or, kinda randomly, actually).
Right now, the shares I opened are indeed open, but deleting them all has no effect... shares remain open.
Changing the list of shares (still through the DB) has no effect either, it looks like samba is now stuck with the first list of shares I created.

What I tried :
- service smbd reload
- service samba_server restart
- service -R

How should I make FreeNAS (11.3U5) aware of the updates made through freenas-v1.db ?
Or is it not the right way to do this anymore ?
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,553
I'm trying to create a script to automatically open a list of SMB shares from the command-line.
The script uses sqlite3 to update the 'sharing_cifs_share' table in freenas-v1.db, as stated by a veteran forum user here :

It works : the updates I do immediatey appear in the UI.

But the actual shares are not affected (or, kinda randomly, actually).
Right now, the shares I opened are indeed open, but deleting them all has no effect... shares remain open.
Changing the list of shares (still through the DB) has no effect either, it looks like samba is now stuck with the first list of shares I created.

What I tried :
- service smbd reload
- service samba_server restart
- service -R

How should I make FreeNAS (11.3U5) aware of the updates made through freenas-v1.db ?
Or is it not the right way to do this anymore ?
You shouldn't use sqlite3 to modify the shares. We have an API for doing this. What exactly are you trying to do?
 

AlcSi

Dabbler
Joined
Sep 20, 2019
Messages
41
I'm just trying to script modifications of the list of SMB shares, like if I did them in the UI, preferably (so that changes can be seen through UI and are thus less confusing to other users).

Specifically, I'm trying to get from point A. which is 0 shares are set, to point B. which is a given list of shares are set.
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,553
I'm just trying to script modifications of the list of SMB shares, like if I did them in the UI, preferably (so that changes can be seen through UI and are thus less confusing to other users).

Specifically, I'm trying to get from point A. which is 0 shares are set, to point B. which is a given list of shares are set.
You can't script through sqlite3 commands. The proper way to do it in 11.3 is to use our API (see https://<ip of server>/api/docs).

Here's a trivial example:
Code:
root@freenas[~]# midclt call sharing.smb.query |jq
[
  {
    "id": 1,
    "purpose": "NO_PRESET",
    "path": "/mnt/dozer/SMB",
    "path_suffix": "",
    "home": false,
    "name": "SMB",
    "comment": "",
    "ro": false,
    "browsable": true,
    "recyclebin": false,
    "guestok": false,
    "hostsallow": [],
    "hostsdeny": [],
    "auxsmbconf": "",
    "aapl_name_mangling": true,
    "abe": false,
    "acl": true,
    "durablehandle": true,
    "streams": true,
    "timemachine": false,
    "vuid": "",
    "shadowcopy": true,
    "fsrvp": false,
    "enabled": true,
    "locked": false
  }
]
root@freenas[~]# midclt call sharing.smb.update 1 '{"guestok": true}'
{"id": 1, "purpose": "NO_PRESET", "path": "/mnt/dozer/SMB", "path_suffix": "", "home": false, "name": "SMB", "comment": "", "ro": false, "browsable": true, "recyclebin": false, "guestok": true, "hostsallow": [], "hostsdeny": [], "auxsmbconf": "", "aapl_name_mangling": true, "abe": false, "acl": true, "durablehandle": true, "streams": true, "timemachine": false, "vuid": "", "shadowcopy": true, "fsrvp": false, "enabled": true, "locked": false}
root@freenas[~]# 


First command gets configuration of all shares. Second command updates share 1 to enable guest access. "sharing.smb.update" in this case takes two arguments. The first is an integer ("id" for share), the second is a JSON object with the new parameters to set.
 
Top