diff options
author | Michael Brown | 2013-12-03 17:48:56 +0100 |
---|---|---|
committer | Michael Brown | 2013-12-05 01:37:02 +0100 |
commit | 22001cb206c1320aee27f679a63d2171d35e99c5 (patch) | |
tree | a972bb914371a68d4925dcc007238dcb836546ba /src/net/tcp | |
parent | [fbcon] Add support for displaying a cursor (diff) | |
download | ipxe-22001cb206c1320aee27f679a63d2171d35e99c5.tar.gz ipxe-22001cb206c1320aee27f679a63d2171d35e99c5.tar.xz ipxe-22001cb206c1320aee27f679a63d2171d35e99c5.zip |
[settings] Explicitly separate the concept of a completed fetched setting
The fetch_setting() family of functions may currently modify the
definition of the specified setting (e.g. to add missing type
information). Clean up this interface by requiring callers to provide
an explicit buffer to contain the completed definition of the fetched
setting, if required.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net/tcp')
-rw-r--r-- | src/net/tcp/iscsi.c | 61 | ||||
-rw-r--r-- | src/net/tcp/oncrpc.c | 4 | ||||
-rw-r--r-- | src/net/tcp/syslogs.c | 10 |
3 files changed, 24 insertions, 51 deletions
diff --git a/src/net/tcp/iscsi.c b/src/net/tcp/iscsi.c index c9daf1ff..197069cc 100644 --- a/src/net/tcp/iscsi.c +++ b/src/net/tcp/iscsi.c @@ -1860,7 +1860,7 @@ enum iscsi_root_path_component { }; /** iSCSI initiator IQN setting */ -struct setting initiator_iqn_setting __setting ( SETTING_SANBOOT_EXTRA ) = { +const struct setting initiator_iqn_setting __setting ( SETTING_SANBOOT_EXTRA ) = { .name = "initiator-iqn", .description = "iSCSI initiator name", .tag = DHCP_ISCSI_INITIATOR_IQN, @@ -1868,7 +1868,7 @@ struct setting initiator_iqn_setting __setting ( SETTING_SANBOOT_EXTRA ) = { }; /** iSCSI reverse username setting */ -struct setting reverse_username_setting __setting ( SETTING_AUTH_EXTRA ) = { +const struct setting reverse_username_setting __setting ( SETTING_AUTH_EXTRA ) = { .name = "reverse-username", .description = "Reverse user name", .tag = DHCP_EB_REVERSE_USERNAME, @@ -1876,7 +1876,7 @@ struct setting reverse_username_setting __setting ( SETTING_AUTH_EXTRA ) = { }; /** iSCSI reverse password setting */ -struct setting reverse_password_setting __setting ( SETTING_AUTH_EXTRA ) = { +const struct setting reverse_password_setting __setting ( SETTING_AUTH_EXTRA ) = { .name = "reverse-password", .description = "Reverse password", .tag = DHCP_EB_REVERSE_PASSWORD, @@ -1947,46 +1947,23 @@ static int iscsi_fetch_settings ( struct iscsi_session *iscsi ) { /* Fetch relevant settings. Don't worry about freeing on * error, since iscsi_free() will take care of that anyway. */ - if ( ( len = fetch_string_setting_copy ( NULL, &username_setting, - &iscsi->initiator_username ) ) < 0 ) { - DBGC ( iscsi, "iSCSI %p could not fetch username: %s\n", - iscsi, strerror ( len ) ); - return len; - } - if ( ( len = fetch_string_setting_copy ( NULL, &password_setting, - &iscsi->initiator_password ) ) < 0 ) { - DBGC ( iscsi, "iSCSI %p could not fetch password: %s\n", - iscsi, strerror ( len ) ); - return len; - } - if ( ( len = fetch_string_setting_copy( NULL, &reverse_username_setting, - &iscsi->target_username ) ) < 0 ) { - DBGC ( iscsi, "iSCSI %p could not fetch reverse username: %s\n", - iscsi, strerror ( len ) ); - return len; - } - if ( ( len = fetch_string_setting_copy( NULL, &reverse_password_setting, - &iscsi->target_password ) ) < 0 ) { - DBGC ( iscsi, "iSCSI %p could not fetch reverse password: %s\n", - iscsi, strerror ( len ) ); - return len; - } - - /* Find a suitable initiator name */ - if ( ( len = fetch_string_setting_copy ( NULL, &initiator_iqn_setting, - &iscsi->initiator_iqn ) ) < 0 ) { - DBGC ( iscsi, "iSCSI %p could not fetch initiator IQN: %s\n", - iscsi, strerror ( len ) ); - return len; - } + fetch_string_setting_copy ( NULL, &username_setting, + &iscsi->initiator_username ); + fetch_string_setting_copy ( NULL, &password_setting, + &iscsi->initiator_password ); + fetch_string_setting_copy ( NULL, &reverse_username_setting, + &iscsi->target_username ); + fetch_string_setting_copy ( NULL, &reverse_password_setting, + &iscsi->target_password ); + + /* Use explicit initiator IQN if provided */ + fetch_string_setting_copy ( NULL, &initiator_iqn_setting, + &iscsi->initiator_iqn ); if ( iscsi->initiator_iqn ) return 0; - if ( ( len = fetch_string_setting_copy ( NULL, &hostname_setting, - &hostname ) ) < 0 ) { - DBGC ( iscsi, "iSCSI %p could not fetch hostname: %s\n", - iscsi, strerror ( len ) ); - return len; - } + + /* Otherwise, try to construct an initiator IQN from the hostname */ + fetch_string_setting_copy ( NULL, &hostname_setting, &hostname ); if ( hostname ) { len = asprintf ( &iscsi->initiator_iqn, ISCSI_DEFAULT_IQN_PREFIX ":%s", hostname ); @@ -1999,6 +1976,8 @@ static int iscsi_fetch_settings ( struct iscsi_session *iscsi ) { assert ( iscsi->initiator_iqn ); return 0; } + + /* Otherwise, try to construct an initiator IQN from the UUID */ if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting, &uuid ) ) < 0 ) { DBGC ( iscsi, "iSCSI %p has no suitable initiator IQN\n", iscsi ); diff --git a/src/net/tcp/oncrpc.c b/src/net/tcp/oncrpc.c index 819d3179..0a3b3858 100644 --- a/src/net/tcp/oncrpc.c +++ b/src/net/tcp/oncrpc.c @@ -58,14 +58,14 @@ struct oncrpc_cred oncrpc_auth_none = { .length = 0 }; -struct setting uid_setting __setting ( SETTING_AUTH ) = { +const struct setting uid_setting __setting ( SETTING_AUTH ) = { .name = "uid", .description = "User ID", .tag = DHCP_EB_UID, .type = &setting_type_uint32 }; -struct setting gid_setting __setting ( SETTING_AUTH ) = { +const struct setting gid_setting __setting ( SETTING_AUTH ) = { .name = "gid", .description = "Group ID", .tag = DHCP_EB_GID, diff --git a/src/net/tcp/syslogs.c b/src/net/tcp/syslogs.c index bcda8b45..503ed177 100644 --- a/src/net/tcp/syslogs.c +++ b/src/net/tcp/syslogs.c @@ -190,7 +190,7 @@ struct console_driver syslogs_console __console_driver = { */ /** Encrypted syslog server setting */ -struct setting syslogs_setting __setting ( SETTING_MISC ) = { +const struct setting syslogs_setting __setting ( SETTING_MISC ) = { .name = "syslogs", .description = "Encrypted syslog server", .tag = DHCP_EB_SYSLOGS_SERVER, @@ -206,15 +206,10 @@ static int apply_syslogs_settings ( void ) { static char *old_server; char *server; struct interface *socket; - int len; int rc; /* Fetch log server */ - len = fetch_string_setting_copy ( NULL, &syslogs_setting, &server ); - if ( len < 0 ) { - rc = len; - goto err_fetch_server; - } + fetch_string_setting_copy ( NULL, &syslogs_setting, &server ); /* Do nothing unless log server has changed */ if ( ( ( server == NULL ) && ( old_server == NULL ) ) || @@ -266,7 +261,6 @@ static int apply_syslogs_settings ( void ) { out_no_server: out_no_change: free ( server ); - err_fetch_server: return rc; } |