Err, correction to my cut-off sentence below.  Sorry about that.

On 1/7/26 17:18, Collin Walling wrote:

[...]

>> +    for (list = path_list; list; list = list->next) {
>> +        cert_path = list->value->path;
>> +
>> +        if (g_strcmp0(cert_path, "") == 0) {
>> +            error_setg(errp, "Empty path in certificate path list is not 
>> allowed");
>> +            goto fail;
>> +        }
>> +
>> +        if (stat(cert_path, &st) != 0) {
>> +            error_setg(errp, "Failed to stat path '%s': %s",
>> +                       cert_path, g_strerror(errno));
>> +            goto fail;
>> +        }
>> +
>> +        if (S_ISREG(st.st_mode)) {
>> +            if (!g_str_has_suffix(cert_path, ".pem")) {
>> +                error_setg(errp, "Certificate file '%s' must have a .pem 
>> extension",
>> +                           cert_path);
>> +                goto fail;
>> +            }
>> +
>> +            g_ptr_array_add(cert_path_builder, g_strdup(cert_path));
>> +        } else if (S_ISDIR(st.st_mode)) {
>> +            dir = g_dir_open(cert_path, 0, &err);
>> +            if (dir == NULL) {
>> +                error_setg(errp, "Failed to open directory '%s': %s",
>> +                           cert_path, err->message);
>> +
>> +                goto fail;
>> +            }
>> +
>> +            while ((filename = g_dir_read_name(dir))) {
>> +                if (g_str_has_suffix(filename, ".pem")) {
>> +                    g_ptr_array_add(cert_path_builder,
>> +                                    g_build_filename(cert_path, filename, 
>> NULL));
>> +                }
>> +            }
>> +
>> +            g_dir_close(dir);

Does this mean that an empty directory or one that does not contain any
.pem files is allowed?  Should at least a warning message should be
printed?  Also, if a file found within the directory is not a .pem,
should that be reported as well?

Another approach is to first iterate through each directory and resolve
the path of *every file* and append them to the end of `list` ignoring
sub directories).  Throw a warn/err if empty dir.  Then continue to
iterate each file in `list`.

>> +        } else {
>> +            error_setg(errp, "Path '%s' is neither a file nor a directory", 
>> cert_path);
>> +            goto fail;
>> +        }
>> +    }
>> +
>> +    qapi_free_BootCertificatesList(path_list);
>> +    return g_steal_pointer(&cert_path_builder);
>> +
>> +fail:
>> +    qapi_free_BootCertificatesList(path_list);
>> +    return NULL;
>> +}


-- 
Regards,
  Collin

Reply via email to