2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
9 #include <linux/errno.h>
10 #include <linux/types.h>
11 #include <linux/socket.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/timer.h>
16 #include <linux/string.h>
17 #include <linux/sockios.h>
18 #include <linux/net.h>
19 #include <linux/spinlock.h>
21 #include <linux/inet.h>
22 #include <linux/netdevice.h>
23 #include <linux/if_arp.h>
24 #include <linux/skbuff.h>
26 #include <asm/uaccess.h>
27 #include <asm/system.h>
28 #include <linux/fcntl.h>
30 #include <linux/interrupt.h>
31 #include <linux/notifier.h>
32 #include <linux/proc_fs.h>
33 #include <linux/seq_file.h>
34 #include <linux/stat.h>
35 #include <linux/netfilter.h>
36 #include <linux/sysctl.h>
41 * Callsign/UID mapper. This is in kernel space for security on multi-amateur machines.
44 static ax25_uid_assoc
*ax25_uid_list
;
45 static DEFINE_RWLOCK(ax25_uid_lock
);
47 int ax25_uid_policy
= 0;
49 ax25_address
*ax25_findbyuid(uid_t uid
)
51 ax25_uid_assoc
*ax25_uid
;
52 ax25_address
*res
= NULL
;
54 read_lock(&ax25_uid_lock
);
55 for (ax25_uid
= ax25_uid_list
; ax25_uid
!= NULL
; ax25_uid
= ax25_uid
->next
) {
56 if (ax25_uid
->uid
== uid
) {
57 res
= &ax25_uid
->call
;
61 read_unlock(&ax25_uid_lock
);
66 int ax25_uid_ioctl(int cmd
, struct sockaddr_ax25
*sax
)
68 ax25_uid_assoc
*s
, *ax25_uid
;
74 read_lock(&ax25_uid_lock
);
75 for (ax25_uid
= ax25_uid_list
; ax25_uid
!= NULL
; ax25_uid
= ax25_uid
->next
) {
76 if (ax25cmp(&sax
->sax25_call
, &ax25_uid
->call
) == 0) {
81 read_unlock(&ax25_uid_lock
);
86 if (!capable(CAP_NET_ADMIN
))
88 if (ax25_findbyuid(sax
->sax25_uid
))
90 if (sax
->sax25_uid
== 0)
92 if ((ax25_uid
= kmalloc(sizeof(*ax25_uid
), GFP_KERNEL
)) == NULL
)
95 ax25_uid
->uid
= sax
->sax25_uid
;
96 ax25_uid
->call
= sax
->sax25_call
;
98 write_lock(&ax25_uid_lock
);
99 ax25_uid
->next
= ax25_uid_list
;
100 ax25_uid_list
= ax25_uid
;
101 write_unlock(&ax25_uid_lock
);
106 if (!capable(CAP_NET_ADMIN
))
109 write_lock(&ax25_uid_lock
);
110 for (ax25_uid
= ax25_uid_list
; ax25_uid
!= NULL
; ax25_uid
= ax25_uid
->next
) {
111 if (ax25cmp(&sax
->sax25_call
, &ax25_uid
->call
) == 0) {
115 if (ax25_uid
== NULL
) {
116 write_unlock(&ax25_uid_lock
);
119 if ((s
= ax25_uid_list
) == ax25_uid
) {
120 ax25_uid_list
= s
->next
;
121 write_unlock(&ax25_uid_lock
);
125 while (s
!= NULL
&& s
->next
!= NULL
) {
126 if (s
->next
== ax25_uid
) {
127 s
->next
= ax25_uid
->next
;
128 write_unlock(&ax25_uid_lock
);
134 write_unlock(&ax25_uid_lock
);
142 return -EINVAL
; /*NOTREACHED */
145 #ifdef CONFIG_PROC_FS
147 static void *ax25_uid_seq_start(struct seq_file
*seq
, loff_t
*pos
)
149 struct ax25_uid_assoc
*pt
;
152 read_lock(&ax25_uid_lock
);
154 return SEQ_START_TOKEN
;
156 for (pt
= ax25_uid_list
; pt
!= NULL
; pt
= pt
->next
) {
164 static void *ax25_uid_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
167 return (v
== SEQ_START_TOKEN
) ? ax25_uid_list
:
168 ((struct ax25_uid_assoc
*) v
)->next
;
171 static void ax25_uid_seq_stop(struct seq_file
*seq
, void *v
)
173 read_unlock(&ax25_uid_lock
);
176 static int ax25_uid_seq_show(struct seq_file
*seq
, void *v
)
178 if (v
== SEQ_START_TOKEN
)
179 seq_printf(seq
, "Policy: %d\n", ax25_uid_policy
);
181 struct ax25_uid_assoc
*pt
= v
;
184 seq_printf(seq
, "%6d %s\n", pt
->uid
, ax2asc(&pt
->call
));
189 static struct seq_operations ax25_uid_seqops
= {
190 .start
= ax25_uid_seq_start
,
191 .next
= ax25_uid_seq_next
,
192 .stop
= ax25_uid_seq_stop
,
193 .show
= ax25_uid_seq_show
,
196 static int ax25_uid_info_open(struct inode
*inode
, struct file
*file
)
198 return seq_open(file
, &ax25_uid_seqops
);
201 struct file_operations ax25_uid_fops
= {
202 .owner
= THIS_MODULE
,
203 .open
= ax25_uid_info_open
,
206 .release
= seq_release
,
212 * Free all memory associated with UID/Callsign structures.
214 void __exit
ax25_uid_free(void)
216 ax25_uid_assoc
*s
, *ax25_uid
;
218 write_lock(&ax25_uid_lock
);
219 ax25_uid
= ax25_uid_list
;
220 while (ax25_uid
!= NULL
) {
222 ax25_uid
= ax25_uid
->next
;
226 ax25_uid_list
= NULL
;
227 write_unlock(&ax25_uid_lock
);