(file) Return to Parent.c CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Executor

  1 kumpf 1.2 /*
  2           //%2006////////////////////////////////////////////////////////////////////////
  3           //
  4           // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  5           // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  6           // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  7           // IBM Corp.; EMC Corporation, The Open Group.
  8           // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  9           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 10           // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 11           // EMC Corporation; VERITAS Software Corporation; The Open Group.
 12           // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 13           // EMC Corporation; Symantec Corporation; The Open Group.
 14           //
 15           // Permission is hereby granted, free of charge, to any person obtaining a copy
 16           // of this software and associated documentation files (the "Software"), to
 17           // deal in the Software without restriction, including without limitation the
 18           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 19           // sell copies of the Software, and to permit persons to whom the Software is
 20           // furnished to do so, subject to the following conditions:
 21           // 
 22 kumpf 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 23           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 24           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 25           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 26           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 27           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 28           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 29           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 30           //
 31           //%/////////////////////////////////////////////////////////////////////////////
 32           */
 33           #include <sys/time.h>
 34           #include <sys/resource.h>
 35           #include <sys/types.h>
 36           #include <sys/stat.h>
 37           #include <errno.h>
 38           #include <string.h>
 39           #include <fcntl.h>
 40           #include <sys/wait.h>
 41           #include <unistd.h>
 42           #include <signal.h>
 43 kumpf 1.2 #include "Parent.h"
 44           #include "Log.h"
 45           #include "Messages.h"
 46           #include "Socket.h"
 47           #include "Fatal.h"
 48           #include "Globals.h"
 49           #include "Path.h"
 50           #include "User.h"
 51           #include "Exit.h"
 52           #include "Strlcpy.h"
 53           #include "LocalAuth.h"
 54           #include "Strlcat.h"
 55           #include "PasswordFile.h"
 56           #include "Policy.h"
 57           #include "Macro.h"
 58 kumpf 1.10 #include "FileHandle.h"
 59 kumpf 1.2  
 60            #if defined(PEGASUS_PAM_AUTHENTICATION)
 61            # include "PAMAuth.h"
 62            #endif
 63            
 64            /*
 65            **==============================================================================
 66            **
 67            ** _sigHandler()
 68            **
 69            **     Signal handler for SIGTERM.
 70            **
 71            **==============================================================================
 72            */
 73            
 74            static void _sigHandler(int signum)
 75            {
 76 kumpf 1.12     globals.signalMask |= (1UL << signum);
 77 kumpf 1.2  }
 78            
 79            /*
 80            **==============================================================================
 81            **
 82 kumpf 1.4  ** ReadExecutorRequest()
 83            **
 84            **     Read a request of the specified size from the specified socket into the
 85            **     buffer provided.
 86            **
 87            **==============================================================================
 88            */
 89            
 90            static void ReadExecutorRequest(int sock, void* buffer, size_t size)
 91            {
 92                if (RecvNonBlock(sock, buffer, size) != (ssize_t)size)
 93                {
 94                    Fatal(FL, "Failed to read request");
 95                }
 96            }
 97            
 98            /*
 99            **==============================================================================
100            **
101            ** WriteExecutorResponse()
102            **
103 kumpf 1.4  **     Write a response of the specified size from the given buffer onto the
104            **     specified socket.
105            **
106            **==============================================================================
107            */
108            
109            static void WriteExecutorResponse(int sock, const void* buffer, size_t size)
110            {
111                if (SendNonBlock(sock, buffer, size) != (ssize_t)size)
112                {
113                    Fatal(FL, "Failed to write response");
114                }
115            }
116            
117            /*
118            **==============================================================================
119            **
120 kumpf 1.2  ** HandlePingRequest()
121            **
122            **     Handle ping request.
123            **
124            **==============================================================================
125            */
126            
127            static void HandlePingRequest(int sock)
128            {
129                struct ExecutorPingResponse response;
130            
131                memset(&response, 0, sizeof(response));
132                response.magic = EXECUTOR_PING_MAGIC;
133            
134                Log(LL_TRACE, "HandlePingRequest()");
135            
136 kumpf 1.4      WriteExecutorResponse(sock, &response, sizeof(response));
137 kumpf 1.2  }
138            
139            /*
140            **==============================================================================
141            **
142            ** HandleOpenFileRequest()
143            **
144            **     Handle a request from a child to open a file.
145            **
146            **==============================================================================
147            */
148            
149            static void HandleOpenFileRequest(int sock)
150            {
151                struct ExecutorOpenFileRequest request;
152                struct ExecutorOpenFileResponse response;
153                int fd;
154            
155                memset(&response, 0, sizeof(response));
156            
157                /* Read the request message. */
158 kumpf 1.2  
159 kumpf 1.4      ReadExecutorRequest(sock, &request, sizeof(request));
160 kumpf 1.2  
161                /* Log the request. */
162            
163                Log(LL_TRACE, "HandleOpenFileRequest(): path=\"%s\", mode='%c'",
164                    request.path, request.mode);
165            
166                /* Perform the operation. */
167            
168                response.status = 0;
169                fd = -1;
170            
171                do
172                {
173                    /* Check the policy. */
174            
175 kumpf 1.6          unsigned long permissions = 0;
176            
177                    if (CheckOpenFilePolicy(request.path, request.mode, &permissions) != 0)
178 kumpf 1.2          {
179                        response.status = -1;
180                        break;
181                    }
182            
183                    /* Open file. */
184            
185                    switch (request.mode)
186                    {
187                        case 'r':
188                            fd = open(request.path, O_RDONLY);
189                            break;
190            
191                        case 'w':
192                            fd = open(
193                                request.path,
194 a.rachapudi 1.14                     O_WRONLY | O_TRUNC,
195 kumpf       1.6                      permissions);
196 kumpf       1.2                  break;
197                  
198                              case 'a':
199                              {
200                                  fd = open(
201                                      request.path,
202 a.rachapudi 1.14                     O_WRONLY | O_APPEND,
203 kumpf       1.6                      permissions);
204 kumpf       1.2                  break;
205                              }
206                          }
207 a.rachapudi 1.14         /* If the open call fails with ENOENT errno,then create the file.
208                          If the umask is set to a non default value,then the file will not 
209                          get created with permissions specified in the open system call.
210                          So set the permissions for the file explicitly using fchmod.
211                          */
212 kumpf       1.2          if (fd == -1)
213 a.rachapudi 1.14         {
214                              if (errno == ENOENT && (request.mode == 'w' || request.mode == 'a'))
215                              {
216                                  fd = open(request.path,O_CREAT | O_WRONLY,permissions);
217                                  if (fchmod(fd,permissions) != 0)
218                                  {
219                                      response.status = -1;
220                                      close(fd);
221                                  }
222                              }
223                              else
224                              {
225                                  response.status = -1;
226                              }
227                          }
228 kumpf       1.2      }
229                      while (0);
230                  
231                      /* Log failure. */
232                  
233                      if (response.status != 0)
234                      {
235                          Log(LL_WARNING, "open(\"%s\", '%c') failed",
236                              request.path, request.mode);
237                      }
238                  
239                      /* Send response. */
240                  
241 kumpf       1.4      WriteExecutorResponse(sock, &response, sizeof(response));
242 kumpf       1.2  
243                      /* Send descriptor to calling process (if any to send). */
244                  
245                      if (response.status == 0)
246                      {
247                          int descriptors[1];
248                          descriptors[0] = fd;
249                          SendDescriptorArray(sock, descriptors, 1);
250                          close(fd);
251                      }
252                  }
253                  
254                  /*
255                  **==============================================================================
256                  **
257                  ** HandleStartProviderAgentRequest()
258                  **
259                  **==============================================================================
260                  */
261                  
262                  static void HandleStartProviderAgentRequest(int sock)
263 kumpf       1.2  {
264                      int status;
265 kumpf       1.3      int uid;
266                      int gid;
267 kumpf       1.2      int pid;
268                      int to[2];
269                      int from[2];
270                      struct ExecutorStartProviderAgentResponse response;
271                      struct ExecutorStartProviderAgentRequest request;
272                  
273                      memset(&response, 0, sizeof(response));
274                  
275                      /* Read request. */
276                  
277 kumpf       1.4      ReadExecutorRequest(sock, &request, sizeof(request));
278 kumpf       1.2  
279                      /* Log request. */
280                  
281                      Log(LL_TRACE, "HandleStartProviderAgentRequest(): "
282 kumpf       1.3          "module=%s userName=%s", request.module, request.userName);
283 kumpf       1.2  
284                      /* Process request. */
285                  
286                      status = 0;
287                      pid = -1;
288                  
289                      do
290                      {
291                          /* Resolve full path of CIMPROVAGT. */
292                  
293                          const char* path;
294                  
295                          if ((path = FindMacro("cimprovagtPath")) == NULL)
296                              Fatal(FL, "Failed to locate %s program", CIMPROVAGT);
297                  
298 kumpf       1.3  #if !defined(PEGASUS_DISABLE_PROV_USERCTXT)
299                  
300                          /* Look up the user ID and group ID of the specified user. */
301                  
302                          if (GetUserInfo(request.userName, &uid, &gid) != 0)
303                          {
304                              status = -1;
305                              break;
306                          }
307                  
308                          Log(LL_TRACE, "cimprovagt user context: "
309                              "userName=%s uid=%d gid=%d", request.userName, uid, gid);
310                  
311                  #endif /* !defined(PEGASUS_DISABLE_PROV_USERCTXT) */
312                  
313 kumpf       1.2          /* Create "to-agent" pipe: */
314                  
315                          if (pipe(to) != 0)
316                          {
317                              status = -1;
318                              break;
319                          }
320                  
321                          /* Create "from-agent" pipe: */
322                  
323                          if (pipe(from) != 0)
324                          {
325                              status = -1;
326                              break;
327                          }
328                  
329                          /* Fork process: */
330                  
331                          pid = fork();
332                  
333                          if (pid < 0)
334 kumpf       1.2          {
335                              Log(LL_SEVERE, "fork failed");
336                              status = -1;
337                              break;
338                          }
339                  
340                          /* If child: */
341                  
342                          if (pid == 0)
343                          {
344 kumpf       1.11             char toPipeArg[32];
345                              char fromPipeArg[32];
346                              /* The user context is set here; no need to do it in cimprovagt. */
347                              const char* setUserContextFlag = "0";
348 kumpf       1.2  
349                              /* Close unused pipe descriptors: */
350                  
351                              close(to[1]);
352                              close(from[0]);
353                  
354 kumpf       1.10             /* Redirect terminal I/O if required and not yet daemonized. */
355                  
356                              if (globals.initCompletePipe != -1 && !globals.bindVerbose)
357                              {
358                                  RedirectTerminalIO();
359                              }
360                  
361 kumpf       1.2              /*
362                               * Close unused descriptors. Leave stdin, stdout, stderr, and the
363                               * child's pipe descriptors open.
364                               */
365                  
366 kumpf       1.10             CloseUnusedDescriptors(to[0], from[1]);
367 kumpf       1.2  
368 kumpf       1.3  #if !defined(PEGASUS_DISABLE_PROV_USERCTXT)
369                  
370 kumpf       1.10             SetUserContext(request.userName, uid, gid);
371 kumpf       1.2  
372                              Log(LL_TRACE, "starting %s on module %s as user %s",
373 kumpf       1.3                  path, request.module, request.userName);
374 kumpf       1.2  
375 kumpf       1.3  #endif /* !defined(PEGASUS_DISABLE_PROV_USERCTXT) */
376 kumpf       1.2  
377                              /* Exec the CIMPROVAGT program. */
378                  
379 kumpf       1.11             sprintf(toPipeArg, "%d", to[0]);
380                              sprintf(fromPipeArg, "%d", from[1]);
381 kumpf       1.2  
382 kumpf       1.11             Log(LL_TRACE, "execl(%s, %s, %s, %s, %s, %s, %s)\n",
383                                  path,
384                                  path,
385                                  setUserContextFlag,
386                                  toPipeArg,
387                                  fromPipeArg,
388                                  request.userName,
389                                  request.module);
390 kumpf       1.2  
391                              /* Flawfinder: ignore */
392 kumpf       1.11             execl(
393                                  path,
394                                  path,
395                                  setUserContextFlag,
396                                  toPipeArg,
397                                  fromPipeArg,
398                                  request.userName,
399                                  request.module,
400                                  (char*)0);
401                  
402                              Log(LL_SEVERE, "execl(%s, %s, %s, %s, %s, %s, %s): failed\n",
403                                  path,
404                                  path,
405                                  setUserContextFlag,
406                                  toPipeArg,
407                                  fromPipeArg,
408                                  request.userName,
409                                  request.module);
410 kumpf       1.5              _exit(1);
411 kumpf       1.2          }
412                      }
413                      while (0);
414                  
415                      /* Close unused pipe descriptors. */
416                  
417                      close(to[0]);
418                      close(from[1]);
419                  
420                      /* Send response. */
421                  
422                      response.status = status;
423                      response.pid = pid;
424                  
425 kumpf       1.4      WriteExecutorResponse(sock, &response, sizeof(response));
426 kumpf       1.2  
427                      /* Send descriptors to calling process. */
428                  
429                      if (response.status == 0)
430                      {
431                          int descriptors[2];
432                          descriptors[0] = from[0];
433                          descriptors[1] = to[1];
434                  
435                          SendDescriptorArray(sock, descriptors, 2);
436                          close(from[0]);
437                          close(to[1]);
438                      }
439                  }
440                  
441                  /*
442                  **==============================================================================
443                  **
444                  ** HandleDaemonizeExecutorRequest()
445                  **
446                  **==============================================================================
447 kumpf       1.2  */
448                  
449 kumpf       1.10 static void HandleDaemonizeExecutorRequest(int sock)
450 kumpf       1.2  {
451                      struct ExecutorDaemonizeExecutorResponse response;
452                  
453                      memset(&response, 0, sizeof(response));
454                  
455                      Log(LL_TRACE, "HandleDaemonizeExecutorRequest()");
456                  
457 kumpf       1.10     if (!globals.bindVerbose)
458 kumpf       1.2      {
459 kumpf       1.10         RedirectTerminalIO();
460 kumpf       1.2      }
461                  
462 kumpf       1.10     if (globals.initCompletePipe != -1)
463 kumpf       1.2      {
464 kumpf       1.10         ssize_t result;
465 kumpf       1.2  
466 kumpf       1.10         EXECUTOR_RESTART(write(globals.initCompletePipe, "\0", 1), result);
467                          close(globals.initCompletePipe);
468                          globals.initCompletePipe = -1;
469 kumpf       1.2      }
470                  
471                      response.status = 0;
472                  
473 kumpf       1.4      WriteExecutorResponse(sock, &response, sizeof(response));
474 kumpf       1.2  }
475                  
476                  /*
477                  **==============================================================================
478                  **
479                  ** HandleRenameFileRequest()
480                  **
481                  **==============================================================================
482                  */
483                  
484                  static void HandleRenameFileRequest(int sock)
485                  {
486                      struct ExecutorRenameFileResponse response;
487                      struct ExecutorRenameFileRequest request;
488                  
489                      memset(&response, 0, sizeof(response));
490                  
491                      /* Read the request message. */
492                  
493 kumpf       1.4      ReadExecutorRequest(sock, &request, sizeof(request));
494 kumpf       1.2  
495                      /* Log request. */
496                  
497                      Log(LL_TRACE, "HandleRenameFileRequest(): oldPath=%s newPath=%s",
498                          request.oldPath, request.newPath);
499                  
500                      /* Perform the operation: */
501                  
502                      response.status = 0;
503                  
504                      do
505                      {
506                          /* Check the policy. */
507                  
508                          if (CheckRenameFilePolicy(request.oldPath, request.newPath) != 0)
509                          {
510                              response.status = -1;
511                              break;
512                          }
513                  
514                          /* Rename the file. */
515 kumpf       1.2  
516                          if (rename(request.oldPath, request.newPath) != 0)
517                          {
518                              response.status = -1;
519                              break;
520                          }
521                      }
522                      while (0);
523                  
524                      /* Send response message. */
525                  
526 kumpf       1.4      WriteExecutorResponse(sock, &response, sizeof(response));
527 kumpf       1.2  }
528                  
529                  /*
530                  **==============================================================================
531                  **
532                  ** HandleRemoveFileRequest()
533                  **
534                  **==============================================================================
535                  */
536                  
537                  static void HandleRemoveFileRequest(int sock)
538                  {
539                      struct ExecutorRemoveFileRequest request;
540                      struct ExecutorRemoveFileResponse response;
541                  
542                      memset(&response, 0, sizeof(response));
543                  
544                      /* Read the request message. */
545                  
546 kumpf       1.4      ReadExecutorRequest(sock, &request, sizeof(request));
547 kumpf       1.2  
548                      /* Log request. */
549                  
550                      Log(LL_TRACE, "HandleRemoveFileRequest(): path=%s", request.path);
551                  
552                      response.status = 0;
553                  
554                      do
555                      {
556                          /* Check the policy. */
557                  
558                          if (CheckRemoveFilePolicy(request.path) != 0)
559                          {
560                              response.status = -1;
561                              break;
562                          }
563                  
564                          /* Remove the file. */
565                  
566                          if (unlink(request.path) != 0)
567                          {
568 kumpf       1.2              response.status = -1;
569                              Log(LL_WARNING, "unlink(%s) failed", request.path);
570                              break;
571                          }
572                      }
573                      while (0);
574                  
575                      /* Send response message. */
576                  
577 kumpf       1.4      WriteExecutorResponse(sock, &response, sizeof(response));
578 kumpf       1.2  }
579                  
580                  /*
581                  **==============================================================================
582                  **
583                  ** HandleAuthenticatePasswordRequest()
584                  **
585                  **==============================================================================
586                  */
587                  
588                  static void HandleAuthenticatePasswordRequest(int sock)
589                  {
590                      int status;
591                      struct ExecutorAuthenticatePasswordRequest request;
592                      struct ExecutorAuthenticatePasswordResponse response;
593                      int gid;
594                      int uid;
595                  
596                      memset(&response, 0, sizeof(response));
597                  
598                      /* Read the request message. */
599 kumpf       1.2  
600 kumpf       1.4      ReadExecutorRequest(sock, &request, sizeof(request));
601 kumpf       1.2  
602                      /* Log request. */
603                  
604                      Log(LL_TRACE, "HandleAuthenticatePasswordRequest(): username=%s",
605                          request.username);
606                  
607                      /* Perform the operation: */
608                  
609                      status = 0;
610                  
611                      do
612                      {
613                          if (GetUserInfo(request.username, &uid, &gid) != 0)
614                          {
615                              status = -1;
616                              break;
617                          }
618                  
619                  #if defined(PEGASUS_PAM_AUTHENTICATION)
620                  
621                          if (PAMAuthenticate(request.username, request.password) != 0)
622 kumpf       1.2          {
623                              status = -1;
624                              break;
625                          }
626                  
627                  
628                  #else /* !PEGASUS_PAM_AUTHENTICATION */
629                  
630                          {
631                              const char* path = FindMacro("passwordFilePath");
632                  
633                              if (!path)
634                              {
635                                  status = -1;
636                                  break;
637                              }
638                  
639                              if (CheckPasswordFile(
640                                  path, request.username, request.password) != 0)
641                              {
642                                  status = -1;
643 kumpf       1.2                  break;
644                              }
645                          }
646                  
647                  #endif /* !PEGASUS_PAM_AUTHENTICATION */
648                      }
649                      while (0);
650                  
651 sushma.fernandes 1.9      Log(LL_TRACE, "Basic authentication attempt: username = %s, "
652                               "successful = %s", 
653                               request.username, status == 0 ? "TRUE" : "FALSE" );
654 kumpf            1.2  
655                           /* Send response message. */
656                       
657                           response.status = status;
658                       
659 kumpf            1.4      WriteExecutorResponse(sock, &response, sizeof(response));
660 kumpf            1.2  }
661                       
662                       /*
663                       **==============================================================================
664                       **
665                       ** HandleValidateUserRequest()
666                       **
667                       **==============================================================================
668                       */
669                       
670                       static void HandleValidateUserRequest(int sock)
671                       {
672                           int status;
673                           struct ExecutorValidateUserResponse response;
674                           struct ExecutorValidateUserRequest request;
675                       
676                           memset(&response, 0, sizeof(response));
677                       
678                           /* Read the request message. */
679                       
680 kumpf            1.4      ReadExecutorRequest(sock, &request, sizeof(request));
681 kumpf            1.2  
682                           /* Validate the user. */
683                       
684                           Log(LL_TRACE,
685                               "HandleValidateUserRequest(): username=%s", request.username);
686                       
687                           /* Get the uid for the username. */
688                       
689                           status = 0;
690                       
691                       #if defined(PEGASUS_PAM_AUTHENTICATION)
692                       
693                           if (PAMValidateUser(request.username) != 0)
694                               status = -1;
695                       
696                       #else /* !PEGASUS_PAM_AUTHENTICATION */
697                       
698                           do
699                           {
700                               const char* path = FindMacro("passwordFilePath");
701                       
702 kumpf            1.2          if (!path)
703                               {
704                                   status = -1;
705                                   break;
706                               }
707                       
708                               if (CheckPasswordFile(path, request.username, NULL) != 0)
709                               {
710                                   status = -1;
711                                   break;
712                               }
713                           }
714                           while (0);
715                       
716                       #endif /* !PEGASUS_PAM_AUTHENTICATION */
717                       
718                           /* Send response message. */
719                       
720                           response.status = status;
721                       
722 kumpf            1.4      WriteExecutorResponse(sock, &response, sizeof(response));
723 kumpf            1.2  }
724                       
725                       /*
726                       **==============================================================================
727                       **
728                       ** HandleChallengeLocalRequest()
729                       **
730                       **==============================================================================
731                       */
732                       
733                       static void HandleChallengeLocalRequest(int sock)
734                       {
735                           char challenge[EXECUTOR_BUFFER_SIZE];
736                           struct ExecutorChallengeLocalRequest request;
737                           struct ExecutorChallengeLocalResponse response;
738                       
739                           memset(&response, 0, sizeof(response));
740                       
741                           /* Read the request message. */
742                       
743 kumpf            1.4      ReadExecutorRequest(sock, &request, sizeof(request));
744 kumpf            1.2  
745                           Log(LL_TRACE, "HandleChallengeLocalRequest(): user=%s", request.user);
746                       
747                           /* Perform operation. */
748                       
749 kumpf            1.4      response.status = StartLocalAuthentication(request.user, challenge);
750 kumpf            1.2  
751 kumpf            1.4      /* Send response message. */
752                       
753 sushma.fernandes 1.9      if (response.status == 0)
754 kumpf            1.4      {
755 kumpf            1.2          Strlcpy(response.challenge, challenge, sizeof(response.challenge));
756 kumpf            1.4      }
757 kumpf            1.2  
758 kumpf            1.4      WriteExecutorResponse(sock, &response, sizeof(response));
759 kumpf            1.2  }
760                       
761                       /*
762                       **==============================================================================
763                       **
764                       ** HandleAuthenticateLocalRequest()
765                       **
766                       **==============================================================================
767                       */
768                       
769                       static void HandleAuthenticateLocalRequest(int sock)
770                       {
771                           int status;
772                           struct ExecutorAuthenticateLocalRequest request;
773                           struct ExecutorAuthenticateLocalResponse response;
774                       
775                           memset(&response, 0, sizeof(response));
776                       
777                           /* Read the request message. */
778                       
779 kumpf            1.4      ReadExecutorRequest(sock, &request, sizeof(request));
780 kumpf            1.2  
781                           Log(LL_TRACE, "HandleAuthenticateLocalRequest()");
782                       
783                           /* Perform operation. */
784                       
785                           status = FinishLocalAuthentication(request.challenge, request.response);
786                       
787                           /* Send response. */
788                       
789                           response.status = status;
790                       
791 kumpf            1.4      WriteExecutorResponse(sock, &response, sizeof(response));
792 kumpf            1.2  }
793                       
794                       /*
795                       **==============================================================================
796                       **
797 kumpf            1.5  ** HandleUpdateLogLevelRequest()
798                       **
799                       **==============================================================================
800                       */
801                       
802                       static void HandleUpdateLogLevelRequest(int sock)
803                       {
804                           int status;
805                           struct ExecutorUpdateLogLevelRequest request;
806                           struct ExecutorUpdateLogLevelResponse response;
807                       
808                           memset(&response, 0, sizeof(response));
809                       
810                           /* Read the request message. */
811                       
812                           ReadExecutorRequest(sock, &request, sizeof(request));
813                       
814                           /* Log request. */
815                       
816                           Log(LL_TRACE, "HandleUpdateLogLevelRequest(): logLevel=%s",
817                               request.logLevel);
818 kumpf            1.5  
819                           /* Perform operation. */
820                       
821                           status = SetLogLevel(request.logLevel);
822                       
823                           if (status == -1)
824                               Log(LL_WARNING, "SetLogLevel(%d) failed", request.logLevel);
825                       
826                           /* Send response message. */
827                       
828                           response.status = status;
829                       
830                           WriteExecutorResponse(sock, &response, sizeof(response));
831                       }
832                       
833                       /*
834                       **==============================================================================
835                       **
836 kumpf            1.2  ** Parent()
837                       **
838                       **     The parent process (cimserver).
839                       **
840                       **==============================================================================
841                       */
842                       
843 kumpf            1.10 void Parent(int sock, int initCompletePipe, int childPid, int bindVerbose)
844 kumpf            1.2  {
845                           /* Handle Ctrl-C. */
846                       
847                           signal(SIGINT, _sigHandler);
848                       
849                           /* Catch SIGTERM, sent by kill program. */
850                       
851                           signal(SIGTERM, _sigHandler);
852                       
853                           /*
854                            * Ignore SIGPIPE, which occurs if a child with whom the executor shares
855                            * a local domain socket unexpectedly dies. In such a case, the socket
856                            * read/write functions will return an error. There are two child processes
857                            * the executor talks to over sockets: CIMSERVERA and CIMSERVERMAIN.
858                            */
859                       
860                           signal(SIGPIPE, SIG_IGN);
861                       
862                           /* Save child PID globally; it is used by Exit() function. */
863                       
864                           globals.childPid = childPid;
865 kumpf            1.2  
866 kumpf            1.10     /* Save initCompletePipe; it is used at daemonization. */
867                       
868                           globals.initCompletePipe = initCompletePipe;
869                       
870                           /* Save bindVerbose; it is used at daemonization and cimprovagt start. */
871                       
872                           globals.bindVerbose = bindVerbose;
873                       
874 kumpf            1.2      /* Prepares socket into non-blocking I/O. */
875                       
876                           SetNonBlocking(sock);
877                       
878                           /* Process client requests until client exists. */
879                       
880                           for (;;)
881                           {
882                               size_t n;
883                               struct ExecutorRequestHeader header;
884                       
885                               /* Receive request header. */
886                       
887                               n = RecvNonBlock(sock, &header, sizeof(header));
888                       
889                               if (n == 0)
890                               {
891                                   /*
892                                    * Either client closed its end of the pipe (possibly by exiting)
893                                    * or we caught a SIGTERM.
894                                    */
895 kumpf            1.2              break;
896                               }
897                       
898                               if (n != sizeof(header))
899                                   Fatal(FL, "Failed to read header");
900                       
901                               /* Dispatch request. */
902                       
903                               switch ((enum ExecutorMessageCode)header.code)
904                               {
905                                   case EXECUTOR_PING_MESSAGE:
906                                       HandlePingRequest(sock);
907                                       break;
908                       
909                                   case EXECUTOR_OPEN_FILE_MESSAGE:
910                                       HandleOpenFileRequest(sock);
911                                       break;
912                       
913                                   case EXECUTOR_START_PROVIDER_AGENT_MESSAGE:
914                                       HandleStartProviderAgentRequest(sock);
915                                       break;
916 kumpf            1.2  
917                                   case EXECUTOR_DAEMONIZE_EXECUTOR_MESSAGE:
918 kumpf            1.10                 HandleDaemonizeExecutorRequest(sock);
919 kumpf            1.2                  break;
920                       
921                                   case EXECUTOR_RENAME_FILE_MESSAGE:
922                                       HandleRenameFileRequest(sock);
923                                       break;
924                       
925                                   case EXECUTOR_REMOVE_FILE_MESSAGE:
926                                       HandleRemoveFileRequest(sock);
927                                       break;
928                       
929                                   case EXECUTOR_AUTHENTICATE_PASSWORD_MESSAGE:
930                                       HandleAuthenticatePasswordRequest(sock);
931                                       break;
932                       
933                                   case EXECUTOR_VALIDATE_USER_MESSAGE:
934                                       HandleValidateUserRequest(sock);
935                                       break;
936                       
937                                   case EXECUTOR_CHALLENGE_LOCAL_MESSAGE:
938                                       HandleChallengeLocalRequest(sock);
939                                       break;
940 kumpf            1.2  
941                                   case EXECUTOR_AUTHENTICATE_LOCAL_MESSAGE:
942                                       HandleAuthenticateLocalRequest(sock);
943                                       break;
944                       
945 kumpf            1.5              case EXECUTOR_UPDATE_LOG_LEVEL_MESSAGE:
946                                       HandleUpdateLogLevelRequest(sock);
947                                       break;
948                       
949 kumpf            1.2              default:
950                                       Fatal(FL, "Invalid request code: %d", header.code);
951                                       break;
952                               }
953                           }
954                       
955                           /* Reached due to socket EOF, SIGTERM, or SIGINT. */
956                       
957                           Exit(0);
958                       }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2