Blame SOURCES/0014-Add-support-for-DCCP-and-SCTP-protocols.patch

47bb90
From 78260f2d8fdeb05a9d53727ea64bf5b2d08d3349 Mon Sep 17 00:00:00 2001
47bb90
From: Vit Mojzis <vmojzis@redhat.com>
47bb90
Date: Fri, 20 Jul 2018 17:33:22 +0200
47bb90
Subject: [PATCH] Add support for DCCP and SCTP protocols
47bb90
47bb90
Resolves: rhbz#1607273
47bb90
---
47bb90
 libapol/include/apol/util.h          | 12 ++++++------
47bb90
 libapol/src/util.c                   | 17 +++++++++++++++++
47bb90
 libapol/swig/apol.i                  |  3 +++
47bb90
 libqpol/include/qpol/portcon_query.h | 13 +++++++++++--
47bb90
 libqpol/src/policy_define.c          | 10 ++++++++++
47bb90
 libqpol/src/policy_parse.y           |  7 +++++++
47bb90
 libqpol/swig/qpol.i                  |  3 +++
47bb90
 python/setools/seinfo.c              |  4 +++-
47bb90
 secmds/seinfo.c                      |  4 ++++
47bb90
 9 files changed, 64 insertions(+), 9 deletions(-)
47bb90
47bb90
diff --git a/libapol/include/apol/util.h b/libapol/include/apol/util.h
47bb90
index 99db1685..3e370332 100644
47bb90
--- a/libapol/include/apol/util.h
47bb90
+++ b/libapol/include/apol/util.h
47bb90
@@ -48,8 +48,8 @@ extern "C"
47bb90
  * Given a portcon protocol, return a read-only string that describes
47bb90
  * that protocol.
47bb90
  *
47bb90
- * @param protocol Portcon protocol, one of IPPROTO_TCP or IPPROTO_UDP
47bb90
- * from netinet/in.h.
47bb90
+ * @param protocol Portcon protocol, one of IPPROTO_TCP, IPPROTO_UDP,
47bb90
+ * IPPROTO_DCCP or IPPROTO_SCTP from netinet/in.h.
47bb90
  *
47bb90
  * @return A string that describes the protocol, or NULL if the
47bb90
  * protocol is invalid.  Do not free() this string.
47bb90
@@ -59,10 +59,10 @@ extern "C"
47bb90
 /**
47bb90
  * Given the name of a portcon protocol, return its numeric value.
47bb90
  *
47bb90
- * @param protocol_str Portcon protocol, one of "tcp", "TCP", "udp", or "UDP".
47bb90
- *
47bb90
- * @return Numeric value for the protocol, one of IPPROTO_TCP or IPPROTO_UDP
47bb90
- * from netinet/in.h.  Upon error return 0.
47bb90
+ * @param protocol_str Portcon protocol, one of "tcp", "TCP", "udp", "UDP",
47bb90
+ * "dccp", "DCCP", "sctp" or "SCTP".
47bb90
+ * @return Numeric value for the protocol, one of IPPROTO_TCP, IPPROTO_UDP,
47bb90
+ * IPPROTO_DCCP or IPPROTO_SCTP from netinet/in.h.  Upon error return 0.
47bb90
  */
47bb90
 	extern uint8_t apol_str_to_protocol(const char *protocol_str);
47bb90
 
47bb90
diff --git a/libapol/src/util.c b/libapol/src/util.c
47bb90
index dd6d300d..fc38d9d5 100644
47bb90
--- a/libapol/src/util.c
47bb90
+++ b/libapol/src/util.c
47bb90
@@ -42,6 +42,13 @@
47bb90
 #include <arpa/inet.h>
47bb90
 #include <netinet/in.h>		       /* needed for portcon's protocol */
47bb90
 
47bb90
+#ifndef IPPROTO_DCCP
47bb90
+#define IPPROTO_DCCP 33
47bb90
+#endif
47bb90
+#ifndef IPPROTO_SCTP
47bb90
+#define IPPROTO_SCTP 132
47bb90
+#endif
47bb90
+
47bb90
 /* use 8k line size */
47bb90
 #define APOL_LINE_SZ 8192
47bb90
 #define APOL_ENVIRON_VAR_NAME "APOL_INSTALL_DIR"
47bb90
@@ -173,6 +180,10 @@ const char *apol_protocol_to_str(uint8_t protocol)
47bb90
 		return "tcp";
47bb90
 	case IPPROTO_UDP:
47bb90
 		return "udp";
47bb90
+	case IPPROTO_DCCP:
47bb90
+		return "dccp";
47bb90
+	case IPPROTO_SCTP:
47bb90
+		return "sctp";
47bb90
 	default:
47bb90
 		errno = EPROTONOSUPPORT;
47bb90
 		return NULL;
