@@ -152,23 +152,28 @@ def _parse(self, file, fp, default_netrc):
152152 else :
153153 raise NetrcParseError ("bad follower token %r" % tt ,
154154 file , lexer .lineno )
155- self ._security_check (fp , default_netrc , self .hosts [entryname ][0 ])
156-
157- def _security_check (self , fp , default_netrc , login ):
158- if _can_security_check () and default_netrc and login != "anonymous" :
159- prop = os .fstat (fp .fileno ())
160- current_user_id = os .getuid ()
161- if prop .st_uid != current_user_id :
162- fowner = _getpwuid (prop .st_uid )
163- user = _getpwuid (current_user_id )
164- raise NetrcParseError (
165- f"~/.netrc file owner ({ fowner } ) does not match"
166- f" current user ({ user } )" )
167- if (prop .st_mode & (stat .S_IRWXG | stat .S_IRWXO )):
168- raise NetrcParseError (
169- "~/.netrc access too permissive: access"
170- " permissions must restrict access to only"
171- " the owner" )
155+
156+ if _can_security_check () and default_netrc :
157+ for entry in self .hosts .values ():
158+ if entry [0 ] != "anonymous" :
159+ # Raises on security issue; once passed once can exit.
160+ self ._security_check (fp )
161+ return
162+
163+ def _security_check (self , fp ):
164+ prop = os .fstat (fp .fileno ())
165+ current_user_id = os .getuid ()
166+ if prop .st_uid != current_user_id :
167+ fowner = _getpwuid (prop .st_uid )
168+ user = _getpwuid (current_user_id )
169+ raise NetrcParseError (
170+ f"~/.netrc file owner ({ fowner } ) does not match"
171+ f" current user ({ user } )" )
172+ if (prop .st_mode & (stat .S_IRWXG | stat .S_IRWXO )):
173+ raise NetrcParseError (
174+ "~/.netrc access too permissive: access"
175+ " permissions must restrict access to only"
176+ " the owner" )
172177
173178 def authenticators (self , host ):
174179 """Return a (user, account, password) tuple for given host."""
0 commit comments