summaryrefslogtreecommitdiffstats
path: root/zarb-ml/mageia-dev/2012-November/019802.html
blob: daff9fbd1bb1587c54a922369f9e88a699301ac7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
 <HEAD>
   <TITLE> [Mageia-dev] [soft-commits] [6416] Initial commit of Admin	Panel.
   </TITLE>
   <LINK REL="Index" HREF="index.html" >
   <LINK REL="made" HREF="mailto:mageia-dev%40mageia.org?Subject=Re%3A%20%5BMageia-dev%5D%20%5Bsoft-commits%5D%20%5B6416%5D%20Initial%20commit%20of%20Admin%0A%09Panel.&In-Reply-To=%3C5098FF94.5010004%40gmail.com%3E">
   <META NAME="robots" CONTENT="index,nofollow">
   <META http-equiv="Content-Type" content="text/html; charset=us-ascii">
   <LINK REL="Previous"  HREF="019803.html">
   <LINK REL="Next"  HREF="019810.html">
 </HEAD>
 <BODY BGCOLOR="#ffffff">
   <H1>[Mageia-dev] [soft-commits] [6416] Initial commit of Admin	Panel.</H1>
    <B>Guillaume Rousse</B> 
    <A HREF="mailto:mageia-dev%40mageia.org?Subject=Re%3A%20%5BMageia-dev%5D%20%5Bsoft-commits%5D%20%5B6416%5D%20Initial%20commit%20of%20Admin%0A%09Panel.&In-Reply-To=%3C5098FF94.5010004%40gmail.com%3E"
       TITLE="[Mageia-dev] [soft-commits] [6416] Initial commit of Admin	Panel.">guillomovitch at gmail.com
       </A><BR>
    <I>Tue Nov  6 13:16:20 CET 2012</I>
    <P><UL>
        <LI>Previous message: <A HREF="019803.html">[Mageia-dev] Back to our weekly meetings
</A></li>
        <LI>Next message: <A HREF="019810.html">[Mageia-dev] [soft-commits] [6416] Initial commit of Admin	Panel.
</A></li>
         <LI> <B>Messages sorted by:</B> 
              <a href="date.html#19802">[ date ]</a>
              <a href="thread.html#19802">[ thread ]</a>
              <a href="subject.html#19802">[ subject ]</a>
              <a href="author.html#19802">[ author ]</a>
         </LI>
       </UL>
    <HR>  