47bb90
@@ -191,6 +202,12 @@ uint8_t apol_str_to_protocol(const char *protocol_str)
47bb90
 	if (strcmp(protocol_str, "udp") == 0 || strcmp(protocol_str, "UDP") == 0) {
47bb90
 		return IPPROTO_UDP;
47bb90
 	}
47bb90
+	if (strcmp(protocol_str, "dccp") == 0 || strcmp(protocol_str, "DCCP") == 0) {
47bb90
+		return IPPROTO_DCCP;
47bb90
+	}
47bb90
+	if (strcmp(protocol_str, "sctp") == 0 || strcmp(protocol_str, "SCTP") == 0) {
47bb90
+		return IPPROTO_SCTP;
47bb90
+	}
47bb90
 	errno = EPROTONOSUPPORT;
47bb90
 	return 0;
47bb90
 }
47bb90
diff --git a/libapol/swig/apol.i b/libapol/swig/apol.i
47bb90
index 8a4a195f..6a650315 100644
47bb90
--- a/libapol/swig/apol.i
47bb90
+++ b/libapol/swig/apol.i
47bb90
@@ -227,6 +227,9 @@ const char *libapol_get_version(void);
47bb90
 /* defines from netinet/in.h for ip protocols */
47bb90
 #define IPPROTO_TCP  6
47bb90
 #define IPPROTO_UDP 17
47bb90
+#define IPPROTO_DCCP 33
47bb90
+#define IPPROTO_SCTP 132
47bb90
+
47bb90
 const char *apol_protocol_to_str(uint8_t protocol);
47bb90
 uint8_t apol_str_to_protocol(const char *protocol_str);
47bb90
 %newobject wrap_apol_str_to_internal_ip(char*);
47bb90
diff --git a/libqpol/include/qpol/portcon_query.h b/libqpol/include/qpol/portcon_query.h
47bb90
index 63210feb..72e8ce9e 100644
47bb90
--- a/libqpol/include/qpol/portcon_query.h
47bb90
+++ b/libqpol/include/qpol/portcon_query.h
47bb90
@@ -37,6 +37,13 @@ extern "C"
47bb90
 #include <qpol/iterator.h>
47bb90
 #include <qpol/policy.h>
47bb90
 
47bb90
+#ifndef IPPROTO_DCCP
47bb90
+#define IPPROTO_DCCP 33
47bb90
+#endif
47bb90
+#ifndef IPPROTO_SCTP
47bb90
+#define IPPROTO_SCTP 132
47bb90
+#endif
47bb90
+
47bb90
 	typedef struct qpol_portcon qpol_portcon_t;
47bb90
 
47bb90
 /**
47bb90
@@ -46,7 +53,8 @@ extern "C"
47bb90
  *  @param high The high port of the range of ports; if searching for a
47bb90
  *  single port, set high equal to low.
47bb90
  *  @param protocol The protocol used in the portcon statement.
47bb90
- *  Value should be one of IPPROTO_TCP or IPPROTO_UDP from netinet/in.h
47bb90
+ *  Value should be one of IPPROTO_TCP, IPPROTO_UDP, IPPROTO_DCCP or 
47bb90
+ *  IPPROTO_SCTP from netinet/in.h
47bb90
  *  @param ocon Pointer in which to store the statement returned.
47bb90
  *  The caller should not free this pointer.
47bb90
  *  @return 0 on success and < 0 on failure; if the call fails,
47bb90
@@ -73,7 +81,8 @@ extern "C"
47bb90
  *  @param policy The policy associated with the portcon statement.
47bb90
  *  @param ocon The portcon statement from which to get the protocol.
47bb90
  *  @param protocol Pointer to set to the value of protocol.
47bb90
- *  Value will be one of IPPROTO_TCP or IPPROTO_UDP from netinet/in.h
47bb90
+ *  Value will be one of IPPROTO_TCP, IPPROTO_UDP, IPPROTO_DCCP or 
47bb90
+ *  IPPROTO_SCTP from netinet/in.h
47bb90
  *  @return 0 on success and < 0 on failure; if the call fails,
47bb90
  *  errno will be set and *protocol will be 0;
47bb90
  */
47bb90
diff --git a/libqpol/src/policy_define.c b/libqpol/src/policy_define.c
47bb90
index 15f70ba3..2c5d488b 100644
47bb90
--- a/libqpol/src/policy_define.c
47bb90
+++ b/libqpol/src/policy_define.c
47bb90
@@ -63,6 +63,12 @@
47bb90
 #ifdef HAVE_SEPOL_ERRCODES
47bb90
 #include <sepol/errcodes.h>
47bb90
 #endif
47bb90
+#ifndef IPPROTO_DCCP
47bb90
+#define IPPROTO_DCCP 33
47bb90
+#endif
47bb90
+#ifndef IPPROTO_SCTP
47bb90
+#define IPPROTO_SCTP 132
47bb90
+#endif
47bb90
 
