@@ -59,12 +59,65 @@ pub mod fs;
59
59
pub mod parser;
60
60
pub mod values;
61
61
62
- // mod de;
63
- // mod ser;
64
- // mod error;
65
- // pub use de::{from_str, Deserializer};
66
- // pub use error::{Error, Result};
67
- // pub use ser::{to_string, Serializer};
62
+ mod permissions {
63
+ use crate :: Permissions ;
64
+
65
+ impl Permissions {
66
+ /// Allow everything which usually relates to a fully trusted environment
67
+ pub fn all ( ) -> Self {
68
+ use git_sec:: Permission :: * ;
69
+ Permissions {
70
+ system : Allow ,
71
+ global : Allow ,
72
+ user : Allow ,
73
+ repository : Allow ,
74
+ worktree : Allow ,
75
+ env : Allow ,
76
+ includes : Allow ,
77
+ }
78
+ }
79
+
80
+ /// If in doubt, this configuration can be used to safely load configuration from sources which is usually trusted,
81
+ /// that is system and user configuration. Do load any configuration that isn't trusted as it's now owned by the current user.
82
+ pub fn secure ( ) -> Self {
83
+ use git_sec:: Permission :: * ;
84
+ Permissions {
85
+ system : Allow ,
86
+ global : Allow ,
87
+ user : Allow ,
88
+ repository : Deny ,
89
+ worktree : Deny ,
90
+ env : Allow ,
91
+ includes : Deny ,
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+ /// Configure security relevant options when loading a git configuration.
98
+ #[ derive( Copy , Clone , Ord , PartialOrd , PartialEq , Eq , Debug , Hash ) ]
99
+ #[ cfg_attr( feature = "serde1" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
100
+ pub struct Permissions {
101
+ /// How to use the system configuration.
102
+ /// This is defined as `$(prefix)/etc/gitconfig` on unix.
103
+ pub system : git_sec:: Permission ,
104
+ /// How to use the global configuration.
105
+ /// This is usually `~/.gitconfig`.
106
+ pub global : git_sec:: Permission ,
107
+ /// How to use the user configuration.
108
+ /// Second user-specific configuration path; if `$XDG_CONFIG_HOME` is not
109
+ /// set or empty, `$HOME/.config/git/config` will be used.
110
+ pub user : git_sec:: Permission ,
111
+ /// How to use the repository configuration.
112
+ pub repository : git_sec:: Permission ,
113
+ /// How to use worktree configuration from `config.worktree`.
114
+ // TODO: figure out how this really applies and provide more information here.
115
+ pub worktree : git_sec:: Permission ,
116
+ /// How to use the configuration from environment variables.
117
+ pub env : git_sec:: Permission ,
118
+ /// What to do when include files are encountered in loaded configuration.
119
+ pub includes : git_sec:: Permission ,
120
+ }
68
121
69
122
#[ cfg( test) ]
70
123
pub mod test_util;
0 commit comments