| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * $Id: acl.h,v 1.3 1999/07/27 18:30:53 mdw Exp $ |
| 4 | * |
| 5 | * Access control list handling |
| 6 | * |
| 7 | * (c) 1999 Straylight/Edgeware |
| 8 | */ |
| 9 | |
| 10 | /*----- Licensing notice --------------------------------------------------* |
| 11 | * |
| 12 | * This file is part of the `fw' port forwarder. |
| 13 | * |
| 14 | * `fw' is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * `fw' is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with `fw'; if not, write to the Free Software Foundation, |
| 26 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 27 | */ |
| 28 | |
| 29 | /*----- Revision history --------------------------------------------------* |
| 30 | * |
| 31 | * $Log: acl.h,v $ |
| 32 | * Revision 1.3 1999/07/27 18:30:53 mdw |
| 33 | * Various minor portability fixes. |
| 34 | * |
| 35 | * Revision 1.2 1999/07/26 23:28:16 mdw |
| 36 | * Minor modifications for new design. |
| 37 | * |
| 38 | * Revision 1.1.1.1 1999/07/01 08:56:23 mdw |
| 39 | * Initial revision. |
| 40 | * |
| 41 | */ |
| 42 | |
| 43 | #ifndef ACL_H |
| 44 | #define ACL_H |
| 45 | |
| 46 | #ifdef __cplusplus |
| 47 | extern "C" { |
| 48 | #endif |
| 49 | |
| 50 | /*----- Header files ------------------------------------------------------*/ |
| 51 | |
| 52 | #include <stdio.h> |
| 53 | |
| 54 | #include <sys/types.h> |
| 55 | #include <sys/socket.h> |
| 56 | #include <netinet/in.h> |
| 57 | |
| 58 | /*----- Data structures ---------------------------------------------------*/ |
| 59 | |
| 60 | /* --- An access control entry --- */ |
| 61 | |
| 62 | typedef struct acl_entry { |
| 63 | struct acl_entry *next; /* Next entry in the list */ |
| 64 | unsigned act; /* What to do with matching hosts */ |
| 65 | struct in_addr addr, mask; /* Address and netmask */ |
| 66 | } acl_entry; |
| 67 | |
| 68 | #define ACL_DENY 0 /* Deny access to matching hosts */ |
| 69 | #define ACL_ALLOW 1 /* Allow access to matching hosts */ |
| 70 | #define ACL_PERM 1u /* Bit mask for permission bit */ |
| 71 | |
| 72 | /*----- Functions provided ------------------------------------------------*/ |
| 73 | |
| 74 | /* --- @acl_check@ --- * |
| 75 | * |
| 76 | * Arguments: @acl_entry *a@ = pointer to ACL to check against |
| 77 | * @struct in_addr addr@ = address to check |
| 78 | * |
| 79 | * Returns: Nonzero if allowed. |
| 80 | * |
| 81 | * Use: Checks an address against an ACL. |
| 82 | */ |
| 83 | |
| 84 | extern int acl_check(acl_entry */*a*/, struct in_addr /*addr*/); |
| 85 | |
| 86 | /* --- @acl_dump@ --- * |
| 87 | * |
| 88 | * Arguments: @acl_entry *a@ = pointer to ACL to dump |
| 89 | * @FILE *fp@ = pointer to stream to dump on |
| 90 | * |
| 91 | * Returns: --- |
| 92 | * |
| 93 | * Use: Dumps an access control list to an output stream. |
| 94 | */ |
| 95 | |
| 96 | extern void acl_dump(acl_entry */*a*/, FILE */*fp*/); |
| 97 | |
| 98 | /* --- @acl_free@ --- * |
| 99 | * |
| 100 | * Arguments: @acl_entry *a@ = pointer to a list of ACLs |
| 101 | * |
| 102 | * Returns: --- |
| 103 | * |
| 104 | * Use: Frees all of the memory used by an ACL. |
| 105 | */ |
| 106 | |
| 107 | extern void acl_free(acl_entry */*a*/); |
| 108 | |
| 109 | /* --- @acl_add@ --- * |
| 110 | * |
| 111 | * Arguments: @acl_entry ***a@ = address of pointer to list tail |
| 112 | * @unsigned act@ = what to do with matching addresses |
| 113 | * @struct in_addr addr, mask@ = address and mask to match |
| 114 | * |
| 115 | * Returns: --- |
| 116 | * |
| 117 | * Use: Adds an entry to the end of an access control list. |
| 118 | */ |
| 119 | |
| 120 | extern void acl_add(acl_entry ***/*a*/, unsigned /*act*/, |
| 121 | struct in_addr /*addr*/, struct in_addr /*mask*/); |
| 122 | |
| 123 | /*----- That's all, folks -------------------------------------------------*/ |
| 124 | |
| 125 | #ifdef __cplusplus |
| 126 | } |
| 127 | #endif |
| 128 | |
| 129 | #endif |