]> git.sur5r.net Git - openldap/commitdiff
ITS#7305 add slapi_[get|free]_client_ip()
authorJani Salonen <jani.salonen@eficode.com>
Sat, 23 Jun 2012 12:45:14 +0000 (05:45 -0700)
committerHoward Chu <hyc@openldap.org>
Sat, 23 Jun 2012 12:46:25 +0000 (05:46 -0700)
include/slapi-plugin.h
servers/slapd/slapi/slapi_utils.c

index 4eda66ebabf662de758dadb896aed6f998510af4..888bae847cb10b34a0ff73c648e8cfa1c66fd00c 100644 (file)
@@ -399,6 +399,8 @@ void slapi_seq_internal_set_pb( Slapi_PBlock *pb, char *ibase, int type,
 /* connection related routines */
 int slapi_is_connection_ssl(Slapi_PBlock *pPB, int *isSSL);
 int slapi_get_client_port(Slapi_PBlock *pPB, int *fromPort);
+int slapi_get_client_ip(Slapi_PBlock *pb, char **clientIP);
+void slapi_free_client_ip(char **clientIP);
 
 /* computed attributes */
 typedef struct _computed_attr_context computed_attr_context;
index 3b913e15210a08f2b67639392a821b55a976ee05..5811f5460168b87c687830075647d528a042ed8c 100644 (file)
@@ -1843,6 +1843,43 @@ slapi_pw_find(
        return 1;
 }
 
+// Get connected client IP address.
+//
+// The user must free the returned client IP after its use.
+// Compatible with IBM Tivoli call.
+//
+// Errors:
+// * LDAP_PARAM_ERROR - If the pb parameter is null.
+// * LDAP_OPERATIONS_ERROR - If the API encounters error processing the request.
+// * LDAP_NO_MEMORY - Failed to allocate required memory.
+
+int
+slapi_get_client_ip(Slapi_PBlock *pb, char **clientIP)
+{
+       char *s = NULL;
+
+       if(pb == NULL || pb->pb_conn == NULL) return(LDAP_PARAM_ERROR);
+       if((s = (char *) slapi_ch_malloc(pb->pb_conn->c_peer_name.bv_len + 1)) == NULL) {
+               return(LDAP_NO_MEMORY);
+       }
+
+       memcpy(s, pb->pb_conn->c_peer_name.bv_val, pb->pb_conn->c_peer_name.bv_len);
+
+       s[pb->pb_conn->c_peer_name.bv_len] = 0;
+
+       *clientIP = s;
+
+       return(LDAP_SUCCESS);
+}
+
+// Free previously allocated client IP address.
+
+void
+slapi_free_client_ip(char **clientIP)
+{
+       slapi_ch_free((void **) clientIP);
+}
+
 #define MAX_HOSTNAME 512
 
 char *