From 8944ab910cc8f62dc6ce567046a92e50b1e2813f Mon Sep 17 00:00:00 2001
From: Charles Krinke
Date: Wed, 29 Apr 2009 22:31:00 +0000
Subject: Thank you kindly, MCortez for a patch that: The attached patch
 provides the necessary infrastructure to support security and authentication
 features of the xmlrpc server. * Read/Write keys for accessing a Group's
 xmlrpc service. * Requiring user session verification for write operations.

---
 .../Avatar/XmlRpcGroups/XmlRpcGroupData.cs         | 163 ++++++++++++---------
 1 file changed, 96 insertions(+), 67 deletions(-)

(limited to 'OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs')

diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs
index d941118..a7ef40a 100644
--- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs
@@ -61,7 +61,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
 
         private bool m_disableKeepAlive = false;
 
-        public XmlRpcGroupDataProvider(string serviceURL, bool disableKeepAlive)
+        private string m_groupReadKey  = string.Empty;
+        private string m_groupWriteKey = string.Empty;
+
+        public XmlRpcGroupDataProvider(string serviceURL, bool disableKeepAlive, string groupReadKey, string groupWriteKey)
         {
             m_serviceURL = serviceURL.Trim();
             m_disableKeepAlive = disableKeepAlive;
@@ -71,12 +74,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             {
                 throw new Exception("Please specify a valid ServiceURL for XmlRpcGroupDataProvider in OpenSim.ini, [Groups], XmlRpcServiceURL");
             }
+
+            m_groupReadKey = groupReadKey;
+            m_groupWriteKey = groupWriteKey;
         }
 
         /// <summary>
         /// Create a Group, including Everyone and Owners Role, place FounderID in both groups, select Owner as selected role, and newly created group as agent's active role.
         /// </summary>
