Author: mahadev
Date: Thu Apr 16 20:28:17 2009
New Revision: 765746
URL: http://svn.apache.org/viewvc?rev=765746&view=rev
Log:
ZOOKEEPER-374. Uninitialized struct variable in C causes warning which is treated as an error
(phunt via mahadev)
Modified:
hadoop/zookeeper/trunk/CHANGES.txt
hadoop/zookeeper/trunk/src/c/src/zookeeper.c
hadoop/zookeeper/trunk/src/c/tests/TestClient.cc
Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=765746&r1=765745&r2=765746&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Thu Apr 16 20:28:17 2009
@@ -48,6 +48,9 @@
ZOOKEEPER-355. make validatePath non public in Zookeeper client api. (phunt
via mahadev)
+ ZOOKEEPER-374. Uninitialized struct variable in C causes warning which
+is treated as an error (phunt via mahadev)
+
IMPROVEMENTS:
ZOOKEEPER-308. improve the atomic broadcast performance 3x.
(breed via mahadev)
Modified: hadoop/zookeeper/trunk/src/c/src/zookeeper.c
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/src/zookeeper.c?rev=765746&r1=765745&r2=765746&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/src/zookeeper.c (original)
+++ hadoop/zookeeper/trunk/src/c/src/zookeeper.c Thu Apr 16 20:28:17 2009
@@ -2390,13 +2390,16 @@
}
memcpy(auth.buff,cert,certLen);
auth.len=certLen;
+ } else {
+ auth.buff = 0;
+ auth.len = 0;
}
zoo_lock_auth(zh);
free_auth_info(&zh->auth);
zh->auth.scheme=strdup(scheme);
- if(cert!=NULL && certLen!=0)
+ if(auth.buff)
zh->auth.auth=auth;
zh->auth.completion=completion;
zh->auth.data=data;
Modified: hadoop/zookeeper/trunk/src/c/tests/TestClient.cc
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/tests/TestClient.cc?rev=765746&r1=765745&r2=765746&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/tests/TestClient.cc (original)
+++ hadoop/zookeeper/trunk/src/c/tests/TestClient.cc Thu Apr 16 20:28:17 2009
@@ -160,6 +160,7 @@
CPPUNIT_TEST(testPathValidation);
CPPUNIT_TEST(testPing);
CPPUNIT_TEST(testAcl);
+ CPPUNIT_TEST(testAuth);
CPPUNIT_TEST(testWatcherAutoResetWithGlobal);
CPPUNIT_TEST(testWatcherAutoResetWithLocal);
#endif
@@ -286,6 +287,10 @@
}
}
+ static void voidCompletion(int rc, const void *data) {
+ CPPUNIT_ASSERT_EQUAL((int)data, rc);
+ }
+
static void verifyCreateFails(const char *path, zhandle_t *zk) {
CPPUNIT_ASSERT_EQUAL((int)ZBADARGUMENTS, zoo_create(zk,
path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0));
@@ -332,7 +337,6 @@
void testAcl() {
int rc;
- struct String_vector strings;
struct ACL_vector aclvec;
struct Stat stat;
watchctx_t ctx;
@@ -353,6 +357,50 @@
}
+ void testAuth() {
+ int rc;
+
+ watchctx_t ctx1;
+ zhandle_t *zk = createClient(&ctx1);
+
+ rc = zoo_add_auth(0, "", 0, 0, voidCompletion, (void*)-1);
+ CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc);
+
+ rc = zoo_add_auth(zk, 0, 0, 0, voidCompletion, (void*)-1);
+ CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc);
+
+ // auth as pat, create /tauth1, close session
+ rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion,
+ (void*)ZOK);
+ CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
+
+ rc = zoo_create(zk, "/tauth1", "", 0, &ZOO_CREATOR_ALL_ACL, 0, 0, 0);
+ CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
+
+ // auth as pat w/bad pass, access /tauth1, verify failure
+ watchctx_t ctx2;
+ zk = createClient(&ctx2);
+
+ rc = zoo_add_auth(zk, "digest", "pat:passwd2", 11, voidCompletion,
+ (void*)ZOK);
+ CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
+
+ char buf[1024];
+ int blen = sizeof(buf);
+ struct Stat stat;
+ rc = zoo_get(zk, "/tauth1", 0, buf, &blen, &stat);
+ CPPUNIT_ASSERT_EQUAL((int)ZNOAUTH, rc);
+
+ // add auth pat w/correct pass verify success
+ rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion,
+ (void*)ZOK);
+ CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
+
+ rc = zoo_get(zk, "/tauth1", 0, buf, &blen, &stat);
+ CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
+ }
+
+
void testPathValidation() {
watchctx_t ctx;
zhandle_t *zk = createClient(&ctx);
|