Changeset 4a212dd
- Timestamp:
- Dec 2, 2013, 3:57:31 AM (11 years ago)
- 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. - Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tester.c
r6a8b519 r21dc927 25 25 int owl_history_regtest(void); 26 26 int call_filter_regtest(void); 27 int owl_smartstrip_regtest(void); 27 28 28 29 extern void owl_perl_xs_init(pTHX); … … 116 117 numfailures += owl_history_regtest(); 117 118 numfailures += call_filter_regtest(); 119 numfailures += owl_smartstrip_regtest(); 118 120 if (numfailures) { 119 121 fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures); … … 1018 1020 return numfailed; 1019 1021 } 1022 1023 int 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 1319 1319 CALLER_OWN char *owl_zephyr_smartstripped_user(const char *in) 1320 1320 { 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); 1359 1332 } 1360 1333
Note: See TracChangeset
for help on using the changeset viewer.