function drush_policy_make_me_a_sandwich_validate

8.0.x policy.drush.inc drush_policy_make_me_a_sandwich_validate()
6.x policy.drush.inc drush_policy_make_me_a_sandwich_validate()
7.x policy.drush.inc drush_policy_make_me_a_sandwich_validate()
4.x policy.drush.inc drush_policy_make_me_a_sandwich_validate()
5.x policy.drush.inc drush_policy_make_me_a_sandwich_validate()

Implements drush_hook_COMMAND_validate().

Only sudo tells me to make a sandwich: http://xkcd.com/149/

File

examples/policy.drush.inc, line 98
Example policy commandfile. Modify as desired.

Code

function drush_policy_make_me_a_sandwich_validate() {
  if (drush_is_windows()) {
    // $name = drush_get_username();
    // TODO: implement check for elevated process using w32api
    // as sudo is not available for Windows
    // @see http://php.net/manual/en/book.w32api.php
    // @see http://social.msdn.microsoft.com/Forums/en/clr/thread/0957c58c-b30b-4972-a319-015df11b427d
  }
  else {
    $name = posix_getpwuid(posix_geteuid());
    if ($name['name'] !== 'root') {
      return drush_set_error('POLICY_MAKE_IT_YOUSELF', dt('What? Make your own sandwich.'));
    }
  }
}