47bb90
 #include "queue.h"
47bb90
 /* Required for SETools libqpol - Removed #include "checkpolicy.h"*/
47bb90
@@ -4350,6 +4356,10 @@ int define_port_context(unsigned int low, unsigned int high)
47bb90
 		protocol = IPPROTO_TCP;
47bb90
 	} else if ((strcmp(id, "udp") == 0) || (strcmp(id, "UDP") == 0)) {
47bb90
 		protocol = IPPROTO_UDP;
47bb90
+	} else if ((strcmp(id, "dccp") == 0) || (strcmp(id, "DCCP") == 0)) {
47bb90
+		protocol = IPPROTO_DCCP;
47bb90
+	} else if ((strcmp(id, "sctp") == 0) || (strcmp(id, "SCTP") == 0)) {
47bb90
+		protocol = IPPROTO_SCTP;
47bb90
 	} else {
47bb90
 		yyerror2("unrecognized protocol %s", id);
47bb90
 		free(newc);
47bb90
diff --git a/libqpol/src/policy_parse.y b/libqpol/src/policy_parse.y
47bb90
index 357f3d8f..e07ff52c 100644
47bb90
--- a/libqpol/src/policy_parse.y
47bb90
+++ b/libqpol/src/policy_parse.y
47bb90
@@ -52,6 +52,13 @@
47bb90
 #include <arpa/inet.h>
47bb90
 #include <stdlib.h>
47bb90
 
47bb90
+#ifndef IPPROTO_DCCP
47bb90
+#define IPPROTO_DCCP 33
47bb90
+#endif
47bb90
+#ifndef IPPROTO_SCTP
47bb90
+#define IPPROTO_SCTP 132
47bb90
+#endif
47bb90
+
47bb90
 #include <sepol/policydb/expand.h>
47bb90
 #include <sepol/policydb/policydb.h>
47bb90
 #include <sepol/policydb/services.h>
47bb90
diff --git a/libqpol/swig/qpol.i b/libqpol/swig/qpol.i
47bb90
index b604488a..9fbb8286 100644
47bb90
--- a/libqpol/swig/qpol.i
47bb90
+++ b/libqpol/swig/qpol.i
47bb90
@@ -2005,6 +2005,9 @@ typedef struct qpol_nodecon {} qpol_nodecon_t;
47bb90
 /* from netinet/in.h */
47bb90
 #define IPPROTO_TCP 6
47bb90
 #define IPPROTO_UDP 17
47bb90
+#define IPPROTO_DCCP 33
47bb90
+#define IPPROTO_SCTP 132
47bb90
+
47bb90
 typedef struct qpol_portcon {} qpol_portcon_t;
47bb90
 %extend qpol_portcon_t {
47bb90
 	qpol_portcon(qpol_policy_t *p, uint16_t low, uint16_t high, uint8_t protocol) {
47bb90
diff --git a/python/setools/seinfo.c b/python/setools/seinfo.c
47bb90
index 211930a3..7c22f9e7 100644
47bb90
--- a/python/setools/seinfo.c
47bb90
+++ b/python/setools/seinfo.c
47bb90
@@ -512,7 +512,9 @@ static PyObject*  get_ports(const char *num, const apol_policy_t * policydb)
47bb90
 		}
47bb90
 
47bb90
 		if ((ocon_proto != IPPROTO_TCP) &&
47bb90
-		    (ocon_proto != IPPROTO_UDP)) 
47bb90
+		    (ocon_proto != IPPROTO_UDP) &&
47bb90
+		    (ocon_proto != IPPROTO_DCCP) &&
47bb90
+		    (ocon_proto != IPPROTO_SCTP)) 
47bb90
 			goto cleanup;
47bb90
 
47bb90
 		if (qpol_portcon_get_context(q, portcon, &ctxt)) {
47bb90
diff --git a/secmds/seinfo.c b/secmds/seinfo.c
47bb90
index a9708907..3c71af57 100644
47bb90
--- a/secmds/seinfo.c
47bb90
+++ b/secmds/seinfo.c
47bb90
@@ -1155,6 +1155,10 @@ static int print_portcon(FILE * fp, const char *num, const char *protocol, const
47bb90
 			proto = IPPROTO_TCP;
47bb90
 		else if (!strcmp(protocol, "udp"))
47bb90
 			proto = IPPROTO_UDP;
47bb90
+		else if (!strcmp(protocol, "dccp"))
47bb90
+			proto = IPPROTO_DCCP;
47bb90
+		else if (!strcmp(protocol, "sctp"))
47bb90
+			proto = IPPROTO_SCTP;
47bb90
 		else {
47bb90
 			ERR(policydb, "Unable to get portcon by protocol: bad protocol %s.", protocol);
47bb90
 			goto cleanup;
47bb90
-- 
47bb90
2.14.3
47bb90