#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <stdio.h>
#include <strings.h>
#include "defines.h"
#include "lists.h"
#include "log.h"
#include "messages.h"
+#include "match.h"
#include "exp.h"
static CL2CHAN *Get_Next_Cl2Chan PARAMS(( CL2CHAN *Start, CLIENT *Client, CHANNEL *Chan ));
static void Delete_Channel PARAMS(( CHANNEL *Chan ));
static void Free_Channel PARAMS(( CHANNEL *Chan ));
+static void Update_Predefined PARAMS((CHANNEL *Chan,
+ const struct Conf_Channel *Conf_Chan));
+static void Set_Key_File PARAMS((CHANNEL *Chan, FILE *KeyFile));
GLOBAL void
new_chan = Channel_Search(conf_chan->name);
if (new_chan) {
- Log(LOG_INFO, "Can't create pre-defined channel \"%s\": name already in use.",
- conf_chan->name);
+ Log(LOG_INFO,
+ "Can't create pre-defined channel \"%s\": name already in use.",
+ conf_chan->name);
+ Update_Predefined(new_chan, conf_chan);
continue;
}
conf_chan->name);
continue;
}
+ Log(LOG_INFO, "Created pre-defined channel \"%s\"",
+ conf_chan->name);
Channel_ModeAdd(new_chan, 'P');
Channel_SetKey(new_chan, conf_chan->key);
Channel_SetMaxUsers(new_chan, conf_chan->maxusers);
- Log(LOG_INFO, "Created pre-defined channel \"%s\"",
- conf_chan->name);
+ Update_Predefined(new_chan, conf_chan);
}
if (channel_count)
array_free(&Conf_Channels);
array_free(&chan->topic);
Lists_Free(&chan->list_bans);
Lists_Free(&chan->list_invites);
+ if (Chan->keyfile)
+ fclose(Chan->keyfile);
free(chan);
}
} /* Channel_LogServer */
+GLOBAL bool
+Channel_CheckKey(CHANNEL *Chan, CLIENT *Client, const char *Key)
+{
+ char line[COMMAND_LEN], *nick, *pass;
+
+ assert(Chan != NULL);
+ assert(Client != NULL);
+ assert(Key != NULL);
+
+ if (!strchr(Chan->modes, 'k'))
+ return true;
+ if (strcmp(Chan->key, Key) == 0)
+ return true;
+ if (!Chan->keyfile)
+ return false;
+
+ Chan->keyfile = freopen(NULL, "r", Chan->keyfile);
+ while (fgets(line, sizeof(line), Chan->keyfile) != NULL) {
+ ngt_TrimStr(line);
+ if (! (nick = strchr(line, ':')))
+ continue;
+ *nick++ = '\0';
+ if (!Match(line, Client_User(Client)))
+ continue;
+ if (! (pass = strchr(nick, ':')))
+ continue;
+ *pass++ = '\0';
+ if (!Match(nick, Client_ID(Client)))
+ continue;
+ if (strcmp(Key, pass) != 0)
+ continue;
+
+ return true;
+ }
+ return false;
+} /* Channel_CheckKey */
+
+
static CL2CHAN *
Get_First_Cl2Chan( CLIENT *Client, CHANNEL *Chan )
{
} /* Delete_Channel */
+static void
+Update_Predefined(CHANNEL *Chan, const struct Conf_Channel *Conf_Chan)
+{
+ FILE *fd;
+
+ if (! Conf_Chan->keyfile || ! *Conf_Chan->keyfile)
+ return;
+
+ fd = fopen(Conf_Chan->keyfile, "r");
+ if (! fd)
+ Log(LOG_ERR,
+ "Can't open channel key file for \"%s\", \"%s\": %s",
+ Conf_Chan->name, Conf_Chan->keyfile,
+ strerror(errno));
+ else
+ Set_Key_File(Chan, fd);
+} /* Update_Predefined */
+
+
+static void
+Set_Key_File(CHANNEL *Chan, FILE *KeyFile)
+{
+ assert(Chan != NULL);
+
+ if (Chan->keyfile)
+ fclose(Chan->keyfile);
+ Chan->keyfile = KeyFile;
+ Log(LOG_INFO|LOG_snotice,
+ "New local channel key file for \"%s\" activated.", Chan->name);
+} /* Set_Key_File */
+
+
/* -eof- */