Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly set config directory permissions at first start #1132

Merged
merged 2 commits into from Nov 8, 2020

Conversation

abraunegg
Copy link
Owner

  • When ~/.config/onedrive/ gets created for the first time, directory permissions are not set, thus, effective permissions of 'd---------' get applied. This then causes issues attempting to update the 'refresh_token' as permission is denied.
  • When permission is denied, the file exception error is not correctly handled

* When ~/.config/onedrive/ gets created for the first time, directory permissions are not set, thus, effective permissions of 'd---------' get applied. This then causes issues attempting to update the 'refresh_token' as permission is denied.
* When permission is denied, the file exception error is not correctly handled
* Set refresh_token permissions
@abraunegg abraunegg added this to the v2.4.7 milestone Nov 8, 2020
@abraunegg
Copy link
Owner Author

Without PR:
Clean install, first run

(dmd-2.094.1)alex@ubuntu-20-LTS:~/code/onedrive$ ./onedrive --synchronize --verbose
Using 'user' Config Dir: /home/alex/.config/onedrive
Using 'system' Config Dir: /etc/onedrive
No user or system config file found, using application defaults
Initializing the OneDrive API ...
Configuring Global Azure AD Endpoints
Authorize this app visiting:

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=d50ca740-c83f-4d1b-b616-12c519384f0c&scope=Files.ReadWrite%20Files.ReadWrite.all%20Sites.Read.All%20Sites.ReadWrite.All%20offline_access&response_type=code&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient

Enter the response uri: https://login.microsoftonline.com/common/oauth2/nativeclient?code=M.R3_BL2.6b775cc9-310f-9f44-e52a-815988174c9c
std.file.FileException@std/file.d(837): /home/alex/.config/onedrive/refresh_token: Permission denied
----------------
/home/alex/dlang/dmd-2.094.1/linux/bin64/../../src/phobos/std/file.d:283 @trusted bool std.file.cenforce!(bool).cenforce(bool, scope const(char)[], scope const(char)*, immutable(char)[], ulong) [0x5581838eb488]
??:? @trusted void std.file.writeImpl(scope const(char)[], scope const(char)*, scope const(void)[], bool) [0x5581839d299d]
/home/alex/dlang/dmd-2.094.1/linux/bin64/../../src/phobos/std/file.d:745 @safe void std.file.write!(immutable(char)[]).write(immutable(char)[], const(void[])) [0x55818393e4b1]
src/onedrive.d:724 void onedrive.OneDriveApi.acquireToken(const(char)[]) [0x55818398f3aa]
src/onedrive.d:698 void onedrive.OneDriveApi.redeemToken(const(char)[]) [0x55818398f0cc]
src/onedrive.d:389 bool onedrive.OneDriveApi.authorize() [0x55818398d44e]
src/onedrive.d:319 bool onedrive.OneDriveApi.init() [0x55818398ce4f]
src/main.d:575 _Dmain [0x558183985eda]
(dmd-2.094.1)alex@ubuntu-20-LTS:~/code/onedrive$ 
alex@ubuntu-20-LTS:~$ ls -la ~/.config/ | grep onedrive
d---------  2 alex alex 4096 Nov  9 07:18 onedrive
alex@ubuntu-20-LTS:~$ 

With PR:

(dmd-2.094.1)alex@ubuntu-20-LTS:~/code/onedrive-pr1132$ ./onedrive --synchronize --verbose
Using 'user' Config Dir: /home/alex/.config/onedrive
Using 'system' Config Dir: /etc/onedrive
No user or system config file found, using application defaults
Initializing the OneDrive API ...
Configuring Global Azure AD Endpoints
Authorize this app visiting:

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=d50ca740-c83f-4d1b-b616-12c519384f0c&scope=Files.ReadWrite%20Files.ReadWrite.all%20Sites.Read.All%20Sites.ReadWrite.All%20offline_access&response_type=code&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient

Enter the response uri: https://login.microsoftonline.com/common/oauth2/nativeclient?code=M.R3_BL2.8267562f-cc1a-bd8f-cf3d-00b3391d4c0e
Opening the item database ...
All operations will be performed in: /home/alex/OneDrive
Application version: v2.4.6-24-gd063f62
Account Type: personal
Default Drive ID: 66d53be8a5056eca
Default Root ID: 66D53BE8A5056ECA!101
Remaining Free Space: 5368708865
Fetching details for OneDrive Root
OneDrive Root does not exist in the database. We need to add it.
Added OneDrive Root to the local database
Initializing the Synchronization Engine ...
Syncing changes from OneDrive ...
Applying changes of Path ID: 66D53BE8A5056ECA!101
Updated Remaining Free Space: 5368708865
Processing 26 OneDrive items to ensure consistent local state
Number of items from OneDrive to process: 1
Uploading differences of ~/OneDrive
Processing .
The directory has not changed
Processing random_videos
The directory has not changed
Processing Dropbox
The directory has not changed
Processing Images
The directory has not changed
Processing Images/image003.jpg
The file has not changed
Processing Music
The directory has not changed
Processing Music/audio003.mp3
The file has not changed
Processing Documents
The directory has not changed
Processing Documents/Images
The directory has not changed
Processing Documents/Images/image001.jpg
The file has not changed
Processing Documents/Music
The directory has not changed
Processing Documents/Music/audio001.mp3
The file has not changed
Processing Documents/Uni
The directory has not changed
Processing Documents/Uni/01
The directory has not changed
Processing Documents/Uni/01/asdfasdf.txt
The file has not changed
Processing Documents/Uni/02
The directory has not changed
Processing Documents/Uni/02/qwerqwer.txt
The file has not changed
Processing Documents/Uni/03
The directory has not changed
Processing Documents/Uni/03/zxcvzxcvzxcv.txt
The file has not changed
Processing Documents/Uni/04
The directory has not changed
Processing Documents/Uni/04/fghjfghjfghj.txt
The file has not changed
Processing Documents/Uni/05
The directory has not changed
Processing Documents/Uni/05/dfghdfghdfgh.txt
The file has not changed
Processing random_files
The directory has not changed
Processing random_images
The directory has not changed
Uploading new items of ~/OneDrive
Applying changes of Path ID: 66D53BE8A5056ECA!101
Updated Remaining Free Space: 5368708865
(dmd-2.094.1)alex@ubuntu-20-LTS:~/code/onedrive-pr1132$ 
alex@ubuntu-20-LTS:~$ ls -la ~/.config/ | grep onedrive
drwx------  2 alex alex 4096 Nov  9 07:18 onedrive
alex@ubuntu-20-LTS:~$ 

Copy link
Collaborator

@norbusan norbusan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah well, yesssss, missing explicit configuration of the directory permission setting initializes it to 0, which is not a very good bitmask. Good catch!

@abraunegg abraunegg merged commit 2c80033 into master Nov 8, 2020
@abraunegg abraunegg deleted the fix-permissions-config-dir branch November 8, 2020 21:06
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants