]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/users.cpp
Security audit based on RATS output
[user/henk/code/inspircd.git] / src / users.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include "inspircd_config.h" 
18 #include "channels.h"
19 #include "users.h"
20 #include "inspircd.h"
21 #include <stdio.h>
22
23 extern std::stringstream config_f;
24
25 userrec::userrec()
26 {
27         // the PROPER way to do it, AVOID bzero at *ALL* costs
28         strcpy(nick,"");
29         strcpy(ip,"127.0.0.1");
30         timeout = 0;
31         strcpy(ident,"");
32         strcpy(host,"");
33         strcpy(dhost,"");
34         strcpy(fullname,"");
35         strcpy(modes,"");
36         strcpy(inbuf,"");
37         strcpy(server,"");
38         strcpy(awaymsg,"");
39         fd = lastping = signon = idle_lastmsg = nping = registered = 0;
40         flood = port = bytes_in = bytes_out = cmds_in = cmds_out = 0;
41         haspassed = false;
42         strcpy(result,"");
43         for (int i = 0; i < MAXCHANS; i++)
44         {
45                 this->chans[i].channel = NULL;
46                 this->chans[i].uc_modes = 0;
47         }
48         invites.clear();
49 }
50
51
52  
53 char* userrec::GetFullHost()
54 {
55         snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,dhost);
56         return result;
57 }
58
59
60 char* userrec::GetFullRealHost()
61 {
62         snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,host);
63         return result;
64 }
65
66 bool userrec::IsInvited(char* channel)
67 {
68         for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
69         {
70                 if (i->channel) {
71                         if (!strcasecmp(i->channel,channel))
72                         {
73                                 return true;
74                         }
75                 }
76         }
77         return false;
78 }
79
80 void userrec::InviteTo(char* channel)
81 {
82         Invited i;
83         strlcpy(i.channel,channel,CHANMAX);
84         invites.push_back(i);
85 }
86
87 void userrec::RemoveInvite(char* channel)
88 {
89         log(DEBUG,"Removing invites");
90         if (channel)
91         {
92                 if (invites.size())
93                 {
94                         for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
95                         {
96                                 if (i->channel)
97                                 {
98                                         if (!strcasecmp(i->channel,channel))
99                                         {
100                                                 invites.erase(i);
101                                                 return;
102                                         }
103                                 }
104                         }
105                 }
106         }
107 }
108
109 bool userrec::HasPermission(char* command)
110 {
111         char TypeName[MAXBUF],Classes[MAXBUF],ClassName[MAXBUF],CommandList[MAXBUF];
112         char* myclass;
113         char* mycmd;
114         char* savept;
115         char* savept2;
116         
117         // are they even an oper at all?
118         if (strchr(this->modes,'o'))
119         {
120                 log(DEBUG,"*** HasPermission: %s is an oper",this->nick);
121                 for (int j =0; j < ConfValueEnum("type",&config_f); j++)
122                 {
123                         ConfValue("type","name",j,TypeName,&config_f);
124                         if (!strcmp(TypeName,this->oper))
125                         {
126                                 log(DEBUG,"*** HasPermission: %s is an oper of type '%s'",this->nick,this->oper);
127                                 ConfValue("type","classes",j,Classes,&config_f);
128                                 char* myclass = strtok_r(Classes," ",&savept);
129                                 while (myclass)
130                                 {
131                                         log(DEBUG,"*** HasPermission: checking classtype '%s'",myclass);
132                                         for (int k =0; k < ConfValueEnum("class",&config_f); k++)
133                                         {
134                                                 ConfValue("class","name",k,ClassName,&config_f);
135                                                 if (!strcmp(ClassName,myclass))
136                                                 {
137                                                         ConfValue("class","commands",k,CommandList,&config_f);
138                                                         log(DEBUG,"*** HasPermission: found class named %s with commands: '%s'",ClassName,CommandList);
139                                                         
140                                                         
141                                                         mycmd = strtok_r(CommandList," ",&savept2);
142                                                         while (mycmd)
143                                                         {
144                                                                 if (!strcasecmp(mycmd,command))
145                                                                 {
146                                                                         log(DEBUG,"*** Command %s found, returning true",command);
147                                                                         return true;
148                                                                 }
149                                                                 mycmd = strtok_r(NULL," ",&savept2);
150                                                         }
151                                                 }
152                                         }
153                                         myclass = strtok_r(NULL," ",&savept);
154                                 }
155                         }
156                 }
157         }
158         return false;
159 }
160
161