Re: [phodav PATCH RFC] webdavd: Automount shared folder on Windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Lukas

----- Original Message -----
> Start a new thread, that tries to connect to the shared folder.
> Sleeps for 1 second between every try.

Why not assume that the webdav connection is present when entering the main loop (after a few seconds perhaps just in case the read returns an error)?

> Thread exits on succesful connect, or if the drive letter was already
> asigned.
> ---
> https://bugs.freedesktop.org/show_bug.cgi?id=90477
> 
> This is just RFC
> 
>  - The function needs a way to connect to proper drive letter
>     - NetUseAdd, or GetLogicalDrives()

It is assigned dynamically, no?

>  - I tried calling this function in callback, in g_task, but it seems, that
>    Windows can only succesfully map the drive, if the function is called
>    AFTER the first read (which blocks), that's why I decided to use a new
>    thread.
>      - This seems to be the only way to mount the drive in webdavd itself.
> 
>  - Currently, if the service maps the drive, the user can't disconnect it.
>     - This is most likely because service has SYSTEM privileges.
>     - Need a way to map the drive with user privileges

I am not sure this is a real problem.

> 
>  - Webdavd service on Windows doesn't notice, when the sharing is disabled.
>     - This could be fixed, if vd_agent handled the start and stop of
>       webdavd according to state of the Share Folder button in viewer.

Well, it should notice that connection is gone, the read returns an error. There might be a better way to wait until the connection is up instead (I remember I couldn't find one, but it should be doable).

>     - This would also fix unmapping folder when sharing is disable.
>        - We could just unmap the drive in webdavd when we stop it.

yes

>     - vd_agent could even tell if the webdavd is installed, and grey out the
>       Share Folder button accordingaly.

That would need some more thoughts indeed (I am not sure it's worth the effort).


Thanks!

>   Aditional comments on bugzilla.
> ---
>  Makefile.am           |  4 ++++
>  spice/spice-webdavd.c | 34 ++++++++++++++++++++++++++++++++++
>  2 files changed, 38 insertions(+)
> 
> diff --git a/Makefile.am b/Makefile.am
> index 485417b..df9a73e 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -87,6 +87,10 @@ spice_webdavd_LDADD =		\
>  	$(PIE_LDFLAGS)		\
>  	$(NULL)
> 
> +if OS_WIN32
> +spice_webdavd_LDADD += -lnetapi32 -lmpr
> +endif
> +
>  deps.txt:
>  	$(AM_V_GEN)rpm -qa | grep $(host_os) | sort | unix2dos > $@
> 
> diff --git a/spice/spice-webdavd.c b/spice/spice-webdavd.c
> index c8fb795..373c5f4 100644
> --- a/spice/spice-webdavd.c
> +++ b/spice/spice-webdavd.c
> @@ -287,6 +287,38 @@ typedef struct ReadData
>    gssize size;
>  } ReadData;
> 
> +#ifdef G_OS_WIN32
> +static gpointer
> +map_drive (gpointer user_data)
> +{
> +  while(1) {
> +    char local_name[] = "Z:";
> +    char remote_name[] = "http://localhost:9843/";;
> +    NETRESOURCE net_resource;
> +
> +    net_resource.dwType = RESOURCETYPE_DISK;
> +    net_resource.lpLocalName = local_name;
> +    net_resource.lpRemoteName = remote_name;
> +    net_resource.lpProvider = NULL;
> +
> +    g_usleep (G_USEC_PER_SEC);
> +
> +    DWORD retval = WNetAddConnection2(&net_resource, NULL, NULL,
> CONNECT_TEMPORARY);
> +
> +    if (retval == NO_ERROR) {
> +      g_debug("map_drive ok");
> +      break;
> +      } else if (retval == ERROR_ALREADY_ASSIGNED) {
> +      g_debug("map_drive already asigned");
> +      break;
> +    } else {
> +      g_debug("map_drive error %d", retval);
> +    }
> +  }
> +  return NULL;
> +}
> +#endif
> +
>  static void
>  read_thread (GSimpleAsyncResult *simple,
>               GObject            *object,
> @@ -836,6 +868,8 @@ service_main (DWORD argc, TCHAR *argv[])
>    service_status.dwWaitHint = 0;
>    SetServiceStatus (service_status_handle, &service_status);
> 
> +  g_thread_new ("map-drive", map_drive, NULL);
> +
>    while (!quit_service) {
>        run_service ();
>        g_usleep (G_USEC_PER_SEC);
> --
> 2.4.3
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
> 
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]