radcli_avp_add_username(3)

πŸ“¦ version 2.0.1, in arch rolling

πŸ’– radcli_avp_add_username πŸ’–

okay so bestie, this is a page from the Radius client library (section 3 of the manuals, iykyk), and it's genuinely one of the more thoughtful little functions out there. let me tell you all about it 🫢


✨ NAME ✨

radcli_avp_add_username β€” appends a User-Name AVP, and it'll tack on a realm as "username@realm" β€” but only if the username you handed it doesn't already have a realm in there. the way it just knows? iconic. πŸ‘‘


🌸 SYNOPSIS 🌸

#include <radcli/>

int radcli_avp_add_username(
    radcli_avp_list   *list,
    const radcli_ctx  *ctx,
    const char        *username,
    const char        *realm
);

πŸ¦‹ DESCRIPTION πŸ¦‹

so this one was literally written for callers β€” think an application that's reading its own "default_realm" config knob β€” that need to send "username@realm" only when the caller-supplied username didn't already come with a realm attached. like, no double-realm situations here, we're not doing that today πŸ’…

and here's the cute part: if you pass realm as NULL, it goes and reaches for ctx's own "default_realm" configuration option. so an application whose entire realm policy is just "whatever this ctx's config file says" never has to read that option out itself. literally so convenient, obsessed 😭✨


πŸŽ€ PARAMETERS πŸŽ€

  • list β€” the destination list. that's where the AVP lands 🏠
  • ctx β€” a context with a dictionary that defines User-Name. and yes, any radcli_ctx_new()/radcli_ctx_read_config() context qualifies, so you're probably already good 😌
  • username β€” the username itself. it gets used as-is if it already contains an '@'. respect the existing realm, periodt.
  • realm β€” the realm to append if username has no '@'. three whole moods here:
    • NULL β†’ uses ctx's own "default_realm" configuration option (and if that option is unset or empty, no realm gets appended at all, no drama)
    • "" β†’ explicitly suppresses appending a realm, even if "default_realm" is configured. sometimes you just want the username, alone, thriving 🌈
    • any other string β†’ used verbatim. you said it, it ships it πŸš€

⭐ RETURN VALUE ⭐

  • 0 on success β€” slay πŸ’–
  • -1 on failure

and the failure cases, fr fr, are: no User-Name attribute in ctx's dictionary, allocation failure, or as radcli_avp_add_str(). so like, check your dictionary bestie πŸ’€


πŸ”₯ SEE ALSO πŸ”₯

the whole friend group, in order:


πŸ‘‘ sign-off πŸ‘‘

this lil masterpiece comes from radcli, dated 2026-10-10, and lives at radcli_avp_add_username(3) in the Radius client library docs. go forth and append those AVPs responsibly bestie, ily, bye πŸ’œπŸŒ·βœ¨

πŸ“¦ where this page comes from