Blame view

kernel/utsname_sysctl.c 2.49 KB
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  /*
   *  Copyright (C) 2007
   *
   *  Author: Eric Biederman <ebiederm@xmision.com>
   *
   *  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, version 2 of the
   *  License.
   */
  
  #include <linux/module.h>
  #include <linux/uts.h>
  #include <linux/utsname.h>
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
15
16
17
18
19
  #include <linux/sysctl.h>
  
  static void *get_uts(ctl_table *table, int write)
  {
  	char *which = table->data;
32df81cbd   Pavel Emelyanov   Isolate the UTS n...
20
21
22
23
  	struct uts_namespace *uts_ns;
  
  	uts_ns = current->nsproxy->uts_ns;
  	which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
7d69a1f4a   Cedric Le Goater   remove CONFIG_UTS...
24

39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  	if (!write)
  		down_read(&uts_sem);
  	else
  		down_write(&uts_sem);
  	return which;
  }
  
  static void put_uts(ctl_table *table, int write, void *which)
  {
  	if (!write)
  		up_read(&uts_sem);
  	else
  		up_write(&uts_sem);
  }
11dea1900   Serge E. Hallyn   proc_sysctl: use ...
39
  #ifdef CONFIG_PROC_SYSCTL
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
40
41
42
43
  /*
   *	Special case of dostring for the UTS structure. This has locks
   *	to observe. Should this be in kernel/sys.c ????
   */
8d65af789   Alexey Dobriyan   sysctl: remove "s...
44
  static int proc_do_uts_string(ctl_table *table, int write,
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
45
46
47
48
49
50
  		  void __user *buffer, size_t *lenp, loff_t *ppos)
  {
  	struct ctl_table uts_table;
  	int r;
  	memcpy(&uts_table, table, sizeof(uts_table));
  	uts_table.data = get_uts(table, write);
8d65af789   Alexey Dobriyan   sysctl: remove "s...
51
  	r = proc_dostring(&uts_table,write,buffer,lenp, ppos);
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
52
53
54
55
56
57
  	put_uts(table, write, uts_table.data);
  	return r;
  }
  #else
  #define proc_do_uts_string NULL
  #endif
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
58
59
  static struct ctl_table uts_kern_table[] = {
  	{
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
60
61
62
63
64
  		.procname	= "ostype",
  		.data		= init_uts_ns.name.sysname,
  		.maxlen		= sizeof(init_uts_ns.name.sysname),
  		.mode		= 0444,
  		.proc_handler	= proc_do_uts_string,
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
65
66
  	},
  	{
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
67
68
69
70
71
  		.procname	= "osrelease",
  		.data		= init_uts_ns.name.release,
  		.maxlen		= sizeof(init_uts_ns.name.release),
  		.mode		= 0444,
  		.proc_handler	= proc_do_uts_string,
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
72
73
  	},
  	{
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
74
75
76
77
78
  		.procname	= "version",
  		.data		= init_uts_ns.name.version,
  		.maxlen		= sizeof(init_uts_ns.name.version),
  		.mode		= 0444,
  		.proc_handler	= proc_do_uts_string,
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
79
80
  	},
  	{
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
81
82
83
84
85
  		.procname	= "hostname",
  		.data		= init_uts_ns.name.nodename,
  		.maxlen		= sizeof(init_uts_ns.name.nodename),
  		.mode		= 0644,
  		.proc_handler	= proc_do_uts_string,
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
86
87
  	},
  	{
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
88
89
90
91
92
  		.procname	= "domainname",
  		.data		= init_uts_ns.name.domainname,
  		.maxlen		= sizeof(init_uts_ns.name.domainname),
  		.mode		= 0644,
  		.proc_handler	= proc_do_uts_string,
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
93
94
95
96
97
98
  	},
  	{}
  };
  
  static struct ctl_table uts_root_table[] = {
  	{
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
99
100
101
102
103
104
105
106
107
  		.procname	= "kernel",
  		.mode		= 0555,
  		.child		= uts_kern_table,
  	},
  	{}
  };
  
  static int __init utsname_sysctl_init(void)
  {
0b4d41471   Eric W. Biederman   [PATCH] sysctl: r...
108
  	register_sysctl_table(uts_root_table);
39732acd9   Eric W. Biederman   [PATCH] sysctl: m...
109
110
111
112
  	return 0;
  }
  
  __initcall(utsname_sysctl_init);