[2748] in BarnOwl Developers
Re: [PATCH] zephyr: update smartstrip logic
daemon@ATHENA.MIT.EDU (David A Benjamin)
Sun Nov 7 01:46:41 2010
Date: Sun, 7 Nov 2010 01:46:36 -0500 (EST)
From: David A Benjamin <davidben@MIT.EDU>
To: =?ISO-8859-15?Q?Alejandro_R=2E_Sede=F1o?= <asedeno@mit.edu>
cc: barnowl-dev@mit.edu
In-Reply-To: <1288902190-2108-1-git-send-email-asedeno@mit.edu>
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
---1257051904-273219423-1289112396=:15631
Content-Type: TEXT/PLAIN; charset=UTF-8; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE
LGTM
On Thu, 4 Nov 2010, Alejandro R. Sede=C3=B1o wrote:
> * Deal with krb5 principal types first, then krb4 princiapl types.
> * Special case principals that start with 'host/', 'daemon/', 'rcmd.', an=
d 'daemon.'.
> * Drop special case for webzephyr as it is now taken care of by the more =
general case above.
>
> Signed-off-by: Alejandro R. Sede=C3=B1o <asedeno@mit.edu>
> ---
> owl.h | 5 +++++
> zephyr.c | 33 +++++++++++++++++++--------------
> 2 files changed, 24 insertions(+), 14 deletions(-)
>
> diff --git a/owl.h b/owl.h
> index b67cd1a..ae4147f 100644
> --- a/owl.h
> +++ b/owl.h
> @@ -201,6 +201,11 @@ typedef void HV;
> #define OWL_WEBZEPHYR_CLASS "webzephyr"
> #define OWL_WEBZEPHYR_OPCODE "webzephyr"
>
> +#define OWL_ZEPHYR_NOSTRIP_HOST "host/"
> +#define OWL_ZEPHYR_NOSTRIP_RCMD "rcmd."
> +#define OWL_ZEPHYR_NOSTRIP_DAEMON5 "daemon/"
> +#define OWL_ZEPHYR_NOSTRIP_DAEMON4 "daemon."
> +
> #define OWL_REGEX_QUOTECHARS "+*.?[]^\\${}()"
> #define OWL_REGEX_QUOTEWITH "\\"
>
> diff --git a/zephyr.c b/zephyr.c
> index c50ee66..d6349e5 100644
> --- a/zephyr.c
> +++ b/zephyr.c
> @@ -1229,37 +1229,42 @@ char *long_zuser(const char *in)
> }
>
> /* strip out the instance from a zsender's principal. Preserves the
> - * realm if present. daemon/webzephyr.mit.edu is a special case.
> - * The caller must free the return.
> + * realm if present. Leave host/ and daemon/ krb5 principals
> + * alone. Also leave rcmd. and daemon. krb4 principals alone. The
> + * caller must free the return.
> */
> char *owl_zephyr_smartstripped_user(const char *in)
> {
> - char *ptr, *realm, *out;
> + char *slash, *dot, *realm, *out;
>
> - out=3Dowl_strdup(in);
> + out =3D owl_strdup(in);
>
> /* bail immeaditly if we don't have to do any work */
> - ptr=3Dstrchr(out, '.');
> - if (!strchr(out, '/') && !ptr) {
> - /* no '/' and no '.' */
> + slash =3D strchr(out, '/');
> + dot =3D strchr(out, '.');
> + if (!slash && !dot) {
> return(out);
> }
> - if (ptr && strchr(out, '@') && (ptr > strchr(out, '@'))) {
> - /* There's a '.' but it's in the realm */
> +
> + if (!strncasecmp(out, OWL_ZEPHYR_NOSTRIP_HOST, strlen(OWL_ZEPHYR_NOSTR=
IP_HOST)) ||
> + !strncasecmp(out, OWL_ZEPHYR_NOSTRIP_RCMD, strlen(OWL_ZEPHYR_NOSTR=
IP_RCMD)) ||
> + !strncasecmp(out, OWL_ZEPHYR_NOSTRIP_DAEMON5, strlen(OWL_ZEPHYR_NO=
STRIP_DAEMON5)) ||
> + !strncasecmp(out, OWL_ZEPHYR_NOSTRIP_DAEMON4, strlen(OWL_ZEPHYR_NO=
STRIP_DAEMON4))) {
> return(out);
> }
> - if (!strncasecmp(out, OWL_WEBZEPHYR_PRINCIPAL, strlen(OWL_WEBZEPHYR_PR=
INCIPAL))) {
> +
> + realm =3D strchr(out, '@');
> + if (!slash && dot && realm && (dot > realm)) {
> + /* There's no '/', and the first '.' is in the realm */
> return(out);
> }
>
> /* remove the realm from out, but hold on to it */
> - realm=3Dstrchr(out, '@');
> if (realm) realm[0]=3D'\0';
>
> /* strip */
> - ptr=3Dstrchr(out, '.');
> - if (!ptr) ptr=3Dstrchr(out, '/');
> - ptr[0]=3D'\0';
> + if (slash) slash[0] =3D '\0'; /* krb5 style user/instance */
> + else if (dot) dot[0] =3D '\0'; /* krb4 style user.instance */
>
> /* reattach the realm if we had one */
> if (realm) {
> --=20
> 1.7.3.2
>
>
---1257051904-273219423-1289112396=:15631--