about summary refs log tree commit diff
path: root/src/n-dhcp4
diff options
context:
space:
mode:
authorSebastien Bacher <seb128@ubuntu.com>2021-08-25 15:23:22 +0200
committerSebastien Bacher <seb128@ubuntu.com>2021-08-25 15:23:22 +0200
commitcfb80376641fa49137b9996130352697e7f8b436 (patch)
tree4ac3eb90a08f27a8bff2372052f8ae78f7e7c3aa /src/n-dhcp4
parent35779c6675728fa6f0fd0a21cefb904408509c23 (diff)
New upstream version 1.32.10
Diffstat (limited to 'src/n-dhcp4')
-rw-r--r--src/n-dhcp4/src/n-dhcp4-c-lease.c44
-rw-r--r--src/n-dhcp4/src/n-dhcp4.h3
2 files changed, 43 insertions, 4 deletions
diff --git a/src/n-dhcp4/src/n-dhcp4-c-lease.c b/src/n-dhcp4/src/n-dhcp4-c-lease.c
index 515814d4..bae2f674 100644
--- a/src/n-dhcp4/src/n-dhcp4-c-lease.c
+++ b/src/n-dhcp4/src/n-dhcp4-c-lease.c
@@ -249,9 +249,11 @@ _c_public_ void n_dhcp4_client_lease_get_lifetime(NDhcp4ClientLease *lease, uint
  * Gets the address contained in the server-identifier DHCP option, in network
  * byte order.
  *
- * Return: 0 on success, negative error code on failure.
+ * Return: 0 on success,
+ *         N_DHCP4_E_UNSET if the lease doesn't contain a server-identifier, or
+ *         N_DCHP4_E_INTERNAL if the server-identifier is not valid.
  */
-_c_public_ int n_dhcp4_client_lease_get_server_identifier (NDhcp4ClientLease *lease, struct in_addr *addr) {
+_c_public_ int n_dhcp4_client_lease_get_server_identifier(NDhcp4ClientLease *lease, struct in_addr *addr) {
         uint8_t *data;
         size_t n_data;
         int r;
@@ -260,7 +262,7 @@ _c_public_ int n_dhcp4_client_lease_get_server_identifier (NDhcp4ClientLease *le
         if (r)
                 return r;
         if (n_data < sizeof(struct in_addr))
-                return N_DHCP4_E_MALFORMED;
+                return N_DHCP4_E_INTERNAL;
 
         memcpy(addr, data, sizeof(struct in_addr));
 
@@ -268,6 +270,42 @@ _c_public_ int n_dhcp4_client_lease_get_server_identifier (NDhcp4ClientLease *le
 }
 
 /**
+ * n_dhcp4_client_lease_get_file() - query the lease for the boot file name
+ * @lease:                      the lease to operate on
+ * @file:                       return argument for the file name
+ *
+ * Query the lease for the boot file name from the DHCP header. The file name
+ * is returned as a NULL-terminated string.
+ *
+ * Return: 0 on success,
+ *         N_DHCP4_E_UNSET if the lease does not contain a file name, or
+ *         N_DCHP4_E_INTERNAL if the file name is invalid.
+ */
+_c_public_ int n_dhcp4_client_lease_get_file(NDhcp4ClientLease *lease, const char **file) {
+        NDhcp4Message *message;
+
+        if (lease->message->options[N_DHCP4_OPTION_OVERLOAD].size > 0
+            && ((*lease->message->options[N_DHCP4_OPTION_OVERLOAD].value) & N_DHCP4_OVERLOAD_FILE)) {
+            /* The field is overloaded to contain other options */
+            return N_DHCP4_E_UNSET;
+        }
+
+        message = &lease->message->message;
+
+        if (message->file[0] == '\0')
+            return N_DHCP4_E_UNSET;
+
+        if (!memchr(message->file, '\0', sizeof(message->file))) {
+            /* The field is NULL-terminated (RFC 2131 section 2) */
+            return N_DHCP4_E_INTERNAL;
+        }
+
+        *file = (const char *) message->file;
+
+        return 0;
+}
+
+/**
  * n_dhcp4_client_lease_query() - query the lease for an option
  * @lease:                      the lease to operate on
  * @option:                     the DHCP4 option code
diff --git a/src/n-dhcp4/src/n-dhcp4.h b/src/n-dhcp4/src/n-dhcp4.h
index 435c5600..8493a487 100644
--- a/src/n-dhcp4/src/n-dhcp4.h
+++ b/src/n-dhcp4/src/n-dhcp4.h
@@ -171,7 +171,8 @@ void n_dhcp4_client_lease_get_siaddr(NDhcp4ClientLease *lease, struct in_addr *s
 void n_dhcp4_client_lease_get_basetime(NDhcp4ClientLease *lease, uint64_t *ns_basetimep);
 void n_dhcp4_client_lease_get_lifetime(NDhcp4ClientLease *lease, uint64_t *ns_lifetimep);
 int n_dhcp4_client_lease_query(NDhcp4ClientLease *lease, uint8_t option, uint8_t **datap, size_t *n_datap);
-int n_dhcp4_client_lease_get_server_identifier (NDhcp4ClientLease *lease, struct in_addr *addr);
+int n_dhcp4_client_lease_get_server_identifier(NDhcp4ClientLease *lease, struct in_addr *addr);
+int n_dhcp4_client_lease_get_file(NDhcp4ClientLease *lease, const char **file);
 
 int n_dhcp4_client_lease_select(NDhcp4ClientLease *lease);
 int n_dhcp4_client_lease_accept(NDhcp4ClientLease *lease);