Reputation: 838
I have a windows desktop app (written in Delphi) that allows users to store and retrieve files.
Currently we have to allow every user of the app access to the shared folder, so a malicious user could find the directory and gain access to all of the files.
Is there a way that the app can act as a specific user such that only the "app as a user" and not each individual needs permission to the shared folder?
Upvotes: 2
Views: 1854
Reputation: 597156
You need to either:
1) run the app as the desired user.
2) have your code programmably impersonate the desired user, via LogonUser()
and ImpersonateLoggedOnUser()
, or other similar functions, before then accessing the shared folder. Don't forget to stop impersonating when you are finished using the folder.
Upvotes: 5
Reputation: 4902
Not with standard file sharing -- the application is always going to running in the security context of the logged in user.
There's 2 obvious solutions I can see:
It's possible that #2 could be implemented with something like WebDAV, FTP/SFTP/FTPS, or some other "already done" file transfer protocol that you can piggy back off of to save you some work.
Upvotes: 1
Reputation: 84610
Not directly, no. The app has exactly the same rights as its user has. That's part of the OS's security model. If I had to deal with something like this, I'd do it this way:
Create a second program that runs as a Service, and set it to run under a user account that has access to the shared folder. It should implement some sort of validation logic, and listen for incoming messages. (What exact method it uses for this is up to you, but you're essentially creating a server.)
Your desktop app runs under the limited user accounts. To request a file, it sends a message to the server, in which it identifies the user and the request it's making.
The server checks the request, and if it's valid, retrieves the file and passes it back to the user app. If not, it should return some sort of error message.
Upvotes: 1