blob: a2cd77e70d4d8359cf3e38b8fb61cc5388fe5cb4 [file] [log] [blame]
Eric W. Biederman39732ac2007-02-14 00:33:58 -08001/*
2 * Copyright (C) 2007
3 *
4 * Author: Eric Biederman <ebiederm@xmision.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2 of the
9 * License.
10 */
11
12#include <linux/module.h>
13#include <linux/uts.h>
14#include <linux/utsname.h>
Eric W. Biederman39732ac2007-02-14 00:33:58 -080015#include <linux/sysctl.h>
16
17static void *get_uts(ctl_table *table, int write)
18{
19 char *which = table->data;
Pavel Emelyanov32df81c2007-11-28 16:21:38 -080020 struct uts_namespace *uts_ns;
21
22 uts_ns = current->nsproxy->uts_ns;
23 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
Cedric Le Goater7d69a1f2007-07-15 23:40:58 -070024
Eric W. Biederman39732ac2007-02-14 00:33:58 -080025 if (!write)
26 down_read(&uts_sem);
27 else
28 down_write(&uts_sem);
29 return which;
30}
31
32static void put_uts(ctl_table *table, int write, void *which)
33{
34 if (!write)
35 up_read(&uts_sem);
36 else
37 up_write(&uts_sem);
38}
39
Serge E. Hallyn11dea192009-04-02 16:58:27 -070040#ifdef CONFIG_PROC_SYSCTL
Eric W. Biederman39732ac2007-02-14 00:33:58 -080041/*
42 * Special case of dostring for the UTS structure. This has locks
43 * to observe. Should this be in kernel/sys.c ????
44 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070045static int proc_do_uts_string(ctl_table *table, int write,
Eric W. Biederman39732ac2007-02-14 00:33:58 -080046 void __user *buffer, size_t *lenp, loff_t *ppos)
47{
48 struct ctl_table uts_table;
49 int r;
50 memcpy(&uts_table, table, sizeof(uts_table));
51 uts_table.data = get_uts(table, write);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070052 r = proc_dostring(&uts_table,write,buffer,lenp, ppos);
Eric W. Biederman39732ac2007-02-14 00:33:58 -080053 put_uts(table, write, uts_table.data);
54 return r;
55}
56#else
57#define proc_do_uts_string NULL
58#endif
59
Eric W. Biederman39732ac2007-02-14 00:33:58 -080060static struct ctl_table uts_kern_table[] = {
61 {
Eric W. Biederman39732ac2007-02-14 00:33:58 -080062 .procname = "ostype",
63 .data = init_uts_ns.name.sysname,
64 .maxlen = sizeof(init_uts_ns.name.sysname),
65 .mode = 0444,
66 .proc_handler = proc_do_uts_string,
Eric W. Biederman39732ac2007-02-14 00:33:58 -080067 },
68 {
Eric W. Biederman39732ac2007-02-14 00:33:58 -080069 .procname = "osrelease",
70 .data = init_uts_ns.name.release,
71 .maxlen = sizeof(init_uts_ns.name.release),
72 .mode = 0444,
73 .proc_handler = proc_do_uts_string,
Eric W. Biederman39732ac2007-02-14 00:33:58 -080074 },
75 {
Eric W. Biederman39732ac2007-02-14 00:33:58 -080076 .procname = "version",
77 .data = init_uts_ns.name.version,
78 .maxlen = sizeof(init_uts_ns.name.version),
79 .mode = 0444,
80 .proc_handler = proc_do_uts_string,
Eric W. Biederman39732ac2007-02-14 00:33:58 -080081 },
82 {
Eric W. Biederman39732ac2007-02-14 00:33:58 -080083 .procname = "hostname",
84 .data = init_uts_ns.name.nodename,
85 .maxlen = sizeof(init_uts_ns.name.nodename),
86 .mode = 0644,
87 .proc_handler = proc_do_uts_string,
Eric W. Biederman39732ac2007-02-14 00:33:58 -080088 },
89 {
Eric W. Biederman39732ac2007-02-14 00:33:58 -080090 .procname = "domainname",
91 .data = init_uts_ns.name.domainname,
92 .maxlen = sizeof(init_uts_ns.name.domainname),
93 .mode = 0644,
94 .proc_handler = proc_do_uts_string,
Eric W. Biederman39732ac2007-02-14 00:33:58 -080095 },
96 {}
97};
98
99static struct ctl_table uts_root_table[] = {
100 {
Eric W. Biederman39732ac2007-02-14 00:33:58 -0800101 .procname = "kernel",
102 .mode = 0555,
103 .child = uts_kern_table,
104 },
105 {}
106};
107
108static int __init utsname_sysctl_init(void)
109{
Eric W. Biederman0b4d4142007-02-14 00:34:09 -0800110 register_sysctl_table(uts_root_table);
Eric W. Biederman39732ac2007-02-14 00:33:58 -0800111 return 0;
112}
113
114__initcall(utsname_sysctl_init);