[Debtags-commits] [svn] r1926 - in daemon: . src

Enrico Zini enrico at costa.debian.org
Mon Sep 18 18:34:47 UTC 2006


Author: enrico
Date: Mon Sep 18 18:34:45 2006
New Revision: 1926

Modified:
   daemon/   (props changed)
   daemon/src/debtagsd.cpp
Log:
 r3366 at viaza:  enrico | 2006-09-18 20:08:52 +0200
 Log the peer credentials


Modified: daemon/src/debtagsd.cpp
==============================================================================
--- daemon/src/debtagsd.cpp	(original)
+++ daemon/src/debtagsd.cpp	Mon Sep 18 18:34:45 2006
@@ -161,13 +161,23 @@
 		if (res != str.size())
 			throw wibble::exception::System("writing data");
 	}
+
+	void credentials(uid_t& uid, gid_t& gid)
+	{
+		struct ucred cr;
+		socklen_t cl = sizeof(cr);
+		if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl) == -1)
+			throw wibble::exception::System("reading socket peer credentials");
+		uid = cr.uid;
+		gid = cr.gid;
+	}
 };
 
 /// Deserialize a sequence of keywords
 std::vector<std::string> parseKeys(const std::string& str)
 {
 	std::vector<std::string> res;
-	wibble::Tokenizer tok(str, "[^ ]+", REG_EXTENDED);
+	wibble::Tokenizer tok(str, "[[:alnum:]_-]+", REG_EXTENDED);
 	for (wibble::Tokenizer::const_iterator i = tok.begin(); i != tok.end(); ++i)
 		res.push_back(*i);
 	return res;
@@ -177,25 +187,9 @@
 std::set<std::string> parseTagset(const std::string& str)
 {
 	std::set<std::string> res;
-	size_t beg = 0;
-	size_t end = 0;
-	while (true)
-	{
-		//cerr << "Str: -" << str << "- " << beg << "-" << end << endl;
-		end = str.find(" ", beg);
-		if (end == string::npos)
-		{
-			if (beg != str.size())
-				res.insert(str.substr(beg));
-			break;
-		}
-		else
-		{
-			if (end != beg)
-				res.insert(str.substr(beg, end-beg));
-			beg = end + 1;
-		}
-	}
+	wibble::Tokenizer tok(str, "[[:alnum:]:_-]+", REG_EXTENDED);
+	for (wibble::Tokenizer::const_iterator i = tok.begin(); i != tok.end(); ++i)
+		res.insert(*i);
 	return res;
 }
 
@@ -365,10 +359,13 @@
 
 			ListeningSocket lsock(cfg.sockfile);
 
+			uid_t uid;
+			gid_t gid;
 			while (!interrupted)
 			{
 				Connection conn(lsock.accept());
-				cfg.log() << "Got connection" << endl;
+				conn.credentials(uid, gid);
+				cfg.log() << "Got connection from " << uid << ":" << gid << endl;
 				handleConnection(conn);
 			}
 



More information about the Debtags-commits mailing list