(file) Return to cimservera.c CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Security / Cimservera

  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           //%/////////////////////////////////////////////////////////////////////////////
 34           */
 35           
 36           #include <Executor/PAMAuth.h>
 37 kumpf 1.3 #include <Executor/Socket.h>
 38 kumpf 1.3.4.1 #include <Pegasus/Common/PegasusVersion.h>
 39 kumpf 1.2     #include <stdio.h>
 40               #include <stdlib.h>
 41               #include <syslog.h>
 42               #include <unistd.h>
 43               #include <errno.h>
 44               #include <string.h>
 45               
 46               static void Exit(int status)
 47               {
 48                   syslog(LOG_DEBUG, "exit(%d)", status);
 49                   exit(status);
 50               }
 51               
 52               int main(int argc, char* argv[])
 53               {
 54                   int sock;
 55                   CimserveraRequest request;
 56 kumpf 1.3         CimserveraResponse response;
 57 kumpf 1.2     
 58                   /* Open syslog: */
 59               
 60                   openlog("cimservera", LOG_PID, LOG_AUTH);
 61                   syslog(LOG_DEBUG, "started");
 62               
 63 kumpf 1.3         /* Check arguments. */
 64 kumpf 1.2     
 65                   if (argc != 2)
 66                   {
 67                       fprintf(stderr, "Usage: %s <socket-number>\n", argv[0]);
 68                       Exit(1);
 69                   }
 70               
 71                   /* Open socket stream. */
 72               
 73                   {
 74                       char* end;
 75                       long x = strtoul(argv[1], &end, 10);
 76               
 77                       if (*end != '\0')
 78                       {
 79                           fprintf(stderr, "%s : bad socket argument: %s\n", argv[0], argv[1]);
 80                           Exit(1);
 81                       }
 82                       
 83                       sock = (int)x;
 84                   }
 85 kumpf 1.2     
 86                   /* Wait on request. */
 87               
 88 kumpf 1.3         if (RecvBlock(sock, &request, sizeof(request)) != sizeof(request))
 89 kumpf 1.2         {
 90                       close(sock);
 91                       Exit(1);
 92                   }
 93               
 94                   /* Handle request (authenticate or validateUser) */
 95               
 96                   if (strcmp(request.arg0, "authenticate") == 0)
 97                   {
 98                       int status = PAMAuthenticateInProcess(request.arg1, request.arg2);
 99               
100                       if (status != 0)
101                       {
102                           syslog(LOG_WARNING, "user \"%s\" failed to authenticate",
103                               request.arg1);
104                       }
105               
106 kumpf 1.3             response.status = status;
107               
108                       if (SendBlock(sock, &response, sizeof(response)) != sizeof(response))
109                       {
110                           close(sock);
111                           Exit(1);
112                       }
113               
114                       close(sock);
115 kumpf 1.2             Exit(status == 0 ? 0 : 1);
116                   }
117                   else if (strcmp(request.arg0, "validateUser") == 0)
118                   {
119                       int status = PAMValidateUserInProcess(request.arg1);
120               
121                       if (status != 0)
122 kumpf 1.3             {
123 kumpf 1.2                 syslog(LOG_WARNING, "failed to validate user \"%s\"", request.arg1);
124 kumpf 1.3             }
125               
126                       response.status = status;
127               
128                       if (SendBlock(sock, &response, sizeof(response)) != sizeof(response))
129                       {
130                           close(sock);
131                           Exit(1);
132                       }
133 kumpf 1.2     
134 kumpf 1.3             close(sock);
135 kumpf 1.2             Exit(status == 0 ? 0 : 1);
136                   }
137               
138 kumpf 1.3         syslog(LOG_WARNING, "invalid request");
139 kumpf 1.2         close(sock);
140 kumpf 1.3         Exit(1);
141                   return 1;
142 kumpf 1.2     }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2