[PATCH 08/14] ext_password: add an operation to store a password

Angelo Compagnucci angelo.compagnucci at gmail.com
Mon Nov 23 06:24:42 PST 2026


Backends could only return passwords, so another tool had to write
them to the backend. Add an optional set operation that stores a
password by name and replaces the old one. Backends without it still
work, and ext_password_set() fails for them.

The pkcs11 backend implements it in the next commit, and it is tested
there.

Signed-off-by: Angelo Compagnucci <angelo.compagnucci at gmail.com>
---
 src/utils/ext_password.c   | 21 +++++++++++++++++++++
 src/utils/ext_password.h   |  3 +++
 src/utils/ext_password_i.h |  1 +
 3 files changed, 25 insertions(+)

diff --git a/src/utils/ext_password.c b/src/utils/ext_password.c
index 3f59167d7..762039778 100644
--- a/src/utils/ext_password.c
+++ b/src/utils/ext_password.c
@@ -84,6 +84,27 @@ struct wpabuf * ext_password_get(struct ext_password_data *data,
 }
 
 
+/**
+ * ext_password_set - Store a password in the external backend
+ * @data: External password backend
+ * @name: Name of the password to store
+ * @pw: Password to store
+ * Returns: 0 on success, -1 on failure or if the backend cannot store
+ *
+ * An existing password with the same name is replaced.
+ */
+int ext_password_set(struct ext_password_data *data, const char *name,
+		     const struct wpabuf *pw)
+{
+	if (!data || !data->backend->set) {
+		wpa_printf(MSG_DEBUG,
+			   "EXT PW: Backend does not support storing passwords");
+		return -1;
+	}
+	return data->backend->set(data->priv, name, pw);
+}
+
+
 struct wpabuf * ext_password_alloc(size_t len)
 {
 	struct wpabuf *buf;
diff --git a/src/utils/ext_password.h b/src/utils/ext_password.h
index e3e46ea08..25fb988af 100644
--- a/src/utils/ext_password.h
+++ b/src/utils/ext_password.h
@@ -19,6 +19,8 @@ void ext_password_deinit(struct ext_password_data *data);
 
 struct wpabuf * ext_password_get(struct ext_password_data *data,
 				 const char *name);
+int ext_password_set(struct ext_password_data *data, const char *name,
+		     const struct wpabuf *pw);
 void ext_password_free(struct wpabuf *pw);
 
 #else /* CONFIG_EXT_PASSWORD */
@@ -26,6 +28,7 @@ void ext_password_free(struct wpabuf *pw);
 #define ext_password_init(b, p) ((void *) 1)
 #define ext_password_deinit(d) do { } while (0)
 #define ext_password_get(d, n) (NULL)
+#define ext_password_set(d, n, p) (-1)
 #define ext_password_free(p) do { } while (0)
 
 #endif /* CONFIG_EXT_PASSWORD */
diff --git a/src/utils/ext_password_i.h b/src/utils/ext_password_i.h
index da0ee738a..496a34be4 100644
--- a/src/utils/ext_password_i.h
+++ b/src/utils/ext_password_i.h
@@ -16,6 +16,7 @@ struct ext_password_backend {
 	void * (*init)(const char *params);
 	void (*deinit)(void *ctx);
 	struct wpabuf * (*get)(void *ctx, const char *name);
+	int (*set)(void *ctx, const char *name, const struct wpabuf *pw);
 };
 
 struct wpabuf * ext_password_alloc(size_t len);
-- 
2.53.0




More information about the Hostap mailing list