diff --git a/src/confd/bin/bootstrap b/src/confd/bin/bootstrap index 68a1a571..fac6de30 100755 --- a/src/confd/bin/bootstrap +++ b/src/confd/bin/bootstrap @@ -225,7 +225,7 @@ sysrepoctl -s $SEARCH \ -i infix-lldp@2023-08-23.yang -g wheel -p 0660 \ -i infix-dhcp-client@2024-01-30.yang -g wheel -p 0660 \ -i infix-shell-type@2023-08-21.yang -g wheel -p 0660 \ - -i infix-system@2023-10-19.yang -g wheel -p 0660 \ + -i infix-system@2024-02-29.yang -g wheel -p 0660 \ -i infix-services@2023-10-16.yang -g wheel -p 0660 \ -i ieee802-ethernet-interface@2019-06-21.yang -g wheel -p 0660 \ -i infix-ethernet-interface@2024-02-27.yang -g wheel -p 0660 \ diff --git a/src/confd/bin/gen-motd b/src/confd/bin/gen-motd index e73f22f1..a6f0940f 100644 --- a/src/confd/bin/gen-motd +++ b/src/confd/bin/gen-motd @@ -6,7 +6,7 @@ if [ -f /etc/motd ]; then cat < #include +#include "base64.h" #include "core.h" #define XPATH_BASE_ "/ietf-system:system" @@ -1028,12 +1029,63 @@ static int change_motd(sr_session_ctx_t *session, uint32_t sub_id, const char *m if (message) { rc = writesf(message, "w", "%s", fn); free(message); + } + + if (rc) { + ERRNO("failed saving %s", fn); + return SR_ERR_SYS; + } + + return SR_ERR_OK; +} + +static int change_motd_banner(sr_session_ctx_t *session, uint32_t sub_id, const char *module, + const char *xpath, sr_event_t event, unsigned request_id, void *priv) +{ + const char *fn = "/etc/motd"; + unsigned char *raw, *txt; + size_t txt_len; + char *legacy; + int rc = 0; + + /* Ignore all events except SR_EV_DONE */ + if (event != SR_EV_DONE) + return SR_ERR_OK; + + legacy = srx_get_str(session, "/ietf-system:system/infix-sys:motd"); + if (legacy) { + NOTE("Legacy /system/motd exists, skipping %s", xpath); + free(legacy); + return SR_ERR_OK; + } + + raw = (unsigned char *)srx_get_str(session, "%s", xpath); + if (raw) { + txt = base64_decode(raw, strlen((char *)raw), &txt_len); + if (!txt) { + ERRNO("failed base64 decoding of %s", xpath); + rc = -1; + } else { + FILE *fp = fopen(fn, "w"); + + if (!fp) { + rc = -1; + } else { + if (fwrite(txt, txt_len, sizeof(txt[0]), fp) != txt_len) + rc = -1; + fclose(fp); + } + + free(txt); + } + + free(raw); } else { (void)remove(fn); } if (rc) { - ERROR("failed writing /etc/motd: %s", strerror(errno)); + ERRNO("failed saving %s", fn); return SR_ERR_SYS; } @@ -1137,6 +1189,7 @@ int ietf_system_init(struct confd *confd) REGISTER_CHANGE(confd->session, "ietf-system", XPATH_AUTH_, 0, change_auth, confd, &confd->sub); REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/hostname", 0, change_hostname, confd, &confd->sub); REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/infix-system:motd", 0, change_motd, confd, &confd->sub); + REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/infix-system:motd-banner", 0, change_motd_banner, confd, &confd->sub); REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/clock", 0, change_clock, confd, &confd->sub); REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/ntp", 0, change_ntp, confd, &confd->sub); REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/dns-resolver", 0, change_dns, confd, &confd->sub); diff --git a/src/confd/yang/infix-system@2023-10-19.yang b/src/confd/yang/infix-system@2024-02-29.yang similarity index 69% rename from src/confd/yang/infix-system@2023-10-19.yang rename to src/confd/yang/infix-system@2024-02-29.yang index 9ec7a96c..7db96eb7 100644 --- a/src/confd/yang/infix-system@2023-10-19.yang +++ b/src/confd/yang/infix-system@2024-02-29.yang @@ -19,6 +19,11 @@ module infix-system { contact "kernelkit@googlegroups.com"; description "Infix augments and deviations to ietf-system."; + revision 2024-02-29 { + description "Mark infix-sys:motd as deprecated, to be replaced with type binary."; + reference "internal"; + } + revision 2023-10-19 { description "Change deviation for timezone-utc-offset from unsupported to Etc+/-HOUR - Unit is set to hours (tzdata compatibility) @@ -26,6 +31,7 @@ module infix-system { reference "internal"; } + revision 2023-08-15 { description "Add support for user login shell. @@ -60,9 +66,31 @@ module infix-system { augment "/sys:system" { description "Augment of ietf-system for modifying /etc/motd."; + leaf motd { + description "Legacy MotD (Message of the Day), shown after login. + + Please note, this is obsolete! When set it overrides the + 'motd-banner' setting for backwards compatibility. + + Instead, use 'motd-banner', which takes a base64 encoded + text file as an argument. For CLI users, edit with the + 'text-editor motd-banner' command."; + status obsolete; // Replaced with motd-banner (binary) type string; - description "Set the MotD (Message of the Day), shown after login"; + } + + // From openconfig-system, which also has login-banner (TODO) + leaf motd-banner { + description "Message of the Day (MotD), shown after SSH/console login. + + Base64 encoded (binary) file contents for the system file + /etc/motd, displayed after SSH/console login. + + They system may append additional standard information such + as the current system date and time, uptime, last login + timestamp, etc."; + type binary; } }