-/*
- Copyright (C) Andrew Tridgell 1998
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
/*
- hosts allow/deny code for rsync
-
- */
+ * Routines to authenticate access to a daemon (hosts allow/deny).
+ *
+ * Copyright (C) 1998 Andrew Tridgell
+ * Copyright (C) 2004-2009 Wayne Davison
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, visit the http://fsf.org website.
+ */
#include "rsync.h"
-
-static int match_hostname(char *host, char *tok)
+static int match_hostname(const char *host, const char *tok)
{
if (!host || !*host)
return 0;
- return wildmatch(tok, host);
+ return iwildmatch(tok, host);
}
-static int match_binary(char *b1, char *b2, char *mask, int addrlen)
+static int match_binary(const char *b1, const char *b2, const char *mask, int addrlen)
{
int i;
return;
}
-static int match_address(char *addr, char *tok)
+static int match_address(const char *addr, const char *tok)
{
char *p;
struct addrinfo hints, *resa, *rest;
ret = match_binary(a, t, mask, addrlen);
-out:
+ out:
freeaddrinfo(resa);
freeaddrinfo(rest);
return ret;
}
-static int access_match(char *list, char *addr, char *host)
+static int access_match(const char *list, const char *addr, const char *host)
{
char *tok;
char *list2 = strdup(list);
out_of_memory("access_match");
strlower(list2);
- if (host)
- strlower(host);
for (tok = strtok(list2, " ,\t"); tok; tok = strtok(NULL, " ,\t")) {
if (match_hostname(host, tok) || match_address(addr, tok)) {
return 0;
}
-int allow_access(char *addr, char *host, char *allow_list, char *deny_list)
+int allow_access(const char *addr, const char *host,
+ const char *allow_list, const char *deny_list)
{
if (allow_list && !*allow_list)
allow_list = NULL;