Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: session_manager_service.h

Issue 553016: port to use centralized constants files, and add input validation (Closed)
Patch Set: address shell injection, otehr comments (per wad) Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « session_manager_main.cc ('k') | session_manager_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009-2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef LOGIN_MANAGER_SESSION_MANAGER_H_ 5 #ifndef LOGIN_MANAGER_SESSION_MANAGER_SERVICE_H_
6 #define LOGIN_MANAGER_SESSION_MANAGER_H_ 6 #define LOGIN_MANAGER_SESSION_MANAGER_SERVICE_H_
7 7
8 #include <gtest/gtest.h> 8 #include <gtest/gtest.h>
9 9
10 #include <errno.h> 10 #include <errno.h>
11 #include <glib.h> 11 #include <glib.h>
12 #include <signal.h> 12 #include <signal.h>
13 #include <unistd.h> 13 #include <unistd.h>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include <base/basictypes.h> 17 #include <base/basictypes.h>
18 #include <base/scoped_ptr.h> 18 #include <base/scoped_ptr.h>
19 #include <chromeos/dbus/abstract_dbus_service.h> 19 #include <chromeos/dbus/abstract_dbus_service.h>
20 #include <chromeos/dbus/dbus.h> 20 #include <chromeos/dbus/dbus.h>
21 #include <chromeos/dbus/service_constants.h>
21 22
22 #include "login_manager/child_job.h" 23 #include "login_manager/child_job.h"
23 #include "login_manager/constants.h" 24 #include "login_manager/system_utils.h"
24 25
25 class CommandLine; 26 class CommandLine;
26 27
27 namespace login_manager { 28 namespace login_manager {
28 namespace gobject { 29 namespace gobject {
29 struct SessionManager; 30 struct SessionManager;
30 } // namespace gobject 31 } // namespace gobject
31 32
32 class ChildJob; 33 class ChildJob;
33 34
34 // Provides a wrapper for exporting SessionManagerInterface to 35 // Provides a wrapper for exporting SessionManagerInterface to
35 // D-Bus and entering the glib run loop. 36 // D-Bus and entering the glib run loop.
36 // 37 //
37 // ::g_type_init() must be called before this class is used. 38 // ::g_type_init() must be called before this class is used.
38 class SessionManagerService : public chromeos::dbus::AbstractDbusService { 39 class SessionManagerService : public chromeos::dbus::AbstractDbusService {
39 public: 40 public:
40 // Takes ownership of |child|. 41 // Takes ownership of |child|.
41 explicit SessionManagerService(ChildJob* child); 42 explicit SessionManagerService(ChildJob* child);
42 SessionManagerService(ChildJob* child, bool exit_on_child_done);
43 virtual ~SessionManagerService(); 43 virtual ~SessionManagerService();
44 44
45 //////////////////////////////////////////////////////////////////////////// 45 ////////////////////////////////////////////////////////////////////////////
46 // Implementing chromeos::dbus::AbstractDbusService 46 // Implementing chromeos::dbus::AbstractDbusService
47 virtual bool Initialize(); 47 virtual bool Initialize();
48 virtual bool Reset(); 48 virtual bool Reset();
49 49
50 // Runs the command specified on the command line as |desired_uid_| and 50 // Runs the command specified on the command line as |desired_uid_| and
51 // watches it, restarting it whenever it exits abnormally -- UNLESS 51 // watches it, restarting it whenever it exits abnormally -- UNLESS
52 // |magic_chrome_file| exists. 52 // |magic_chrome_file| exists.
(...skipping 12 matching lines...) Expand all
65 return kSessionManagerServicePath; 65 return kSessionManagerServicePath;
66 } 66 }
67 virtual const char* service_interface() const { 67 virtual const char* service_interface() const {
68 return kSessionManagerInterface; 68 return kSessionManagerInterface;
69 } 69 }
70 virtual GObject* service_object() const { 70 virtual GObject* service_object() const {
71 return G_OBJECT(session_manager_.get()); 71 return G_OBJECT(session_manager_.get());
72 } 72 }
73 73
74 74
75 // If you want to call any of these setters, you should do so before calling
76 // any other methods on this class.
77 void set_child_pgid(pid_t pgid) { child_pgid_ = pgid; }
78 void set_systemutils(SystemUtils* utils) { system_.reset(utils); }
79 void set_exit_on_child_done(bool do_exit) { exit_on_child_done_ = do_exit; }
80
75 // Returns true if |child_job_| believes it should be run. 81 // Returns true if |child_job_| believes it should be run.
76 bool should_run_child() { return child_job_->ShouldRun(); } 82 bool should_run_child() { return child_job_->ShouldRun(); }
77 83
78 // Fork, then call child_job_->Run() in the child and set a 84 // Fork, then call child_job_->Run() in the child and set a
79 // babysitter in the parent's glib default context that calls 85 // babysitter in the parent's glib default context that calls
80 // HandleChildExit when the child is done. 86 // HandleChildExit when the child is done.
81 int RunChild(); 87 int RunChild();
82 88
83 // Tell us that, if we want, we can cause a graceful exit from g_main_loop. 89 // Tell us that, if we want, we can cause a graceful exit from g_main_loop.
84 void AllowGracefulExit(); 90 void AllowGracefulExit();
(...skipping 23 matching lines...) Expand all
108 private: 114 private:
109 // |data| is a SessionManagerService* 115 // |data| is a SessionManagerService*
110 static void HandleChildExit(GPid pid, 116 static void HandleChildExit(GPid pid,
111 gint status, 117 gint status,
112 gpointer data); 118 gpointer data);
113 119
114 // So that we can enqueue an event that will exit the main loop. 120 // So that we can enqueue an event that will exit the main loop.
115 // |data| is a SessionManagerService* 121 // |data| is a SessionManagerService*
116 static gboolean ServiceShutdown(gpointer data); 122 static gboolean ServiceShutdown(gpointer data);
117 123
124 // Perform very, very basic validation of |email_address|.
125 static bool ValidateEmail(const std::string& email_address);
126
118 // Setup any necessary signal handlers. 127 // Setup any necessary signal handlers.
119 void SetupHandlers(); 128 void SetupHandlers();
120 129
130 // Terminate all children, with increasing prejudice.
131 void CleanupChildren(int max_tries);
132
133 static const uint32 kMaxEmailSize;
134 static const char kEmailSeparator;
135 static const char kLegalCharacters[];
136
121 scoped_ptr<ChildJob> child_job_; 137 scoped_ptr<ChildJob> child_job_;
122 bool exit_on_child_done_; 138 bool exit_on_child_done_;
139 pid_t child_pgid_;
123 140
124 scoped_ptr<gobject::SessionManager> session_manager_; 141 scoped_ptr<gobject::SessionManager> session_manager_;
125 GMainLoop* main_loop_; 142 GMainLoop* main_loop_;
126 143
127 FRIEND_TEST(SessionManagerTest, BadExitTest); 144 scoped_ptr<SystemUtils> system_;
128 FRIEND_TEST(SessionManagerTest, CleanExitTest); 145
146 FRIEND_TEST(SessionManagerTest, EasyCleanupTest);
147 FRIEND_TEST(SessionManagerTest, HarderCleanupTest);
148 FRIEND_TEST(SessionManagerTest, KillCleanupTest);
149 FRIEND_TEST(SessionManagerTest, EmailAddressTest);
150 FRIEND_TEST(SessionManagerTest, EmailAddressNonAsciiTest);
151 FRIEND_TEST(SessionManagerTest, EmailAddressNoAtTest);
152 FRIEND_TEST(SessionManagerTest, EmailAddressTooMuchAtTest);
129 DISALLOW_COPY_AND_ASSIGN(SessionManagerService); 153 DISALLOW_COPY_AND_ASSIGN(SessionManagerService);
130 }; 154 };
131 } // namespace login_manager 155 } // namespace login_manager
132 156
133 #endif // LOGIN_MANAGER_SESSION_MANAGER_H_ 157 #endif // LOGIN_MANAGER_SESSION_MANAGER_SERVICE_H_
OLDNEW
« no previous file with comments | « session_manager_main.cc ('k') | session_manager_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698