main.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "runAs.h"
  19. /**
  20. * The binary would be accepting the command of following format:
  21. * cluster-controller user hostname hadoop-daemon.sh-command
  22. */
  23. int main(int argc, char **argv) {
  24. int errorcode;
  25. char *user;
  26. char *hostname;
  27. char *command;
  28. struct passwd user_detail;
  29. int i = 1;
  30. /*
  31. * Minimum number of arguments required for the binary to perform.
  32. */
  33. if (argc < 4) {
  34. fprintf(stderr, "Invalid number of arguments passed to the binary\n");
  35. return INVALID_ARGUMENT_NUMER;
  36. }
  37. user = argv[1];
  38. if (user == NULL) {
  39. fprintf(stderr, "Invalid user name\n");
  40. return INVALID_USER_NAME;
  41. }
  42. if (getuserdetail(user, &user_detail) != 0) {
  43. fprintf(stderr, "Invalid user name\n");
  44. return INVALID_USER_NAME;
  45. }
  46. if (user_detail.pw_gid == 0 || user_detail.pw_uid == 0) {
  47. fprintf(stderr, "Cannot run tasks as super user\n");
  48. return SUPER_USER_NOT_ALLOWED_TO_RUN_COMMANDS;
  49. }
  50. hostname = argv[2];
  51. command = argv[3];
  52. return process_controller_command(user, hostname, command);
  53. }