1 /* $NetBSD: parse-config.c,v 1.12 2009/10/21 17:10:36 joerg Exp $ */
10 __RCSID("$NetBSD: parse-config.c,v 1.12 2009/10/21 17:10:36 joerg Exp $");
13 * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
14 * All rights reserved.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in
24 * the documentation and/or other materials provided with the
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
35 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
37 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 const char *config_file
= SYSCONFDIR
"/pkg_install.conf";
53 char fetch_flags
[10] = ""; /* Workaround Mac OS X linker issues with BSS */
54 static const char *active_ftp
;
55 static const char *verbose_netio
;
56 static const char *ignore_proxy
;
57 const char *cache_index
= "yes";
58 const char *cert_chain_file
;
59 const char *certs_packages
;
60 const char *certs_pkg_vulnerabilities
;
61 const char *check_vulnerabilities
;
62 const char *config_pkg_path
;
63 const char *do_license_check
;
64 const char *verified_installation
;
66 const char *gpg_keyring_pkgvuln
;
67 const char *gpg_keyring_sign
;
68 const char *gpg_keyring_verify
;
69 const char *gpg_sign_as
;
70 const char *pkg_vulnerabilities_dir
;
71 const char *pkg_vulnerabilities_file
;
72 const char *pkg_vulnerabilities_url
;
73 const char *ignore_advisories
= NULL
;
74 const char tnf_vulnerability_base
[] = "http://ftp.NetBSD.org/pub/NetBSD/packages/vulns";
75 const char *acceptable_licenses
= NULL
;
77 static struct config_variable
{
80 } config_variables
[] = {
81 { "ACCEPTABLE_LICENSES", &acceptable_licenses
},
82 { "ACTIVE_FTP", &active_ftp
},
83 { "CACHE_INDEX", &cache_index
},
84 { "CERTIFICATE_ANCHOR_PKGS", &certs_packages
},
85 { "CERTIFICATE_ANCHOR_PKGVULN", &certs_pkg_vulnerabilities
},
86 { "CERTIFICATE_CHAIN", &cert_chain_file
},
87 { "CHECK_LICENSE", &do_license_check
},
88 { "CHECK_VULNERABILITIES", &check_vulnerabilities
},
89 { "DEFAULT_ACCEPTABLE_LICENSES", &default_acceptable_licenses
},
91 { "GPG_KEYRING_PKGVULN", &gpg_keyring_pkgvuln
},
92 { "GPG_KEYRING_SIGN", &gpg_keyring_sign
},
93 { "GPG_KEYRING_VERIFY", &gpg_keyring_verify
},
94 { "GPG_SIGN_AS", &gpg_sign_as
},
95 { "IGNORE_PROXY", &ignore_proxy
},
96 { "IGNORE_URL", &ignore_advisories
},
97 { "PKG_PATH", &config_pkg_path
},
98 { "PKGVULNDIR", &pkg_vulnerabilities_dir
},
99 { "PKGVULNURL", &pkg_vulnerabilities_url
},
100 { "VERBOSE_NETIO", &verbose_netio
},
101 { "VERIFIED_INSTALLATION", &verified_installation
},
102 { NULL
, NULL
}, /* For use by pkg_install_show_variable */
106 char *config_tmp_variables
[sizeof config_variables
/sizeof config_variables
[0]];
109 parse_pkg_install_conf(void)
111 struct config_variable
*var
;
114 size_t len
, var_len
, i
;
116 fp
= fopen(config_file
, "r");
119 warn("Can't open '%s' for reading", config_file
);
123 while ((line
= fgetln(fp
, &len
)) != (char *) NULL
) {
124 if (line
[len
- 1] == '\n')
126 for (i
= 0; (var
= &config_variables
[i
])->name
!= NULL
; ++i
) {
127 var_len
= strlen(var
->name
);
128 if (strncmp(var
->name
, line
, var_len
) != 0)
130 if (line
[var_len
] != '=')
134 if (config_tmp_variables
[i
])
135 value
= xasprintf("%s\n%.*s",
136 config_tmp_variables
[i
], (int)len
, line
);
138 value
= xasprintf("%.*s", (int)len
, line
);
139 free(config_tmp_variables
[i
]);
140 config_tmp_variables
[i
] = value
;
145 for (i
= 0; (var
= &config_variables
[i
])->name
!= NULL
; ++i
) {
146 if (config_tmp_variables
[i
] == NULL
)
148 *var
->var
= config_tmp_variables
[i
];
149 config_tmp_variables
[i
] = NULL
;
156 pkg_install_config(void)
160 parse_pkg_install_conf();
162 if (pkg_vulnerabilities_dir
== NULL
)
163 pkg_vulnerabilities_dir
= _pkgdb_getPKGDB_DIR();
164 pkg_vulnerabilities_file
= xasprintf("%s/pkg-vulnerabilities",
165 pkg_vulnerabilities_dir
);
166 if (pkg_vulnerabilities_url
== NULL
) {
167 pkg_vulnerabilities_url
= xasprintf("%s/pkg-vulnerabilities.gz",
168 tnf_vulnerability_base
);
170 if (verified_installation
== NULL
)
171 verified_installation
= "never";
173 if (check_vulnerabilities
== NULL
)
174 check_vulnerabilities
= "never";
176 if (do_license_check
== NULL
)
177 do_license_check
= "no";
179 if ((value
= getenv("PKG_PATH")) != NULL
)
180 config_pkg_path
= value
;
182 if (strcasecmp(cache_index
, "yes") == 0)
185 if (strcasecmp(cache_index
, "no"))
186 warnx("Invalid value for configuration option "
191 snprintf(fetch_flags
, sizeof(fetch_flags
), "%s%s%s%s",
192 (do_cache_index
) ? "c" : "",
193 (verbose_netio
&& *verbose_netio
) ? "v" : "",
194 (active_ftp
&& *active_ftp
) ? "a" : "",
195 (ignore_proxy
&& *ignore_proxy
) ? "d" : "");
199 pkg_install_show_variable(const char *var_name
)
201 struct config_variable
*var
;
202 const char *tmp_value
= NULL
;
204 for (var
= config_variables
; var
->name
!= NULL
; ++var
) {
205 if (strcmp(var
->name
, var_name
) == 0)
208 if (var
->name
== NULL
) {
209 var
->name
= var_name
;
210 var
->var
= &tmp_value
;
213 pkg_install_config();
215 if (*var
->var
!= NULL
)