]>
Commit | Line | Data |
---|---|---|
e3805f60 P |
1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: domainmode | |
5 | * CMDLEVEL: QCMD_OPER | |
6 | * CMDARGS: 4 | |
7 | * CMDDESC: Set/Unset Mail Domain Modes | |
8 | * CMDFUNC: csu_dodomainmode | |
9 | * CMDPROTO: int csu_dodomainmode(void *source, int cargc, char **cargv); | |
94e4d2f4 | 10 | * CMDHELP: Usage: domainmode <domain> [<flags>] |
85174237 CP |
11 | * CMDHELP: Views or modifies the domainmode flags for specified domain. |
12 | * CMDHELP: Flags consist of: | |
13 | * CMDHELP: +b don't allow email addresses from this domain. | |
14 | * CMDHELP: +u <limit> don't allow more than <limit> accounts to share | |
15 | * CMDHELP: email addresses on this domain. | |
16 | * CMDHELP: +l <limit> don't allow more than <limit> accounts with | |
17 | * CMDHELP: email addresses on this domain. | |
18 | * CMDHELP: Note that domains are hierarchical, so setting +b on org will | |
19 | * CMDHELP: prevent operations from quakenet.org, fish.quakenet.org, etc. | |
e3805f60 P |
20 | */ |
21 | ||
22 | #include "../chanserv.h" | |
23 | #include "../../lib/irc_string.h" | |
24 | #include <stdio.h> | |
25 | #include <string.h> | |
26 | ||
27 | char *getdomainmode(maildomain *mdp) { | |
28 | static char buf1[50]; | |
29 | char buf2[30]; | |
30 | ||
31 | if (mdp->flags) { | |
32 | strcpy(buf1,printflags(mdp->flags, mdflags)); | |
33 | } else { | |
34 | buf1[0]='\0'; | |
35 | } | |
36 | ||
37 | if (mdp->flags & MDFLAG_LIMIT) { | |
38 | sprintf(buf2, " %d",mdp->limit); | |
39 | strcat(buf1, buf2); | |
40 | } | |
41 | ||
42 | if (mdp->flags & MDFLAG_ACTLIMIT) { | |
43 | sprintf(buf2, " %d",mdp->actlimit); | |
44 | strcat(buf1, buf2); | |
45 | } | |
46 | ||
47 | if (*buf1=='\0') { | |
48 | strcpy(buf1,"(none)"); | |
49 | } | |
50 | ||
51 | return buf1; | |
52 | } | |
53 | ||
ff12167d | 54 | int checkdomain(char *dom) { |
1dfc03b0 | 55 | const char *validchars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"; |
ff12167d | 56 | int hypok=0; |
6cb1b086 | 57 | char lastch = '\0'; |
1dfc03b0 | 58 | char *ch; |
ff12167d | 59 | |
1dfc03b0 | 60 | for (ch=dom;*ch;ch++) { |
ff12167d | 61 | if (*ch=='.') { |
62 | if (hypok==0) { | |
63 | /* This is two dots in a row - bad */ | |
64 | return 1; | |
65 | } | |
66 | hypok=0; | |
67 | } else if (*ch=='-') { | |
68 | if (hypok==0) { | |
69 | /* either .- or - at the start - bad */ | |
70 | return 1; | |
71 | } | |
72 | } else { | |
73 | if (!strchr(validchars, *ch)) { | |
74 | /* Unrecognized char */ | |
75 | return 1; | |
76 | } | |
77 | ||
78 | /* We encountered some random valid characters, so hyphens (and dots) are now OK until the next dot */ | |
79 | hypok=1; | |
80 | } | |
81 | lastch=*ch; | |
82 | } | |
83 | ||
84 | if (lastch=='.') { | |
85 | /* Can't end on a dot */ | |
86 | return 1; | |
87 | } | |
88 | ||
89 | return 0; | |
90 | } | |
91 | ||
e3805f60 P |
92 | int csu_dodomainmode(void *source, int cargc, char **cargv) { |
93 | maildomain *mdp; | |
94 | nick *sender=source; | |
30ed6d2c | 95 | flag_t forceflags, currentflags; |
e3805f60 P |
96 | char buf1[60]; |
97 | int carg=2,limdone=0,actlimdone=0; | |
e3805f60 P |
98 | unsigned int newlim=0; |
99 | unsigned int newactlim=0; | |
100 | ||
101 | if (cargc<1) { | |
102 | chanservstdmessage(sender,QM_NOTENOUGHPARAMS,"domainmode"); | |
103 | return CMD_ERROR; | |
104 | } | |
105 | ||
ff12167d | 106 | if (checkdomain(cargv[0])) { |
107 | chanservstdmessage(sender,QM_INVALIDDOMAIN,cargv[0]); | |
108 | return CMD_ERROR; | |
109 | } | |
110 | ||
e3805f60 P |
111 | if(!(mdp=findorcreatemaildomain(cargv[0]))) { |
112 | return CMD_ERROR; | |
113 | } | |
114 | ||
115 | if (cargc>1) { | |
116 | /* Save the current modes.. */ | |
117 | strcpy(buf1,getdomainmode(mdp)); | |
118 | ||
119 | /* Pick out the + flags: start from 0 */ | |
120 | forceflags=0; | |
121 | setflags(&forceflags, MDFLAG_ALL, cargv[1], mdflags, REJECT_NONE); | |
30ed6d2c CP |
122 | currentflags=mdp->flags; |
123 | setflags(¤tflags, MDFLAG_ALL, cargv[1], mdflags, REJECT_NONE); | |
e3805f60 P |
124 | |
125 | if ((forceflags & MDFLAG_LIMIT) && | |
126 | (!(forceflags & MDFLAG_ACTLIMIT) || strrchr(cargv[1],'l') < strrchr(cargv[1],'u'))) { | |
127 | if (cargc<=carg) { | |
128 | chanservstdmessage(sender,QM_NOTENOUGHPARAMS,"domainmode"); | |
129 | return CMD_ERROR; | |
130 | } | |
131 | newlim=strtol(cargv[carg++],NULL,10); | |
132 | limdone=1; | |
133 | } | |
134 | ||
135 | if ((forceflags & MDFLAG_LIMIT) && !limdone) { | |
136 | if (cargc<=carg) { | |
137 | chanservstdmessage(sender,QM_NOTENOUGHPARAMS,"domainmode"); | |
138 | return CMD_ERROR; | |
139 | } | |
140 | newlim=strtol(cargv[carg++],NULL,10); | |
141 | limdone=1; | |
142 | } | |
143 | ||
144 | if ((forceflags & MDFLAG_ACTLIMIT) && !actlimdone) { | |
145 | if (cargc<=carg) { | |
146 | chanservstdmessage(sender,QM_NOTENOUGHPARAMS,"chanmode"); | |
147 | return CMD_ERROR; | |
148 | } | |
149 | newactlim=strtol(cargv[carg++],NULL,10); | |
150 | actlimdone=1; | |
151 | } | |
152 | ||
153 | /* It parsed OK, so update the structure.. */ | |
30ed6d2c CP |
154 | mdp->flags=currentflags; |
155 | if(actlimdone) | |
156 | mdp->actlimit=newactlim; | |
157 | if(!(currentflags & MDFLAG_ACTLIMIT)) | |
158 | mdp->actlimit=0; | |
159 | if(limdone) | |
160 | mdp->limit=newlim; | |
161 | if(!(currentflags & MDFLAG_LIMIT)) | |
162 | mdp->limit=0; | |
e3805f60 P |
163 | if(mdp->ID) { |
164 | if(mdp->flags) { | |
165 | csdb_updatemaildomain(mdp); | |
166 | } else { | |
167 | csdb_deletemaildomain(mdp); | |
168 | } | |
169 | } else { | |
170 | mdp->ID=++lastdomainID; | |
171 | csdb_createmaildomain(mdp); | |
172 | } | |
173 | ||
174 | chanservstdmessage(sender, QM_DONE); | |
175 | cs_log(sender,"DOMAINMODE %s %s (%s -> %s)",mdp->name->content,cargv[1],buf1,getdomainmode(mdp)); | |
176 | } | |
177 | chanservstdmessage(sender,QM_CURDOMAINMODES,mdp->name->content,getdomainmode(mdp)); | |
178 | ||
179 | return CMD_OK; | |
180 | } |