<!--beginarticle-->
<PRE>Le 06/11/2012 12:09, <A HREF="https://www.mageia.org/mailman/listinfo/mageia-dev">root at mageia.org</A> a &#233;crit :
&gt;<i> Revision
</I>&gt;<i>     6416
</I>&gt;<i> Author
</I>&gt;<i>     tuxta
</I>&gt;<i> Date
</I>&gt;<i>     2012-11-06 12:09:51 +0100 (Tue, 06 Nov 2012)
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i>       Log Message
</I>&gt;<i>
</I>&gt;<i> Initial commit of Admin Panel.
</I>&gt;<i> Has basic functionality that you might expect from the core program, escalates priviledges, loads categories and modules dynamically from configuration file, launches modules and returns to the panel once the module has completed. Works within ncurses, gtk and qt environments using the native widget set.
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i>       Added Paths
</I>&gt;<i>
</I>&gt;<i>   * AdminPanel/trunk/
</I>&gt;<i>   * AdminPanel/trunk/Auth.pm &lt;#AdminPaneltrunkAuthpm&gt;
</I>&gt;<i>   * AdminPanel/trunk/Category.pm &lt;#AdminPaneltrunkCategorypm&gt;
</I>&gt;<i>   * AdminPanel/trunk/ConfigReader.pm &lt;#AdminPaneltrunkConfigReaderpm&gt;
</I>&gt;<i>   * AdminPanel/trunk/MainDisplay.pm &lt;#AdminPaneltrunkMainDisplaypm&gt;
</I>&gt;<i>   * AdminPanel/trunk/Module.pm &lt;#AdminPaneltrunkModulepm&gt;
</I>&gt;<i>   * AdminPanel/trunk/SettingsReader.pm &lt;#AdminPaneltrunkSettingsReaderpm&gt;
</I>&gt;<i>   * AdminPanel/trunk/apanel.pl &lt;#AdminPaneltrunkapanelpl&gt;
</I>&gt;<i>   * AdminPanel/trunk/categories.conf &lt;#AdminPaneltrunkcategoriesconf&gt;
</I>&gt;<i>   * AdminPanel/trunk/extras/
</I>&gt;<i>   * AdminPanel/trunk/extras/README &lt;#AdminPaneltrunkextrasREADME&gt;
</I>&gt;<i>   * AdminPanel/trunk/extras/org.freedesktop.policykit.pkexec.policy
</I>&gt;<i>     &lt;#AdminPaneltrunkextrasorgfreedesktoppolicykitpkexecpolicy&gt;
</I>&gt;<i>   * AdminPanel/trunk/images/
</I>&gt;<i>   * AdminPanel/trunk/images/logo_mageia.png
</I>&gt;<i>     &lt;#AdminPaneltrunkimageslogo_mageiapng&gt;
</I>&gt;<i>   * AdminPanel/trunk/images/mageia.png &lt;#AdminPaneltrunkimagesmageiapng&gt;
</I>&gt;<i>   * AdminPanel/trunk/images/quit.png &lt;#AdminPaneltrunkimagesquitpng&gt;
</I>&gt;<i>   * AdminPanel/trunk/modules/
</I>&gt;<i>   * AdminPanel/trunk/modules/test.cpp &lt;#AdminPaneltrunkmodulestestcpp&gt;
</I>&gt;<i>   * AdminPanel/trunk/settings.conf &lt;#AdminPaneltrunksettingsconf&gt;
</I>&gt;<i>
</I>&gt;<i> Added: AdminPanel/trunk/Auth.pm
</I>&gt;<i> ===================================================================
</I>&gt;<i> --- AdminPanel/trunk/Auth.pm	                        (rev 0)
</I>&gt;<i> +++ AdminPanel/trunk/Auth.pm	2012-11-06 11:09:51 UTC (rev 6416)
</I>&gt;<i> @@ -0,0 +1,50 @@
</I>&gt;<i> +#    Copyright 2012 Matteo Pasotti
</I>&gt;<i> +#
</I>&gt;<i> +#    This file is part of mcc2
</I>&gt;<i> +#
</I>&gt;<i> +#    mcc2 is free software: you can redistribute it and/or modify
</I>&gt;<i> +#    it under the terms of the GNU General Public License as published by
</I>&gt;<i> +#    the Free Software Foundation, either version 2 of the License, or
</I>&gt;<i> +#    (at your option) any later version.
</I>&gt;<i> +#
</I>&gt;<i> +#    mcc2 is distributed in the hope that it will be useful,
</I>&gt;<i> +#    but WITHOUT ANY WARRANTY; without even the implied warranty of
</I>&gt;<i> +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
</I>&gt;<i> +#    GNU General Public License for more details.
</I>&gt;<i> +#
</I>&gt;<i> +#    You should have received a copy of the GNU General Public License
</I>&gt;<i> +#    along with mcc2.  If not, see &lt;<A HREF="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</A>&gt;.
</I>I'm not convinced of the interest of repeating license and copyright 
information in every single file, whereas a single top-level README file 
would be enough.

&gt;<i> +
</I>&gt;<i> +package Auth;
</I>I'm convinced tough than using a shared top-level namespace, for 
instance AdminPanel or Mageia::AdminPanel, would be a better idea to 
express the idea than this module is a part of a software, than a loose 
comment such as &quot;This file is part of mcc2&quot;.
package Mageia::AdminPanel::Auth;

