Changeset 4a212dd


Ignore:
Timestamp:
Dec 2, 2013, 3:57:31 AM (8 years ago)
Author:
Anders Kaseorg <andersk@mit.edu>
Parents:
ebc6f77 (diff), ebcdf4d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:
Merge ebcdf4d1d62cb8a947fa244068de37c0f8ad7dde into ebc6f77fe018701fba1cb7d0a39bd9f487516835
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tester.c

    r6a8b519 r21dc927  
    2525int owl_history_regtest(void);
    2626int call_filter_regtest(void);
     27int owl_smartstrip_regtest(void);
    2728
    2829extern void owl_perl_xs_init(pTHX);
     
    116117  numfailures += owl_history_regtest();
    117118  numfailures += call_filter_regtest();
     119  numfailures += owl_smartstrip_regtest();
    118120  if (numfailures) {
    119121      fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures);
     
    10181020  return numfailed;
    10191021}
     1022
     1023int owl_smartstrip_regtest(void)
     1024{
     1025  int numfailed = 0;
     1026
     1027  printf("# BEGIN testing owl_zephyr_smartstripped_user\n");
     1028
     1029#define CHECK_SMARTSTRIP(in, expected)                  \
     1030  do {                                                  \
     1031    char *__value = owl_zephyr_smartstripped_user(in);  \
     1032    FAIL_UNLESS("owl_zephyr_smartstripped_user " in,    \
     1033                strcmp((expected), __value) == 0);      \
     1034    g_free(__value);                                    \
     1035  } while (0)
     1036
     1037  CHECK_SMARTSTRIP("foo", "foo");
     1038  CHECK_SMARTSTRIP("foo.bar", "foo");
     1039  CHECK_SMARTSTRIP("foo/bar", "foo");
     1040  CHECK_SMARTSTRIP("host/bar", "host/bar");
     1041  CHECK_SMARTSTRIP("rcmd.bar", "rcmd.bar");
     1042  CHECK_SMARTSTRIP("daemon/bar", "daemon/bar");
     1043  CHECK_SMARTSTRIP("daemon.bar", "daemon.bar");
     1044
     1045  CHECK_SMARTSTRIP("foo@ATHENA.MIT.EDU", "foo@ATHENA.MIT.EDU");
     1046  CHECK_SMARTSTRIP("foo.bar@ATHENA.MIT.EDU", "foo@ATHENA.MIT.EDU");
     1047  CHECK_SMARTSTRIP("foo/bar@ATHENA.MIT.EDU", "foo@ATHENA.MIT.EDU");
     1048  CHECK_SMARTSTRIP("host/bar@ATHENA.MIT.EDU", "host/bar@ATHENA.MIT.EDU");
     1049  CHECK_SMARTSTRIP("rcmd.bar@ATHENA.MIT.EDU", "rcmd.bar@ATHENA.MIT.EDU");
     1050  CHECK_SMARTSTRIP("daemon/bar@ATHENA.MIT.EDU", "daemon/bar@ATHENA.MIT.EDU");
     1051  CHECK_SMARTSTRIP("daemon.bar@ATHENA.MIT.EDU", "daemon.bar@ATHENA.MIT.EDU");
     1052
     1053  printf("# END testing owl_zephyr_smartstripped_user\n");
     1054
     1055  return numfailed;
     1056}
  • zephyr.c

    rc55930e rebcdf4d  
    13191319CALLER_OWN char *owl_zephyr_smartstripped_user(const char *in)
    13201320{
    1321   char *slash, *dot, *realm, *out;
    1322 
    1323   out = g_strdup(in);
    1324 
    1325   /* bail immeaditly if we don't have to do any work */
    1326   slash = strchr(out, '/');
    1327   dot = strchr(out, '.');
    1328   if (!slash && !dot) {
    1329     return(out);
    1330   }
    1331 
    1332   if (!strncasecmp(out, OWL_ZEPHYR_NOSTRIP_HOST, strlen(OWL_ZEPHYR_NOSTRIP_HOST)) ||
    1333       !strncasecmp(out, OWL_ZEPHYR_NOSTRIP_RCMD, strlen(OWL_ZEPHYR_NOSTRIP_RCMD)) ||
    1334       !strncasecmp(out, OWL_ZEPHYR_NOSTRIP_DAEMON5, strlen(OWL_ZEPHYR_NOSTRIP_DAEMON5)) ||
    1335       !strncasecmp(out, OWL_ZEPHYR_NOSTRIP_DAEMON4, strlen(OWL_ZEPHYR_NOSTRIP_DAEMON4))) {
    1336     return(out);
    1337   }
    1338 
    1339   realm = strchr(out, '@');
    1340   if (!slash && dot && realm && (dot > realm)) {
    1341     /* There's no '/', and the first '.' is in the realm */
    1342     return(out);
    1343   }
    1344 
    1345   /* remove the realm from out, but hold on to it */
    1346   if (realm) realm[0]='\0';
    1347 
    1348   /* strip */
    1349   if (slash) slash[0] = '\0';  /* krb5 style user/instance */
    1350   else if (dot) dot[0] = '\0'; /* krb4 style user.instance */
    1351 
    1352   /* reattach the realm if we had one */
    1353   if (realm) {
    1354     strcat(out, "@");
    1355     strcat(out, realm+1);
    1356   }
    1357 
    1358   return(out);
     1321  int n = strcspn(in, "./");
     1322  char *realm = strchrnul(in, '@');
     1323
     1324  if (in + n >= realm ||
     1325      g_str_has_prefix(in, OWL_ZEPHYR_NOSTRIP_HOST) ||
     1326      g_str_has_prefix(in, OWL_ZEPHYR_NOSTRIP_RCMD) ||
     1327      g_str_has_prefix(in, OWL_ZEPHYR_NOSTRIP_DAEMON5) ||
     1328      g_str_has_prefix(in, OWL_ZEPHYR_NOSTRIP_DAEMON4))
     1329    return g_strdup(in);
     1330  else
     1331    return g_strdup_printf("%.*s%s", n, in, realm);
    13591332}
    13601333
Note: See TracChangeset for help on using the changeset viewer.