[Pkg-wmaker-commits] [wmbiff] 66/77: move passwordMgr testing to test_wmbiff.c; catch a small bug in handling empty passwords
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Thu Aug 20 03:01:17 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to tag wmbiff_0_4_0
in repository wmbiff.
commit 8fd537e1ddf95c23427a7b244d8a34986ad4b6fe
Author: bluehal <bluehal>
Date: Sat Apr 27 08:29:59 2002 +0000
move passwordMgr testing to test_wmbiff.c; catch a small bug in handling empty passwords
---
wmbiff/Client.h | 6 +--
wmbiff/Makefile.am | 2 +-
wmbiff/charutil.c | 4 +-
wmbiff/passwordMgr.c | 101 ++---------------------------------------------
wmbiff/passwordMgr.h | 3 ++
wmbiff/test_wmbiff.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++-
6 files changed, 119 insertions(+), 105 deletions(-)
diff --git a/wmbiff/Client.h b/wmbiff/Client.h
index e91d396..4f60f84 100644
--- a/wmbiff/Client.h
+++ b/wmbiff/Client.h
@@ -1,11 +1,11 @@
-/* $Id: Client.h,v 1.19 2002/04/20 08:53:20 bluehal Exp $ */
+/* $Id: Client.h,v 1.20 2002/04/27 08:29:59 bluehal Exp $ */
/* Author : Scott Holden ( scotth at thezone.net )
Modified : Yong-iL Joh ( tolkien at mizi.com )
Modified : Jorge Garc�a ( Jorge.Garcia at uv.es )
*
- * Email Checker Pop3/Imap4/Licq/Gicu/mbox/maildir
+ * Email Checker Pop3/Imap4/Licq/Gicu/mbox/maildir/finger
*
- * Last Updated : $Date: 2002/04/20 08:53:20 $
+ * Last Updated : $Date: 2002/04/27 08:29:59 $
*
*/
diff --git a/wmbiff/Makefile.am b/wmbiff/Makefile.am
index 3c572e9..6f598ed 100644
--- a/wmbiff/Makefile.am
+++ b/wmbiff/Makefile.am
@@ -7,7 +7,7 @@ wmbiff_SOURCES = wmbiff.c socket.c Pop3Client.c LicqClient.c mboxClient.c \
wmbiff_LDADD = -L../wmgeneral -lwmgeneral
wmbiff_DEPENDENCIES = ../wmgeneral/libwmgeneral.a
test_wmbiff_SOURCES = ShellClient.c charutil.c charutil.h Client.h \
- test_wmbiff.c
+ test_wmbiff.c passwordMgr.c
man_MANS = wmbiff.1 wmbiffrc.5
skindir = $(datadir)/wmbiff/skins
skin_DATA = wmbiff-master-led.xpm wmbiff-master-contrast.xpm
diff --git a/wmbiff/charutil.c b/wmbiff/charutil.c
index 64fe72a..cb4a4d1 100644
--- a/wmbiff/charutil.c
+++ b/wmbiff/charutil.c
@@ -1,4 +1,4 @@
-/* $Id: charutil.c,v 1.8 2002/04/15 01:26:21 bluehal Exp $ */
+/* $Id: charutil.c,v 1.9 2002/04/27 08:29:59 bluehal Exp $ */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -224,6 +224,6 @@ int compile_and_match_regex(const char *regex, const char *str, /*@out@ */
void chomp(char *s)
{
int l = strlen(s) - 1;
- if (l > 0 && s[l] == '\n')
+ if (l >= 0 && s[l] == '\n')
s[l] = '\0';
}
diff --git a/wmbiff/passwordMgr.c b/wmbiff/passwordMgr.c
index 3f0d15e..5e4ea1d 100644
--- a/wmbiff/passwordMgr.c
+++ b/wmbiff/passwordMgr.c
@@ -43,7 +43,8 @@ password_binding pass_list = NULL;
a file, is owned by the user or by root, and is not world
writeable. This is just a sanity check, and is not intended
to ensure the integrity of the password-asking program. */
-static int permissions_ok(Pop3 pc, const char *askpass_fname)
+/* would be static, but used in test_wmbiff */
+int permissions_ok(Pop3 pc, const char *askpass_fname)
{
struct stat st;
if (index(askpass_fname, ' ')) {
@@ -135,7 +136,7 @@ const char *passwordFor(const char *username,
strerror(errno));
} else {
DM(pc, DEBUG_ERROR,
- "passmgr: '%s' returne non-zero exit status %d\n",
+ "passmgr: '%s' returned non-zero exit status %d\n",
buf, exit_status);
}
}
@@ -150,99 +151,3 @@ const char *passwordFor(const char *username,
return (NULL);
}
-#ifdef TEST_PASS_MGR
-int main(int argc, char *argv[])
-{
- const char *b;
- mbox_t m;
-
- /* sh is almost certainly conforming; owned by root, etc. */
- if (!permissions_ok(NULL, "/bin/sh")) {
- printf("FAILURE: permission checker failed on /bin/sh.");
- exit(EXIT_FAILURE);
- }
- /* tmp is definitely bad; and better be og+w */
- if (permissions_ok(NULL, "/tmp")) {
- printf("FAILURE: permission checker failed on /tmp.");
- exit(EXIT_FAILURE);
- }
- /* TODO: also find some user-owned binary that shouldn't be g+w */
- printf("SUCCESS: permission checker sanity check went well.\n");
-
- /* *** */
- m.askpass = "echo xlnt; #";
-
- b = passwordFor("bill", "ted", &m, 0);
- if (strcmp(b, "xlnt") != 0) {
- printf("FAILURE: expected 'xlnt' got '%s'\n", b);
- exit(EXIT_FAILURE);
- }
- printf("SUCCESS: expected 'xlnt' got '%s'\n", b);
-
- /* *** */
- m.askpass = "should be cached";
- b = passwordFor("bill", "ted", &m, 0);
- if (strcmp(b, "xlnt") != 0) {
- printf("FAILURE: expected 'xlnt' got '%s'\n", b);
- exit(EXIT_FAILURE);
- }
-
- printf("SUCCESS: cached 'xlnt' correctly\n");
-
- /* *** */
- m.askpass = "echo abcdefghi1abcdefghi2abcdefghi3a; #";
-
- b = passwordFor("abbot", "costello", &m, 0);
- if (strcmp(b, "abcdefghi1abcdefghi2abcdefghi3a") != 0) {
- printf
- ("FAILURE: expected 'abcdefghi1abcdefghi2abcdefghi3a' got '%s'\n",
- b);
- exit(EXIT_FAILURE);
- }
- printf
- ("SUCCESS: expected 'abcdefghi1abcdefghi2abcdefghi3ab' got '%s'\n",
- b);
-
- /* try overflowing the buffer */
- m.askpass = "echo abcdefghi1abcdefghi2abcdefghi3ab; #";
- b = passwordFor("laverne", "shirley", &m, 0);
- /* should come back truncated to fill the buffer */
- if (strcmp(b, "abcdefghi1abcdefghi2abcdefghi3a") != 0) {
- printf
- ("FAILURE: expected 'abcdefghi1abcdefghi2abcdefghi3a' got '%s'\n",
- b);
- exit(EXIT_FAILURE);
- }
- printf
- ("SUCCESS: expected 'abcdefghi1abcdefghi2abcdefghi3ab' got '%s'\n",
- b);
-
- /* make sure we still have the old one */
- b = passwordFor("bill", "ted", &m, 0);
- if (strcmp(b, "xlnt") != 0) {
- printf("FAILURE: expected 'xlnt' got '%s'\n", b);
- exit(EXIT_FAILURE);
- }
- printf("SUCCESS: expected 'xlnt' got '%s'\n", b);
-
- /* what it's like if ssh-askpass is cancelled - should drop the mailbox */
- m.askpass = "echo -n ; #";
- b = passwordFor("abort", "me", &m, 0);
- if (strcmp(b, "") != 0) {
- printf("FAILURE: expected '' got '%s'\n", b);
- exit(EXIT_FAILURE);
- }
- printf("SUCCESS: expected '' got '%s'\n", b);
-
- /* what it's like if ssh-askpass is ok'd with an empty password. */
- m.askpass = "echo ; #";
- b = passwordFor("try", "again", &m, 0);
- if (strcmp(b, "") != 0) {
- printf("FAILURE: expected '' got '%s'\n", b);
- exit(EXIT_FAILURE);
- }
- printf("SUCCESS: expected '' got '%s'\n", b);
-
- exit(EXIT_SUCCESS);
-}
-#endif
diff --git a/wmbiff/passwordMgr.h b/wmbiff/passwordMgr.h
index 11d0621..249264b 100644
--- a/wmbiff/passwordMgr.h
+++ b/wmbiff/passwordMgr.h
@@ -2,3 +2,6 @@
const char *passwordFor(const char *username,
const char *servername, Pop3 pc, int bFlushCache);
+
+/* tested by test_wmbiff; don't use this for anything. */
+int permissions_ok(Pop3 pc, const char *askpass_fname);
diff --git a/wmbiff/test_wmbiff.c b/wmbiff/test_wmbiff.c
index e6a70ec..f4cbfba 100644
--- a/wmbiff/test_wmbiff.c
+++ b/wmbiff/test_wmbiff.c
@@ -1,7 +1,9 @@
#include "Client.h"
+#include "passwordMgr.h"
int debug_default = DEBUG_INFO;
+/* return 1 if fail, 0 if success */
int test_backtickExpand(void) {
const char *tests[] =
{ "prefix`echo 1`suffix",
@@ -32,9 +34,113 @@ int test_backtickExpand(void) {
return(retval);
}
+/* return 1 if fail, 0 if success */
+int test_passwordMgr(void) {
+ const char *b;
+ mbox_t m;
+
+ /* sh is almost certainly conforming; owned by root, etc. */
+ if (!permissions_ok(NULL, "/bin/sh")) {
+ printf("FAILURE: permission checker failed on /bin/sh.");
+ return(1);
+ }
+ /* tmp is definitely bad; and better be og+w */
+ if (permissions_ok(NULL, "/tmp")) {
+ printf("FAILURE: permission checker failed on /tmp.");
+ return(1);
+ }
+ /* TODO: also find some user-owned binary that shouldn't be g+w */
+ printf("SUCCESS: permission checker sanity check went well.\n");
+
+ /* *** */
+ m.askpass = "echo xlnt; #";
+
+ b = passwordFor("bill", "ted", &m, 0);
+ if (strcmp(b, "xlnt") != 0) {
+ printf("FAILURE: expected 'xlnt' got '%s'\n", b);
+ return(1);
+ }
+ printf("SUCCESS: expected 'xlnt' got '%s'\n", b);
+
+ /* *** */
+ m.askpass = "should be cached";
+ b = passwordFor("bill", "ted", &m, 0);
+ if (strcmp(b, "xlnt") != 0) {
+ printf("FAILURE: expected 'xlnt' got '%s'\n", b);
+ return(1);
+ }
+
+ printf("SUCCESS: cached 'xlnt' correctly\n");
+
+ /* *** */
+ m.askpass = "echo abcdefghi1abcdefghi2abcdefghi3a; #";
+
+ b = passwordFor("abbot", "costello", &m, 0);
+ if (strcmp(b, "abcdefghi1abcdefghi2abcdefghi3a") != 0) {
+ printf
+ ("FAILURE: expected 'abcdefghi1abcdefghi2abcdefghi3a' got '%s'\n",
+ b);
+ return(1);
+ }
+ printf
+ ("SUCCESS: expected 'abcdefghi1abcdefghi2abcdefghi3ab' got '%s'\n",
+ b);
+
+ /* try overflowing the buffer */
+ m.askpass = "echo abcdefghi1abcdefghi2abcdefghi3ab; #";
+ b = passwordFor("laverne", "shirley", &m, 0);
+ /* should come back truncated to fill the buffer */
+ if (strcmp(b, "abcdefghi1abcdefghi2abcdefghi3a") != 0) {
+ printf
+ ("FAILURE: expected 'abcdefghi1abcdefghi2abcdefghi3a' got '%s'\n",
+ b);
+ return(1);
+ }
+ printf
+ ("SUCCESS: expected 'abcdefghi1abcdefghi2abcdefghi3ab' got '%s'\n",
+ b);
+
+ /* make sure we still have the old one */
+ b = passwordFor("bill", "ted", &m, 0);
+ if (strcmp(b, "xlnt") != 0) {
+ printf("FAILURE: expected 'xlnt' got '%s'\n", b);
+ return(1);
+ }
+ printf("SUCCESS: expected 'xlnt' got '%s'\n", b);
+
+ /* what it's like if ssh-askpass is cancelled - should drop the mailbox */
+#if 0
+ /* will exit on our behalf; not so good for continued testing. */
+ m.askpass = "echo -n ; #";
+ b = passwordFor("abort", "me", &m, 0);
+ if (strcmp(b, "") != 0) {
+ printf("FAILURE: expected '' got '%s'\n", b);
+ return(1);
+ }
+ printf("SUCCESS: expected '' got '%s'\n", b);
+#endif
+
+ /* what it's like if ssh-askpass is ok'd with an empty password. */
+ m.askpass = "echo ; #";
+ b = passwordFor("try", "again", &m, 0);
+ if (strcmp(b, "") != 0) {
+ printf("FAILURE: expected '' got '%s'\n", b);
+ return(1);
+ }
+ printf("SUCCESS: expected '' got '%s'\n", b);
+ return(0);
+}
+
int main(int argc __attribute__((unused)),
char *argv[] __attribute__((unused))) {
- exit( test_backtickExpand() );
+ if( test_backtickExpand() ||
+ test_passwordMgr() ) {
+ printf("SOME TESTS FAILED!\n");
+ exit(EXIT_FAILURE);
+ } else {
+ printf("Success! on all tests.\n");
+ exit(EXIT_SUCCESS);
+ }
}
/* vim:set ts=4: */
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbiff.git
More information about the Pkg-wmaker-commits
mailing list