&gt;<i> +
</I>&gt;<i> +require Exporter;
</I>&gt;<i> <A HREF="https://www.mageia.org/mailman/listinfo/mageia-dev">+ at ISA</A> = qw(Exporter);
</I>You'd rather use a modern perl idiom:
use base qw(Exporter)

or

use parent qw(Exporter);

&gt;<i> <A HREF="https://www.mageia.org/mailman/listinfo/mageia-dev">+ at EXPORT</A> = qw(require_root_capability
</I>&gt;<i> +	     ask_for_authentication);
</I>&gt;<i> +
</I>&gt;<i> +use strict;
</I>&gt;<i> +use warnings;
</I>&gt;<i> +use diagnostics;
</I>Those pragmas should come first, before package variables

&gt;<i> +use Data::Dumper;
</I>Unused anywere. Don't load debug-related modules in production coed.

&gt;<i> +sub require_root_capability {
</I>&gt;<i> +	return 0 if(!$&gt;);
</I>&gt;<i> +	return 1;
</I>&gt;<i> +}
</I>Perl best practice: use english name for magic variables, for readability:

use English qw(-no_match_vars );
return 0 if (!$EUID);

And your condition could be expressed in a single statement:
sub require_root_capability {
     return $EUID == 0;
}

&gt;<i> +
</I>&gt;<i> +sub ask_for_authentication {
</I>&gt;<i> +	my @args = @ARGV;
</I>&gt;<i> +	my $command = wrap_command($0);
</I>&gt;<i> +	unshift(@args, $command-&gt;[2]);
</I>&gt;<i> +	exec { $command-&gt;[0] } $command-&gt;[1], @args or die (&quot;command %s missing&quot;, $command-&gt;[0]);
</I>&gt;<i> +	die &quot;You must be root to run this program&quot; if $&gt;;
</I>&gt;<i> +}
</I>You're duplicating the condition from previous function here.
die &quot;You must be root to run this program&quot; if
     !require_root_capability();

Morevoer, you'd better test before executing the command:
die &quot;You must be root to run this program&quot; if
     !require_root_capability();
exec { $command-&gt;[0] } $command-&gt;[1], @args
     or die (&quot;command %s missing&quot;, $command-&gt;[0]);

&gt;<i> +sub wrap_command {
</I>&gt;<i> +	my $currenv = &quot;env&quot;;
</I>&gt;<i> +	my $wrapper = &quot;pkexec&quot;;
</I>&gt;<i> +	my $app = $0;
</I>&gt;<i> +	my $command = [$wrapper, $currenv, $app];
</I>&gt;<i> +	($command);
</I>&gt;<i> +}
</I>Perl best practice: use explicit return statement, for better readability:
return ($command);

Using temporary variables for constant isn't very useful here, the whole 
function would probably be more readable this way:

sub wrap_command {
     my ($app) = @_;
     return (['pkexec', 'env', $app]);
}

I don't understand the need for list contexte here, tough.

BTW, your indentation isn't consistent between various files.
-- 
BOFH excuse #445:

Browser's cookie is corrupted -- someone's been nibbling on it.
</PRE>













<!--endarticle-->
    <HR>
    <P><UL>
        <!--threads-->
	<LI>Previous message: <A HREF="019803.html">[Mageia-dev] Back to our weekly meetings
</A></li>
	<LI>Next message: <A HREF="019810.html">[Mageia-dev] [soft-commits] [6416] Initial commit of Admin	Panel.
</A></li>
         <LI> <B>Messages sorted by:</B> 
              <a href="date.html#19802">[ date ]</a>
              <a href="thread.html#19802">[ thread ]</a>
              <a href="subject.html#19802">[ subject ]</a>
              <a href="author.html#19802">[ author ]</a>
         </LI>
       </UL>

<hr>
<a href="https://www.mageia.org/mailman/listinfo/mageia-dev">More information about the Mageia-dev
mailing list</a><br>
</body></html>