-        public UUID CreateGroup(string name, string charter, bool showInList, UUID insigniaID, 
+        public UUID CreateGroup(GroupRequestID requestID, string name, string charter, bool showInList, UUID insigniaID, 
                                 int membershipFee, bool openEnrollment, bool allowPublish, 
                                 bool maturePublish, UUID founderID)
         {
@@ -145,7 +151,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
                                     | GroupPowers.VoteOnProposal;
             param["OwnersPowers"] = ((ulong)OwnerPowers).ToString();
 
-            Hashtable respData = XmlRpcCall("groups.createGroup", param);
+
+
+
+            Hashtable respData = XmlRpcCall(requestID, "groups.createGroup", param);
 
             if (respData.Contains("error"))
             {
@@ -157,7 +166,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             return UUID.Parse((string)respData["GroupID"]);
         }
 
-        public void UpdateGroup(UUID groupID, string charter, bool showInList, 
+        public void UpdateGroup(GroupRequestID requestID, UUID groupID, string charter, bool showInList, 
                                 UUID insigniaID, int membershipFee, bool openEnrollment, 
                                 bool allowPublish, bool maturePublish)
         {
@@ -171,10 +180,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             param["AllowPublish"] = allowPublish == true ? 1 : 0;
             param["MaturePublish"] = maturePublish == true ? 1 : 0;
 
-            XmlRpcCall("groups.updateGroup", param);
+            XmlRpcCall(requestID, "groups.updateGroup", param);
         }
 
-        public void AddGroupRole(UUID groupID, UUID roleID, string name, string description, 
+        public void AddGroupRole(GroupRequestID requestID, UUID groupID, UUID roleID, string name, string description, 
                                  string title, ulong powers)
         {
             Hashtable param = new Hashtable();
@@ -185,19 +194,19 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             param["Title"] = title;
             param["Powers"] = powers.ToString();
 
-            XmlRpcCall("groups.addRoleToGroup", param);
+            XmlRpcCall(requestID, "groups.addRoleToGroup", param);
         }
 
-        public void RemoveGroupRole(UUID groupID, UUID roleID)
+        public void RemoveGroupRole(GroupRequestID requestID, UUID groupID, UUID roleID)
         {
             Hashtable param = new Hashtable();
             param["GroupID"] = groupID.ToString();
             param["RoleID"] = roleID.ToString();
 
-            XmlRpcCall("groups.removeRoleFromGroup", param);
+            XmlRpcCall(requestID, "groups.removeRoleFromGroup", param);
         }
 
-        public void UpdateGroupRole(UUID groupID, UUID roleID, string name, string description, 
+        public void UpdateGroupRole(GroupRequestID requestID, UUID groupID, UUID roleID, string name, string description, 
                                     string title, ulong powers)
         {
             Hashtable param = new Hashtable();
@@ -217,10 +226,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             }
             param["Powers"] = powers.ToString();
 
-            XmlRpcCall("groups.updateGroupRole", param);
+            XmlRpcCall(requestID, "groups.updateGroupRole", param);
         }
 
-        public GroupRecord GetGroupRecord(UUID GroupID, string GroupName)
+        public GroupRecord GetGroupRecord(GroupRequestID requestID, UUID GroupID, string GroupName)
         {
             Hashtable param = new Hashtable();
             if (GroupID != UUID.Zero)
@@ -232,8 +241,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
                 param["Name"] = GroupName.ToString();
             }
 
-
-            Hashtable respData = XmlRpcCall("groups.getGroup", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.getGroup", param);
 
             if (respData.Contains("error"))
             {
@@ -241,15 +249,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             }
 
             return GroupProfileHashtableToGroupRecord(respData);
+
         }
 
-        public GroupProfileData GetMemberGroupProfile(UUID GroupID, UUID AgentID)
+        public GroupProfileData GetMemberGroupProfile(GroupRequestID requestID, UUID GroupID, UUID AgentID)
         {
             Hashtable param = new Hashtable();
             param["GroupID"] = GroupID.ToString();
 
-
-            Hashtable respData = XmlRpcCall("groups.getGroup", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.getGroup", param);
 
             if (respData.Contains("error"))
             {
@@ -257,13 +265,14 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
                 return new GroupProfileData();
             }
 
-            GroupMembershipData MemberInfo = GetAgentGroupMembership(AgentID, GroupID);
+            GroupMembershipData MemberInfo = GetAgentGroupMembership(requestID, AgentID, GroupID);
             GroupProfileData MemberGroupProfile = GroupProfileHashtableToGroupProfileData(respData);
 
             MemberGroupProfile.MemberTitle = MemberInfo.GroupTitle;
             MemberGroupProfile.PowersMask = MemberInfo.GroupPowers;
 
             return MemberGroupProfile;
+
         }
 
         private GroupProfileData GroupProfileHashtableToGroupProfileData(Hashtable groupProfile)
@@ -314,26 +323,26 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             return group;
         }
 
-        public void SetAgentActiveGroup(UUID AgentID, UUID GroupID)
+        public void SetAgentActiveGroup(GroupRequestID requestID, UUID AgentID, UUID GroupID)
         {
             Hashtable param = new Hashtable();
             param["AgentID"] = AgentID.ToString();
             param["GroupID"] = GroupID.ToString();
 
-            XmlRpcCall("groups.setAgentActiveGroup", param);
+            XmlRpcCall(requestID, "groups.setAgentActiveGroup", param);
         }
 
-        public void SetAgentActiveGroupRole(UUID AgentID, UUID GroupID, UUID RoleID)
+        public void SetAgentActiveGroupRole(GroupRequestID requestID, UUID AgentID, UUID GroupID, UUID RoleID)
         {
             Hashtable param = new Hashtable();
             param["AgentID"] = AgentID.ToString();
             param["GroupID"] = GroupID.ToString();
             param["SelectedRoleID"] = RoleID.ToString();
 
-            XmlRpcCall("groups.setAgentGroupInfo", param);
+            XmlRpcCall(requestID, "groups.setAgentGroupInfo", param);
         }
 
-        public void SetAgentGroupInfo(UUID AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
+        public void SetAgentGroupInfo(GroupRequestID requestID, UUID AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
         {
             Hashtable param = new Hashtable();
             param["AgentID"] = AgentID.ToString();
@@ -341,10 +350,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             param["AcceptNotices"] = AcceptNotices ? "1" : "0";
             param["ListInProfile"] = ListInProfile ? "1" : "0";
 
-            XmlRpcCall("groups.setAgentGroupInfo", param);
+            XmlRpcCall(requestID, "groups.setAgentGroupInfo", param);
+
         }
 
-        public void AddAgentToGroupInvite(UUID inviteID, UUID groupID, UUID roleID, UUID agentID)
+        public void AddAgentToGroupInvite(GroupRequestID requestID, UUID inviteID, UUID groupID, UUID roleID, UUID agentID)
         {
             Hashtable param = new Hashtable();
             param["InviteID"] = inviteID.ToString();
@@ -352,15 +362,16 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             param["RoleID"] = roleID.ToString();
             param["GroupID"] = groupID.ToString();
 
-            XmlRpcCall("groups.addAgentToGroupInvite", param);
+            XmlRpcCall(requestID, "groups.addAgentToGroupInvite", param);
+
         }
 
-        public GroupInviteInfo GetAgentToGroupInvite(UUID inviteID)
+        public GroupInviteInfo GetAgentToGroupInvite(GroupRequestID requestID, UUID inviteID)
         {
             Hashtable param = new Hashtable();
             param["InviteID"] = inviteID.ToString();
 
-            Hashtable respData = XmlRpcCall("groups.getAgentToGroupInvite", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.getAgentToGroupInvite", param);
 
             if (respData.Contains("error"))
             {
@@ -376,59 +387,60 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             return inviteInfo;
         }
 
-        public void RemoveAgentToGroupInvite(UUID inviteID)
+        public void RemoveAgentToGroupInvite(GroupRequestID requestID, UUID inviteID)
         {
             Hashtable param = new Hashtable();
             param["InviteID"] = inviteID.ToString();
 
-            XmlRpcCall("groups.removeAgentToGroupInvite", param);
+            XmlRpcCall(requestID, "groups.removeAgentToGroupInvite", param);
         }
 
-        public void AddAgentToGroup(UUID AgentID, UUID GroupID, UUID RoleID)
+        public void AddAgentToGroup(GroupRequestID requestID, UUID AgentID, UUID GroupID, UUID RoleID)
         {
             Hashtable param = new Hashtable();
             param["AgentID"] = AgentID.ToString();
             param["GroupID"] = GroupID.ToString();
             param["RoleID"] = RoleID.ToString();
 
-            XmlRpcCall("groups.addAgentToGroup", param);
+            XmlRpcCall(requestID, "groups.addAgentToGroup", param);
         }
 
-        public void RemoveAgentFromGroup(UUID AgentID, UUID GroupID)
+        public void RemoveAgentFromGroup(GroupRequestID requestID, UUID AgentID, UUID GroupID)
         {
             Hashtable param = new Hashtable();
             param["AgentID"] = AgentID.ToString();
             param["GroupID"] = GroupID.ToString();
 
-            XmlRpcCall("groups.removeAgentFromGroup", param);
+            XmlRpcCall(requestID, "groups.removeAgentFromGroup", param);
         }
 
-        public void AddAgentToGroupRole(UUID AgentID, UUID GroupID, UUID RoleID)
+        public void AddAgentToGroupRole(GroupRequestID requestID, UUID AgentID, UUID GroupID, UUID RoleID)
         {
             Hashtable param = new Hashtable();
             param["AgentID"] = AgentID.ToString();
             param["GroupID"] = GroupID.ToString();
             param["RoleID"] = RoleID.ToString();
 
-            XmlRpcCall("groups.addAgentToGroupRole", param);
+            XmlRpcCall(requestID, "groups.addAgentToGroupRole", param);
         }
 
-        public void RemoveAgentFromGroupRole(UUID AgentID, UUID GroupID, UUID RoleID)
+        public void RemoveAgentFromGroupRole(GroupRequestID requestID, UUID AgentID, UUID GroupID, UUID RoleID)
         {
             Hashtable param = new Hashtable();
             param["AgentID"] = AgentID.ToString();
             param["GroupID"] = GroupID.ToString();
             param["RoleID"] = RoleID.ToString();
 
-            XmlRpcCall("groups.removeAgentFromGroupRole", param);
+            XmlRpcCall(requestID, "groups.removeAgentFromGroupRole", param);
         }
 
-        public List<DirGroupsReplyData> FindGroups(string search)
+
+        public List<DirGroupsReplyData> FindGroups(GroupRequestID requestID, string search)
         {
             Hashtable param = new Hashtable();
             param["Search"] = search;
 
-            Hashtable respData = XmlRpcCall("groups.findGroups", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.findGroups", param);
 
             List<DirGroupsReplyData> findings = new List<DirGroupsReplyData>();
 
@@ -450,13 +462,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             return findings;
         }
 
-        public GroupMembershipData GetAgentGroupMembership(UUID AgentID, UUID GroupID)
+        public GroupMembershipData GetAgentGroupMembership(GroupRequestID requestID, UUID AgentID, UUID GroupID)
         {
             Hashtable param = new Hashtable();
             param["AgentID"] = AgentID.ToString();
             param["GroupID"] = GroupID.ToString();
 
-            Hashtable respData = XmlRpcCall("groups.getAgentGroupMembership", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.getAgentGroupMembership", param);
 
             if (respData.Contains("error"))
             {
@@ -468,12 +480,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             return data;
         }
 
-        public GroupMembershipData GetAgentActiveMembership(UUID AgentID)
+        public GroupMembershipData GetAgentActiveMembership(GroupRequestID requestID, UUID AgentID)
         {
             Hashtable param = new Hashtable();
             param["AgentID"] = AgentID.ToString();
 
-            Hashtable respData = XmlRpcCall("groups.getAgentActiveMembership", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.getAgentActiveMembership", param);
 
             if (respData.Contains("error"))
             {
@@ -483,12 +495,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             return HashTableToGroupMembershipData(respData);
         }
 
-        public List<GroupMembershipData> GetAgentGroupMemberships(UUID AgentID)
+
+        public List<GroupMembershipData> GetAgentGroupMemberships(GroupRequestID requestID, UUID AgentID)
         {
             Hashtable param = new Hashtable();
             param["AgentID"] = AgentID.ToString();
 
-            Hashtable respData = XmlRpcCall("groups.getAgentGroupMemberships", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.getAgentGroupMemberships", param);
 
             List<GroupMembershipData> memberships = new List<GroupMembershipData>();
 
@@ -503,13 +516,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             return memberships;
         }
 
-        public List<GroupRolesData> GetAgentGroupRoles(UUID AgentID, UUID GroupID)
+        public List<GroupRolesData> GetAgentGroupRoles(GroupRequestID requestID, UUID AgentID, UUID GroupID)
         {
             Hashtable param = new Hashtable();
             param["AgentID"] = AgentID.ToString();
             param["GroupID"] = GroupID.ToString();
 
-            Hashtable respData = XmlRpcCall("groups.getAgentRoles", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.getAgentRoles", param);
 
             List<GroupRolesData> Roles = new List<GroupRolesData>();
 
@@ -531,14 +544,16 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             }
 
             return Roles;
+
+
         }
 
-        public List<GroupRolesData> GetGroupRoles(UUID GroupID)
+        public List<GroupRolesData> GetGroupRoles(GroupRequestID requestID, UUID GroupID)
         {
             Hashtable param = new Hashtable();
             param["GroupID"] = GroupID.ToString();
 
-            Hashtable respData = XmlRpcCall("groups.getGroupRoles", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.getGroupRoles", param);
 
             List<GroupRolesData> Roles = new List<GroupRolesData>();
 
@@ -561,6 +576,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             }
 
             return Roles;
+
         }
 
         private static GroupMembershipData HashTableToGroupMembershipData(Hashtable respData)
@@ -598,12 +614,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             return data;
         }
 
-        public List<GroupMembersData> GetGroupMembers(UUID GroupID)
+        public List<GroupMembersData> GetGroupMembers(GroupRequestID requestID, UUID GroupID)
         {
             Hashtable param = new Hashtable();
             param["GroupID"] = GroupID.ToString();
 
-            Hashtable respData = XmlRpcCall("groups.getGroupMembers", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.getGroupMembers", param);
 
             List<GroupMembersData> members = new List<GroupMembersData>();
 
@@ -628,14 +644,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             }
 
             return members;
+
         }
 
-        public List<GroupRoleMembersData> GetGroupRoleMembers(UUID GroupID)
+        public List<GroupRoleMembersData> GetGroupRoleMembers(GroupRequestID requestID, UUID GroupID)
         {
             Hashtable param = new Hashtable();
             param["GroupID"] = GroupID.ToString();
 
-            Hashtable respData = XmlRpcCall("groups.getGroupRoleMembers", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.getGroupRoleMembers", param);
 
             List<GroupRoleMembersData> members = new List<GroupRoleMembersData>();
 
@@ -651,16 +668,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
                     members.Add(data);
                 }
             }
-            
             return members;
         }
 
-        public List<GroupNoticeData> GetGroupNotices(UUID GroupID)
+        public List<GroupNoticeData> GetGroupNotices(GroupRequestID requestID, UUID GroupID)
         {
             Hashtable param = new Hashtable();
             param["GroupID"] = GroupID.ToString();
 
-            Hashtable respData = XmlRpcCall("groups.getGroupNotices", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.getGroupNotices", param);
 
             List<GroupNoticeData> values = new List<GroupNoticeData>();
 
@@ -679,16 +695,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
                     values.Add(data);
                 }
             }
-            
             return values;
+
         }
-        
-        public GroupNoticeInfo GetGroupNotice(UUID noticeID)
+        public GroupNoticeInfo GetGroupNotice(GroupRequestID requestID, UUID noticeID)
         {
             Hashtable param = new Hashtable();
             param["NoticeID"] = noticeID.ToString();
 
-            Hashtable respData = XmlRpcCall("groups.getGroupNotice", param);
+            Hashtable respData = XmlRpcCall(requestID, "groups.getGroupNotice", param);
 
 
             if (respData.Contains("error"))
@@ -714,8 +729,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
 
             return data;
         }
-        
-        public void AddGroupNotice(UUID groupID, UUID noticeID, string fromName, string subject, string message, byte[] binaryBucket)
+        public void AddGroupNotice(GroupRequestID requestID, UUID groupID, UUID noticeID, string fromName, string subject, string message, byte[] binaryBucket)
         {
             string binBucket = OpenMetaverse.Utils.BytesToHexString(binaryBucket, "");
 
@@ -728,11 +742,24 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
             param["BinaryBucket"] = binBucket;
             param["TimeStamp"] = ((uint)Util.UnixTimeSinceEpoch()).ToString();
 
-            XmlRpcCall("groups.addGroupNotice", param);
+            XmlRpcCall(requestID, "groups.addGroupNotice", param);
         }
 
-        private Hashtable XmlRpcCall(string function, Hashtable param)
+        private Hashtable XmlRpcCall(GroupRequestID requestID, string function, Hashtable param)
         {
+            if (requestID == null)
+            {
+                requestID = new GroupRequestID();
+            }
+            param.Add("RequestingAgentID", requestID.AgentID.ToString());
+            param.Add("RequestingAgentUserService", requestID.UserServiceURL);
+            param.Add("RequestingSessionID", requestID.SessionID.ToString());
+            
+
+            param.Add("ReadKey", m_groupReadKey);
+            param.Add("WriteKey", m_groupWriteKey);
+
+
             IList parameters = new ArrayList();
             parameters.Add(param);
 
@@ -758,9 +785,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
                 m_log.ErrorFormat("[XMLRPCGROUPDATA]: An error has occured while attempting to access the XmlRpcGroups server method: {0}", function);
                 m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} ", e.ToString());
 
-                foreach (KeyValuePair<object, object> kvp in param)
+                                
+                foreach (string key in param.Keys)
                 {
-                    m_log.WarnFormat("[XMLRPCGROUPDATA]: {0} :: {1}", kvp.Key.ToString(), kvp.Value.ToString());
+                    m_log.WarnFormat("[XMLRPCGROUPDATA]: {0} :: {1}", key, param[key].ToString());
                 }
 
                 Hashtable respData = new Hashtable();
@@ -817,6 +845,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
 
             }
         }
+
     }
 
     public class GroupNoticeInfo
-- 
cgit v1.1