Browse Source

[image] Redact password from URIs displayed by imgfetch()

tags/v0.9.7
Michael Brown 15 years ago
parent
commit
3206e470d0
1 changed files with 12 additions and 1 deletions
  1. 12
    1
      src/usr/imgmgmt.c

+ 12
- 1
src/usr/imgmgmt.c View File

43
  */
43
  */
44
 int imgfetch ( struct image *image, const char *uri_string,
44
 int imgfetch ( struct image *image, const char *uri_string,
45
 	       int ( * image_register ) ( struct image *image ) ) {
45
 	       int ( * image_register ) ( struct image *image ) ) {
46
+	char uri_string_redacted[ strlen ( uri_string ) + 3 /* "***" */
47
+				  + 1 /* NUL */ ];
46
 	struct uri *uri;
48
 	struct uri *uri;
49
+	const char *password;
47
 	int rc;
50
 	int rc;
48
 
51
 
49
 	if ( ! ( uri = parse_uri ( uri_string ) ) )
52
 	if ( ! ( uri = parse_uri ( uri_string ) ) )
51
 
54
 
52
 	image_set_uri ( image, uri );
55
 	image_set_uri ( image, uri );
53
 
56
 
57
+	/* Redact password portion of URI, if necessary */
58
+	password = uri->password;
59
+	if ( password )
60
+		uri->password = "***";
61
+	unparse_uri ( uri_string_redacted, sizeof ( uri_string_redacted ),
62
+		      uri );
63
+	uri->password = password;
64
+
54
 	if ( ( rc = create_downloader ( &monojob, image, image_register,
65
 	if ( ( rc = create_downloader ( &monojob, image, image_register,
55
 					LOCATION_URI, uri ) ) == 0 )
66
 					LOCATION_URI, uri ) ) == 0 )
56
-		rc = monojob_wait ( uri_string );
67
+		rc = monojob_wait ( uri_string_redacted );
57
 
68
 
58
 	uri_put ( uri );
69
 	uri_put ( uri );
59
 	return rc;
70
 	return rc;

Loading…
Cancel
Save