]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/pkcs11-util.c
tree-wide: use ASSERT_PTR more
[thirdparty/systemd.git] / src / shared / pkcs11-util.c
index 27823ab219175a9bb7877c0b5d6efbe68ad11079..f5f661705ebb118ebc048168e2aecbde28a43664 100644 (file)
@@ -219,9 +219,9 @@ int pkcs11_token_login_by_pin(
                 return log_error_errno(SYNTHETIC_ERRNO(EIO),
                                        "Failed to log into security token '%s': %s", token_label, p11_kit_strerror(rv));
 
-        log_notice("PIN for token '%s' is incorrect, please try again.", token_label);
-
-        return -ENOLCK;
+        return log_notice_errno(SYNTHETIC_ERRNO(ENOLCK),
+                                "PIN for token '%s' is incorrect, please try again.",
+                                token_label);
 }
 
 int pkcs11_token_login(
@@ -275,15 +275,16 @@ int pkcs11_token_login(
 
         for (unsigned tries = 0; tries < 3; tries++) {
                 _cleanup_strv_free_erase_ char **passwords = NULL;
-                char **i, *e;
+                _cleanup_(erase_and_freep) char *envpin = NULL;
 
-                e = getenv("PIN");
-                if (e) {
-                        passwords = strv_new(e);
+                r = getenv_steal_erase("PIN", &envpin);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to acquire PIN from environment: %m");
+                if (r > 0) {
+                        passwords = strv_new(envpin);
                         if (!passwords)
                                 return log_oom();
 
-                        assert_se(unsetenv_erase("PIN") >= 0);
                 } else if (headless)
                         return log_error_errno(SYNTHETIC_ERRNO(ENOPKG), "PIN querying disabled via 'headless' option. Use the 'PIN' environment variable.");
                 else {
@@ -977,7 +978,7 @@ static int pkcs11_acquire_certificate_callback(
                 void *userdata) {
 
         _cleanup_(erase_and_freep) char *pin_used = NULL;
-        struct pkcs11_acquire_certificate_callback_data *data = userdata;
+        struct pkcs11_acquire_certificate_callback_data *data = ASSERT_PTR(userdata);
         CK_OBJECT_HANDLE object;
         int r;
 
@@ -985,7 +986,6 @@ static int pkcs11_acquire_certificate_callback(
         assert(slot_info);
         assert(token_info);
         assert(uri);
-        assert(data);
 
         /* Called for every token matching our URI */
 
@@ -1199,7 +1199,7 @@ int pkcs11_crypt_device_callback(
                 P11KitUri *uri,
                 void *userdata) {
 
-        pkcs11_crypt_device_callback_data *data = userdata;
+        pkcs11_crypt_device_callback_data *data = ASSERT_PTR(userdata);
         CK_OBJECT_HANDLE object;
         int r;
 
@@ -1207,7 +1207,6 @@ int pkcs11_crypt_device_callback(
         assert(slot_info);
         assert(token_info);
         assert(uri);
-        assert(data);
 
         /* Called for every token matching our URI */