[2735] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[PATCH] zephyr: update smartstrip logic

daemon@ATHENA.MIT.EDU (=?UTF-8?q?Alejandro=20R=2E=20Sede=)
Thu Nov 4 16:23:13 2010

From: =?UTF-8?q?Alejandro=20R=2E=20Sede=C3=B1o?= <asedeno@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Thu,  4 Nov 2010 16:23:10 -0400

* Deal with krb5 principal types first, then krb4 princiapl types.
* Special case principals that start with 'host/', 'daemon/', 'rcmd.', and '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Ʊo <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=owl_strdup(in);
+  out = owl_strdup(in);
 
   /* bail immeaditly if we don't have to do any work */
-  ptr=strchr(out, '.');
-  if (!strchr(out, '/') && !ptr) {
-    /* no '/' and no '.' */
+  slash = strchr(out, '/');
+  dot = 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_NOSTRIP_HOST)) ||
+      !strncasecmp(out, OWL_ZEPHYR_NOSTRIP_RCMD, strlen(OWL_ZEPHYR_NOSTRIP_RCMD)) ||
+      !strncasecmp(out, OWL_ZEPHYR_NOSTRIP_DAEMON5, strlen(OWL_ZEPHYR_NOSTRIP_DAEMON5)) ||
+      !strncasecmp(out, OWL_ZEPHYR_NOSTRIP_DAEMON4, strlen(OWL_ZEPHYR_NOSTRIP_DAEMON4))) {
     return(out);
   }
-  if (!strncasecmp(out, OWL_WEBZEPHYR_PRINCIPAL, strlen(OWL_WEBZEPHYR_PRINCIPAL))) {
+
+  realm = 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=strchr(out, '@');
   if (realm) realm[0]='\0';
 
   /* strip */
-  ptr=strchr(out, '.');
-  if (!ptr) ptr=strchr(out, '/');
-  ptr[0]='\0';
+  if (slash) slash[0] = '\0';  /* krb5 style user/instance */
+  else if (dot) dot[0] = '\0'; /* krb4 style user.instance */
 
   /* reattach the realm if we had one */
   if (realm) {
-- 
1.7.3.2


home help back first fref pref prev next nref lref last post