Message ID | 20230803171256.1d39d71f.hc981@poolhem.se |
---|---|
State | New |
Headers | show |
Series | [v2] Allowing setting and overriding parameters in smb.conf | expand |
I'm just wondering if there are any plans to apply my patch in this version or if you would like me to change anything more in the patch? I am aware that during this time of the year many have been away on vacation and it has also been a new release 8.1 which has blocked any submitted patches but bug fixes. However, now might be a good time to push this patch towards master? Best regards Henrik On Thu, 3 Aug 2023 17:12:56 +0200 Henrik Carlqvist <hc981@poolhem.se> wrote: > From a6dfb322a88965281e3bba00a92f8d5e437bfa95 Mon Sep 17 00:00:00 2001 > From: Henrik Carlqvist <hc1245@poolhem.se> > Date: Thu, 3 Aug 2023 16:52:25 +0200 > Subject: [PATCH] Allowing setting and overriding parameters in smb.conf, > moving some parameters from the [qemu] section to the [global] section to > allow them to get overridden by custom user settings. > > Signed-off-by: Henrik Carlqvist <hc1245@poolhem.se> > --- > > In this second version of the patch I have moved also the "force user" > parameter to the global section of smb.conf. Even though I do not self see > the usefullness of altering that parameter we might just as well give the > users the freedom to alter anything in smb.conf. Maybe someone else will see > the need to alter that parameter. > > Best regards Henrik > > net/slirp.c | 50 ++++++++++++++++++++++++++++++++++++++++--------- > qapi/net.json | 3 +++ > qemu-options.hx | 15 ++++++++++++--- > 3 files changed, 56 insertions(+), 12 deletions(-) > > diff --git a/net/slirp.c b/net/slirp.c > index c33b3e02e7..e27d115bc4 100644 > --- a/net/slirp.c > +++ b/net/slirp.c > @@ -106,7 +106,8 @@ static int slirp_guestfwd(SlirpState *s, const char > *config_str, Error **errp); > > #if defined(CONFIG_SMBD_COMMAND) > static int slirp_smb(SlirpState *s, const char *exported_dir, > - struct in_addr vserver_addr, Error **errp); > + struct in_addr vserver_addr, const char *smbparams, > + Error **errp); > static void slirp_smb_cleanup(SlirpState *s); > #else > static inline void slirp_smb_cleanup(SlirpState *s) { } > @@ -424,6 +425,7 @@ static int net_slirp_init(NetClientState *peer, const > char *model, > const char *bootfile, const char *vdhcp_start, > const char *vnameserver, const char > *vnameserver6, const char *smb_export, const char > *vsmbserver, > + const char *smbparams, > const char **dnssearch, const char *vdomainname, > const char *tftp_server_name, > Error **errp) > @@ -678,7 +680,7 @@ static int net_slirp_init(NetClientState *peer, const > char *model, > } > #if defined(CONFIG_SMBD_COMMAND) > if (smb_export) { > - if (slirp_smb(s, smb_export, smbsrv, errp) < 0) { > + if (slirp_smb(s, smb_export, smbsrv, smbparams, errp) < 0) { > goto error; > } > } > @@ -891,7 +893,8 @@ static void slirp_smb_cleanup(SlirpState *s) > } > > static int slirp_smb(SlirpState* s, const char *exported_dir, > - struct in_addr vserver_addr, Error **errp) > + struct in_addr vserver_addr, const char *smbparams, > + Error **errp) > { > char *smb_conf; > char *smb_cmdline; > @@ -950,11 +953,12 @@ static int slirp_smb(SlirpState* s, const char > *exported_dir, > "printing = bsd\n" > "disable spoolss = yes\n" > "usershare max shares = 0\n" > - "[qemu]\n" > - "path=%s\n" > "read only=no\n" > "guest ok=yes\n" > - "force user=%s\n", > + "force user=%s\n" > + "%s" > + "[qemu]\n" > + "path=%s\n", > s->smb_dir, > s->smb_dir, > s->smb_dir, > @@ -963,8 +967,9 @@ static int slirp_smb(SlirpState* s, const char > *exported_dir, > s->smb_dir, > s->smb_dir, > s->smb_dir, > - exported_dir, > - passwd->pw_name > + passwd->pw_name, > + smbparams, > + exported_dir > ); > fclose(f); > > @@ -1143,6 +1148,29 @@ static const char **slirp_dnssearch(const StringList > *dnsname) > return ret; > } > > +static char *slirp_smbparams(const StringList *smbparam) > +{ > + const StringList *c = smbparam; > + size_t i = 1; /* for string terminating 0 */ > + char *ret; > + > + while (c) { > + i += strlen(c->value->str); > + i++; /* for \n */ > + c = c->next; > + } > + ret = g_malloc(i * sizeof(*ret)); > + ret[0]=0; /* Start with empty string */ > + > + c = smbparam; > + while (c) { > + pstrcat(ret, i * sizeof(*ret), c->value->str); > + pstrcat(ret, i * sizeof(*ret), "\n"); > + c = c->next; > + } > + return ret; > +} > + > int net_init_slirp(const Netdev *netdev, const char *name, > NetClientState *peer, Error **errp) > { > @@ -1151,6 +1179,7 @@ int net_init_slirp(const Netdev *netdev, const char > *name, > int ret; > const NetdevUserOptions *user; > const char **dnssearch; > + char *smbparams; > bool ipv4 = true, ipv6 = true; > > assert(netdev->type == NET_CLIENT_DRIVER_USER); > @@ -1170,6 +1199,7 @@ int net_init_slirp(const Netdev *netdev, const char > *name, > NULL; > > dnssearch = slirp_dnssearch(user->dnssearch); > + smbparams = slirp_smbparams(user->smbparam); > > /* all optional fields are initialized to "all bits zero" */ > > @@ -1182,7 +1212,8 @@ int net_init_slirp(const Netdev *netdev, const char > *name, > user->ipv6_host, user->hostname, user->tftp, > user->bootfile, user->dhcpstart, > user->dns, user->ipv6_dns, user->smb, > - user->smbserver, dnssearch, user->domainname, > + user->smbserver, smbparams, > + dnssearch, user->domainname, > user->tftp_server_name, errp); > > while (slirp_configs) { > @@ -1193,6 +1224,7 @@ int net_init_slirp(const Netdev *netdev, const char > *name, > > g_free(vnet); > g_free(dnssearch); > + g_free(smbparams); > > return ret; > } > diff --git a/qapi/net.json b/qapi/net.json > index 313c8a606e..163091719c 100644 > --- a/qapi/net.json > +++ b/qapi/net.json > @@ -156,6 +156,8 @@ > # > # @smbserver: IP address of the built-in SMB server > # > +# @smbparam: list of parameters with values for smb.conf > +# > # @hostfwd: redirect incoming TCP or UDP host connections to guest > # endpoints > # > @@ -186,6 +188,7 @@ > '*ipv6-dns': 'str', > '*smb': 'str', > '*smbserver': 'str', > + '*smbparam': ['String'], > '*hostfwd': ['String'], > '*guestfwd': ['String'], > '*tftp-server-name': 'str' } } > diff --git a/qemu-options.hx b/qemu-options.hx > index 29b98c3d4c..7b92d08c3e 100644 > --- a/qemu-options.hx > +++ b/qemu-options.hx > @@ -2758,9 +2758,9 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, > " [,ipv6=on|off][,ipv6-net=addr[/int]][,ipv6-host=addr]\n" > " [,restrict=on|off][,hostname=host][,dhcpstart=addr]\n" > " > [,dns=addr][,ipv6-dns=addr][,dnssearch=domain][,domainname=domain]\n" > - " > [,tftp=dir][,tftp-server-name=name][,bootfile=f][,hostfwd=rule][,guestfwd=r > ule]"+ " > [,tftp=dir][,tftp-server-name=name][,bootfile=f][,hostfwd=rule][,guestfwd=r > ule]\n" > #ifndef _WIN32 > - > "[,smb=dir[,smbserver=addr]]\n"+ " > [,smb=dir[,smbserver=addr][,smbparam=parameter=value]]\n" > #endif > " configure a user mode network backend with ID > 'str',\n"" its DHCP server and optional services\n" > @@ -3062,7 +3062,7 @@ SRST > |qemu_system| -hda linux.img -boot n -device e1000,netdev=n1 \\ > -netdev > user,id=n1,tftp=/path/to/tftp/files,bootfile=/pxelinux.0 > > - ``smb=dir[,smbserver=addr]`` > + ``smb=dir[,smbserver=addr][,smbparam=parameter=value]`` > When using the user mode network stack, activate a built-in SMB > server so that Windows OSes can access to the host files in > ``dir`` transparently. The IP address of the SMB server can be > @@ -3081,6 +3081,15 @@ SRST > > Then ``dir`` can be accessed in ``\\smbserver\qemu``. > > + It is possible to set samba parameters in the generated smb.conf > + with one or more ``smbparam=parameter=value``. Example: > + > + .. parsed-literal:: > + > + |qemu_system| -nic user,smb=/tmp,smbparam="read > only"=yes,smbparam="server min protocol"=NT1+ > + See the man page of smb.conf for a complete listing of parameters. > + > Note that a SAMBA server must be installed on the host OS. > > ``hostfwd=[tcp|udp]:[hostaddr]:hostport-[guestaddr]:guestport`` > -- > 2.35.1 >
Still wondering if there are any plans to apply my patch or if you would like to change anything in the patch? Being able to set parameters in smb.conf would be really useful these days for people running old versions of Windows like Windows XP in a qemu guest. Today, the default settings of Samba has disabled SMBv1 making old versions of Windows unable to connect to Samba shares. regards Henrik On Sun, 10 Sep 2023 13:48:12 +0200 Henrik Carlqvist <hc94@poolhem.se> wrote: > I'm just wondering if there are any plans to apply my patch in this version > or if you would like me to change anything more in the patch? I am aware > that during this time of the year many have been away on vacation and it has > also been a new release 8.1 which has blocked any submitted patches but bug > fixes. However, now might be a good time to push this patch towards master? > > Best regards Henrik > > On Thu, 3 Aug 2023 17:12:56 +0200 > Henrik Carlqvist <hc981@poolhem.se> wrote: > > > From a6dfb322a88965281e3bba00a92f8d5e437bfa95 Mon Sep 17 00:00:00 2001 > > From: Henrik Carlqvist <hc1245@poolhem.se> > > Date: Thu, 3 Aug 2023 16:52:25 +0200 > > Subject: [PATCH] Allowing setting and overriding parameters in smb.conf, > > moving some parameters from the [qemu] section to the [global] section to > > allow them to get overridden by custom user settings. > > > > Signed-off-by: Henrik Carlqvist <hc1245@poolhem.se> > > --- > > > > In this second version of the patch I have moved also the "force user" > > parameter to the global section of smb.conf. Even though I do not self see > > the usefullness of altering that parameter we might just as well give the > > users the freedom to alter anything in smb.conf. Maybe someone else will > > see the need to alter that parameter. > > > > Best regards Henrik > > > > net/slirp.c | 50 ++++++++++++++++++++++++++++++++++++++++--------- > > qapi/net.json | 3 +++ > > qemu-options.hx | 15 ++++++++++++--- > > 3 files changed, 56 insertions(+), 12 deletions(-) > > > > diff --git a/net/slirp.c b/net/slirp.c > > index c33b3e02e7..e27d115bc4 100644 > > --- a/net/slirp.c > > +++ b/net/slirp.c > > @@ -106,7 +106,8 @@ static int slirp_guestfwd(SlirpState *s, const char > > *config_str, Error **errp); > > > > #if defined(CONFIG_SMBD_COMMAND) > > static int slirp_smb(SlirpState *s, const char *exported_dir, > > - struct in_addr vserver_addr, Error **errp); > > + struct in_addr vserver_addr, const char *smbparams, > > + Error **errp); > > static void slirp_smb_cleanup(SlirpState *s); > > #else > > static inline void slirp_smb_cleanup(SlirpState *s) { } > > @@ -424,6 +425,7 @@ static int net_slirp_init(NetClientState *peer, const > > char *model, > > const char *bootfile, const char *vdhcp_start, > > const char *vnameserver, const char > > *vnameserver6, const char *smb_export, const > > char*vsmbserver, > > + const char *smbparams, > > const char **dnssearch, const char > > *vdomainname, const char *tftp_server_name, > > Error **errp) > > @@ -678,7 +680,7 @@ static int net_slirp_init(NetClientState *peer, const > > char *model, > > } > > #if defined(CONFIG_SMBD_COMMAND) > > if (smb_export) { > > - if (slirp_smb(s, smb_export, smbsrv, errp) < 0) { > > + if (slirp_smb(s, smb_export, smbsrv, smbparams, errp) < 0) { > > goto error; > > } > > } > > @@ -891,7 +893,8 @@ static void slirp_smb_cleanup(SlirpState *s) > > } > > > > static int slirp_smb(SlirpState* s, const char *exported_dir, > > - struct in_addr vserver_addr, Error **errp) > > + struct in_addr vserver_addr, const char *smbparams, > > + Error **errp) > > { > > char *smb_conf; > > char *smb_cmdline; > > @@ -950,11 +953,12 @@ static int slirp_smb(SlirpState* s, const char > > *exported_dir, > > "printing = bsd\n" > > "disable spoolss = yes\n" > > "usershare max shares = 0\n" > > - "[qemu]\n" > > - "path=%s\n" > > "read only=no\n" > > "guest ok=yes\n" > > - "force user=%s\n", > > + "force user=%s\n" > > + "%s" > > + "[qemu]\n" > > + "path=%s\n", > > s->smb_dir, > > s->smb_dir, > > s->smb_dir, > > @@ -963,8 +967,9 @@ static int slirp_smb(SlirpState* s, const char > > *exported_dir, > > s->smb_dir, > > s->smb_dir, > > s->smb_dir, > > - exported_dir, > > - passwd->pw_name > > + passwd->pw_name, > > + smbparams, > > + exported_dir > > ); > > fclose(f); > > > > @@ -1143,6 +1148,29 @@ static const char **slirp_dnssearch(const > > StringList*dnsname) > > return ret; > > } > > > > +static char *slirp_smbparams(const StringList *smbparam) > > +{ > > + const StringList *c = smbparam; > > + size_t i = 1; /* for string terminating 0 */ > > + char *ret; > > + > > + while (c) { > > + i += strlen(c->value->str); > > + i++; /* for \n */ > > + c = c->next; > > + } > > + ret = g_malloc(i * sizeof(*ret)); > > + ret[0]=0; /* Start with empty string */ > > + > > + c = smbparam; > > + while (c) { > > + pstrcat(ret, i * sizeof(*ret), c->value->str); > > + pstrcat(ret, i * sizeof(*ret), "\n"); > > + c = c->next; > > + } > > + return ret; > > +} > > + > > int net_init_slirp(const Netdev *netdev, const char *name, > > NetClientState *peer, Error **errp) > > { > > @@ -1151,6 +1179,7 @@ int net_init_slirp(const Netdev *netdev, const char > > *name, > > int ret; > > const NetdevUserOptions *user; > > const char **dnssearch; > > + char *smbparams; > > bool ipv4 = true, ipv6 = true; > > > > assert(netdev->type == NET_CLIENT_DRIVER_USER); > > @@ -1170,6 +1199,7 @@ int net_init_slirp(const Netdev *netdev, const char > > *name, > > NULL; > > > > dnssearch = slirp_dnssearch(user->dnssearch); > > + smbparams = slirp_smbparams(user->smbparam); > > > > /* all optional fields are initialized to "all bits zero" */ > > > > @@ -1182,7 +1212,8 @@ int net_init_slirp(const Netdev *netdev, const char > > *name, > > user->ipv6_host, user->hostname, user->tftp, > > user->bootfile, user->dhcpstart, > > user->dns, user->ipv6_dns, user->smb, > > - user->smbserver, dnssearch, user->domainname, > > + user->smbserver, smbparams, > > + dnssearch, user->domainname, > > user->tftp_server_name, errp); > > > > while (slirp_configs) { > > @@ -1193,6 +1224,7 @@ int net_init_slirp(const Netdev *netdev, const char > > *name, > > > > g_free(vnet); > > g_free(dnssearch); > > + g_free(smbparams); > > > > return ret; > > } > > diff --git a/qapi/net.json b/qapi/net.json > > index 313c8a606e..163091719c 100644 > > --- a/qapi/net.json > > +++ b/qapi/net.json > > @@ -156,6 +156,8 @@ > > # > > # @smbserver: IP address of the built-in SMB server > > # > > +# @smbparam: list of parameters with values for smb.conf > > +# > > # @hostfwd: redirect incoming TCP or UDP host connections to guest > > # endpoints > > # > > @@ -186,6 +188,7 @@ > > '*ipv6-dns': 'str', > > '*smb': 'str', > > '*smbserver': 'str', > > + '*smbparam': ['String'], > > '*hostfwd': ['String'], > > '*guestfwd': ['String'], > > '*tftp-server-name': 'str' } } > > diff --git a/qemu-options.hx b/qemu-options.hx > > index 29b98c3d4c..7b92d08c3e 100644 > > --- a/qemu-options.hx > > +++ b/qemu-options.hx > > @@ -2758,9 +2758,9 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, > > " [,ipv6=on|off][,ipv6-net=addr[/int]][,ipv6-host=addr]\n" > > " [,restrict=on|off][,hostname=host][,dhcpstart=addr]\n" > > " > > [,dns=addr][,ipv6-dns=addr][,dnssearch=domain][,domainname=domain]\n" > > - " > > [,tftp=dir][,tftp-server-name=name][,bootfile=f][,hostfwd=rule][,guestfwd > > =r ule]"+ " > > [,tftp=dir][,tftp-server-name=name][,bootfile=f][,hostfwd=rule][,guestfwd > > =r ule]\n" > > #ifndef _WIN32 > > - > > "[,smb=dir[,smbserver=addr]]\n"+ " > > [,smb=dir[,smbserver=addr][,smbparam=parameter=value]]\n" > > #endif > > " configure a user mode network backend with ID > > 'str',\n"" its DHCP server and optional services\n" > > @@ -3062,7 +3062,7 @@ SRST > > |qemu_system| -hda linux.img -boot n -device e1000,netdev=n1 > > |\\ > > -netdev > > user,id=n1,tftp=/path/to/tftp/files,bootfile=/pxelinux.0 > > > > - ``smb=dir[,smbserver=addr]`` > > + ``smb=dir[,smbserver=addr][,smbparam=parameter=value]`` > > When using the user mode network stack, activate a built-in SMB > > server so that Windows OSes can access to the host files in > > ``dir`` transparently. The IP address of the SMB server can be > > @@ -3081,6 +3081,15 @@ SRST > > > > Then ``dir`` can be accessed in ``\\smbserver\qemu``. > > > > + It is possible to set samba parameters in the generated smb.conf > > + with one or more ``smbparam=parameter=value``. Example: > > + > > + .. parsed-literal:: > > + > > + |qemu_system| -nic user,smb=/tmp,smbparam="read > > only"=yes,smbparam="server min protocol"=NT1+ > > + See the man page of smb.conf for a complete listing of > > parameters.+ > > Note that a SAMBA server must be installed on the host OS. > > > > ``hostfwd=[tcp|udp]:[hostaddr]:hostport-[guestaddr]:guestport`` > > -- > > 2.35.1 > >
18.02.2024 01:28, Henrik Carlqvist : > Still wondering if there are any plans to apply my patch or if you would like > to change anything in the patch? > > Being able to set parameters in smb.conf would be really useful these days for > people running old versions of Windows like Windows XP in a qemu guest. Today, > the default settings of Samba has disabled SMBv1 making old versions of > Windows unable to connect to Samba shares. I don't maintain this code, so my email is just a random comment. But I did have an issue with smbd not working right due to one missing/wrong parameter or another, more than once. Also, samba is evolving too, so it might need more parameters or less. My suggestion is still the same as 10+ years ago: to ship a shell script which run smbd, instead of running smbd directly. This script will set up smb.conf (whole thing, exactly as it is done now in the C code), and exec /usr/sbin/smbd with the necessary args. This way, it's a) trivial to modify parameters on the qemu side (easy to edit just this script), b) possible to see which samba version is in use and adopt some parameters, c) use alternative smbd, and especially d) allow the end-user to override smbd or config in use. The best, I'd say, is to allow to specify the script on qemu command line (like samba=/etc/qemu/run-smbd.sh), and have default value for that, like /usr/share/qemu/run-smbd.sh, which is the default script shipped with qemu. Or maybe let qemu choose to use either the one specified on the command line, /etc/qemu/run-smbd.sh if it exists, or /usr/share/qemu/run-smbd.sh. /mjt
On Sun, 18 Feb 2024 12:30:01 +0300 Michael Tokarev <mjt@tls.msk.ru> wrote: > I don't maintain this code, so my email is just a random comment. Thanks for your comment anyway! > But I did have an issue with smbd not working right due to one > missing/wrong parameter or another, more than once. Also, samba > is evolving too, so it might need more parameters or less. During the years, my brute force approach to solve issues like this has been to locally patch qemu source code to build custom qemu binaries with the smb.conf parameters that I want. > My suggestion is still the same as 10+ years ago: to ship a shell script > which run smbd, instead of running smbd directly. This script will set > up smb.conf (whole thing, exactly as it is done now in the C code), and > exec /usr/sbin/smbd with the necessary args. Such a script would be easier to modify than changing the C sources. > This way, it's a) trivial to modify parameters on the qemu side (easy to > edit just this script), b) possible to see which samba version is in use > and adopt some parameters, c) use alternative smbd, and especially d) > allow the end-user to override smbd or config in use. During the years, I have also seen the need to use alternative smbd. I have then solved it by having the old smbd that I prefered for qemu in /usr/sbin and moved the "original" smbd provided by the Linux distribution to /usr/local/sbin where it has been started by any real Samba servers in the network. > The best, I'd say, is to allow to specify the script on qemu command line > (like samba=/etc/qemu/run-smbd.sh), and have default value for that, like > /usr/share/qemu/run-smbd.sh, which is the default script shipped with > qemu. Or maybe let qemu choose to use either the one specified on the > command line, /etc/qemu/run-smbd.sh if it exists, or > /usr/share/qemu/run-smbd.sh. Yes, by specifying such a script on the command line it would be possible to have different parameters for different qemu sessions. However, I think that also my solution allowing settings of samba parameters fixes most of the problems in a way which most of the times will be easier to use. Usually, there is no need to modify more than a handfull of parameters so those extra arguments to the qemu command line will be less to write than a separate script starting samba. In my experience qemu is mostly started from a script with a rather long qemu command line anyway. The remaining problem is when Samba comes with a new version which requires new settings of parameters. Regardless of solution some script will need to be modified to solve that problem. Again, thanks for your comment! I hope that someone will consider my patch or your suggestion. The next thing to look into would be the possibility to start some userspace NFS daemon as an alternative to Samba as Unix-guests works better with NFS than CIFS. However, that would be a much bigger project and I won't dig into such a thing until I have gotten any response on this small patch. regards Henrik
diff --git a/net/slirp.c b/net/slirp.c index c33b3e02e7..e27d115bc4 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -106,7 +106,8 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **errp); #if defined(CONFIG_SMBD_COMMAND) static int slirp_smb(SlirpState *s, const char *exported_dir, - struct in_addr vserver_addr, Error **errp); + struct in_addr vserver_addr, const char *smbparams, + Error **errp); static void slirp_smb_cleanup(SlirpState *s); #else static inline void slirp_smb_cleanup(SlirpState *s) { } @@ -424,6 +425,7 @@ static int net_slirp_init(NetClientState *peer, const char *model, const char *bootfile, const char *vdhcp_start, const char *vnameserver, const char *vnameserver6, const char *smb_export, const char *vsmbserver, + const char *smbparams, const char **dnssearch, const char *vdomainname, const char *tftp_server_name, Error **errp) @@ -678,7 +680,7 @@ static int net_slirp_init(NetClientState *peer, const char *model, } #if defined(CONFIG_SMBD_COMMAND) if (smb_export) { - if (slirp_smb(s, smb_export, smbsrv, errp) < 0) { + if (slirp_smb(s, smb_export, smbsrv, smbparams, errp) < 0) { goto error; } } @@ -891,7 +893,8 @@ static void slirp_smb_cleanup(SlirpState *s) } static int slirp_smb(SlirpState* s, const char *exported_dir, - struct in_addr vserver_addr, Error **errp) + struct in_addr vserver_addr, const char *smbparams, + Error **errp) { char *smb_conf; char *smb_cmdline; @@ -950,11 +953,12 @@ static int slirp_smb(SlirpState* s, const char *exported_dir, "printing = bsd\n" "disable spoolss = yes\n" "usershare max shares = 0\n" - "[qemu]\n" - "path=%s\n" "read only=no\n" "guest ok=yes\n" - "force user=%s\n", + "force user=%s\n" + "%s" + "[qemu]\n" + "path=%s\n", s->smb_dir, s->smb_dir, s->smb_dir, @@ -963,8 +967,9 @@ static int slirp_smb(SlirpState* s, const char *exported_dir, s->smb_dir, s->smb_dir, s->smb_dir, - exported_dir, - passwd->pw_name + passwd->pw_name, + smbparams, + exported_dir ); fclose(f); @@ -1143,6 +1148,29 @@ static const char **slirp_dnssearch(const StringList *dnsname) return ret; } +static char *slirp_smbparams(const StringList *smbparam) +{ + const StringList *c = smbparam; + size_t i = 1; /* for string terminating 0 */ + char *ret; + + while (c) { + i += strlen(c->value->str); + i++; /* for \n */ + c = c->next; + } + ret = g_malloc(i * sizeof(*ret)); + ret[0]=0; /* Start with empty string */ + + c = smbparam; + while (c) { + pstrcat(ret, i * sizeof(*ret), c->value->str); + pstrcat(ret, i * sizeof(*ret), "\n"); + c = c->next; + } + return ret; +} + int net_init_slirp(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -1151,6 +1179,7 @@ int net_init_slirp(const Netdev *netdev, const char *name, int ret; const NetdevUserOptions *user; const char **dnssearch; + char *smbparams; bool ipv4 = true, ipv6 = true; assert(netdev->type == NET_CLIENT_DRIVER_USER); @@ -1170,6 +1199,7 @@ int net_init_slirp(const Netdev *netdev, const char *name, NULL; dnssearch = slirp_dnssearch(user->dnssearch); + smbparams = slirp_smbparams(user->smbparam); /* all optional fields are initialized to "all bits zero" */ @@ -1182,7 +1212,8 @@ int net_init_slirp(const Netdev *netdev, const char *name, user->ipv6_host, user->hostname, user->tftp, user->bootfile, user->dhcpstart, user->dns, user->ipv6_dns, user->smb, - user->smbserver, dnssearch, user->domainname, + user->smbserver, smbparams, + dnssearch, user->domainname, user->tftp_server_name, errp); while (slirp_configs) { @@ -1193,6 +1224,7 @@ int net_init_slirp(const Netdev *netdev, const char *name, g_free(vnet); g_free(dnssearch); + g_free(smbparams); return ret; } diff --git a/qapi/net.json b/qapi/net.json index 313c8a606e..163091719c 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -156,6 +156,8 @@ # # @smbserver: IP address of the built-in SMB server # +# @smbparam: list of parameters with values for smb.conf +# # @hostfwd: redirect incoming TCP or UDP host connections to guest # endpoints # @@ -186,6 +188,7 @@ '*ipv6-dns': 'str', '*smb': 'str', '*smbserver': 'str', + '*smbparam': ['String'], '*hostfwd': ['String'], '*guestfwd': ['String'], '*tftp-server-name': 'str' } } diff --git a/qemu-options.hx b/qemu-options.hx index 29b98c3d4c..7b92d08c3e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2758,9 +2758,9 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, " [,ipv6=on|off][,ipv6-net=addr[/int]][,ipv6-host=addr]\n" " [,restrict=on|off][,hostname=host][,dhcpstart=addr]\n" " [,dns=addr][,ipv6-dns=addr][,dnssearch=domain][,domainname=domain]\n" - " [,tftp=dir][,tftp-server-name=name][,bootfile=f][,hostfwd=rule][,guestfwd=rule]" + " [,tftp=dir][,tftp-server-name=name][,bootfile=f][,hostfwd=rule][,guestfwd=rule]\n" #ifndef _WIN32 - "[,smb=dir[,smbserver=addr]]\n" + " [,smb=dir[,smbserver=addr][,smbparam=parameter=value]]\n" #endif " configure a user mode network backend with ID 'str',\n" " its DHCP server and optional services\n" @@ -3062,7 +3062,7 @@ SRST |qemu_system| -hda linux.img -boot n -device e1000,netdev=n1 \\ -netdev user,id=n1,tftp=/path/to/tftp/files,bootfile=/pxelinux.0 - ``smb=dir[,smbserver=addr]`` + ``smb=dir[,smbserver=addr][,smbparam=parameter=value]`` When using the user mode network stack, activate a built-in SMB server so that Windows OSes can access to the host files in ``dir`` transparently. The IP address of the SMB server can be @@ -3081,6 +3081,15 @@ SRST Then ``dir`` can be accessed in ``\\smbserver\qemu``. + It is possible to set samba parameters in the generated smb.conf + with one or more ``smbparam=parameter=value``. Example: + + .. parsed-literal:: + + |qemu_system| -nic user,smb=/tmp,smbparam="read only"=yes,smbparam="server min protocol"=NT1 + + See the man page of smb.conf for a complete listing of parameters. + Note that a SAMBA server must be installed on the host OS. ``hostfwd=[tcp|udp]:[hostaddr]:hostport-[guestaddr]:guestport``