コード例 #1
0
ファイル: common.c プロジェクト: bzed/pkg-open-vm-tools
VGAuthError
VGAuth_Init(const char *applicationName,
            int numExtraParams,
            const VGAuthExtraParams *extraParams,
            VGAuthContext **ctx)
{
   VGAuthContext *newCtx = NULL;
   VGAuthError err = VGAUTH_E_OK;
   static gboolean firstTime = TRUE;
   int i;

   /*
    * The application name cannot be an empty string.
    */
   if ((NULL == applicationName) || ('\0' == *applicationName) ||
       (NULL == ctx)) {
      return VGAUTH_E_INVALID_ARGUMENT;
   }

   *ctx = NULL;

   /* XXX process any options */

   if (!g_utf8_validate(applicationName, -1, NULL)) {
      Warning("%s: invalid applicationName\n", __FUNCTION__);
      return VGAUTH_E_INVALID_ARGUMENT;
   }

   err = VGAuthValidateExtraParams(numExtraParams, extraParams);
   if (VGAUTH_E_OK != err) {
      return err;
   }

   newCtx = g_malloc0(sizeof(VGAuthContext));
   if (NULL == newCtx) {
      return VGAUTH_E_OUT_OF_MEMORY;
   }

   newCtx->applicationName = g_strdup(applicationName);
   newCtx->isImpersonating = FALSE;
   newCtx->impersonatedUser = NULL;

   /*
    * Only init prefs, i18n and auditing once.
    */
   if (firstTime) {
      gboolean logSuccessAudits;
      gchar *msgCatalog;

      gPrefs = Pref_Init(VGAUTH_PREF_CONFIG_FILENAME);
      logSuccessAudits = Pref_GetBool(gPrefs,
                                      VGAUTH_PREF_AUDIT_SUCCESS,
                                      VGAUTH_PREF_GROUP_NAME_AUDIT,
                                      TRUE);
      msgCatalog = Pref_GetString(gPrefs,
                                  VGAUTH_PREF_LOCALIZATION_DIR,
                                  VGAUTH_PREF_GROUP_NAME_LOCALIZATION,
                                  VGAUTH_PREF_DEFAULT_LOCALIZATION_CATALOG);

      I18n_BindTextDomain(VMW_TEXT_DOMAIN, NULL, msgCatalog);
      g_free(msgCatalog);
      Audit_Init("VGAuth", logSuccessAudits);

      firstTime = FALSE;
   }

   newCtx->numExtraParams = numExtraParams;
   newCtx->extraParams = g_malloc0(sizeof(*newCtx->extraParams) *
                                   numExtraParams);
   for (i = 0; i < numExtraParams; i++) {
      newCtx->extraParams[i].name = g_strdup(extraParams[i].name);
      newCtx->extraParams[i].value = g_strdup(extraParams[i].value);
   }

   err = VGAuth_InitConnection(newCtx);
   if (VGAUTH_E_OK != err) {
      return err;
   }

   err = VGAuthInitAuthentication(newCtx);
   if (VGAUTH_E_OK != err) {
      return err;
   }

   *ctx = newCtx;

   Log("VGAuth '%s' initialized for application '%s'.  Context created at %p\n",
       BUILD_NUMBER,
       newCtx->applicationName, newCtx);

   return err;
}
コード例 #2
0
ファイル: main.c プロジェクト: AlissonGiron/open-vm-tools
static void
ServiceStartAndRun(void)
{
   VGAuthError err;
   ServiceConnection *publicConn;

   gboolean auditSuccess = Pref_GetBool(gPrefs,
                                        VGAUTH_PREF_AUDIT_SUCCESS,
                                        VGAUTH_PREF_GROUP_NAME_AUDIT,
                                        TRUE);
   gchar *msgCatalog = Pref_GetString(gPrefs,
                                      VGAUTH_PREF_LOCALIZATION_DIR,
                                      VGAUTH_PREF_GROUP_NAME_LOCALIZATION,
                                      VGAUTH_PREF_DEFAULT_LOCALIZATION_CATALOG);

   I18n_BindTextDomain(VMW_TEXT_DOMAIN, NULL, msgCatalog);
   g_free(msgCatalog);

   Audit_Init(VGAUTH_SERVICE_NAME, auditSuccess);

   Log("INIT SERVICE\n");

#ifdef _WIN32
   if (ServiceOldInstanceExists()) {
      Warning("%s: another instance is running; exiting\n", __FUNCTION__);
      exit(-1);
   }
#endif

   err = ServiceAliasInitAliasStore();
   if (VGAUTH_E_OK != err) {
      Warning("%s: failed to init alias store; exiting\n", __FUNCTION__);
      exit(-1);
   }

   err = ServiceInitTickets();
   if (VGAUTH_E_OK != err) {
      Warning("%s: failed to init tickets; exiting\n", __FUNCTION__);
      exit(-1);
   }

   err = ServiceInitVerify();
   if (VGAUTH_E_OK != err) {
      Warning("%s: failed to init verification; exiting\n", __FUNCTION__);
      exit(-1);
   }

   err = ServiceRegisterIOFunctions(ServiceIOStartListen, ServiceStopIO);
   if (VGAUTH_E_OK != err) {
      Warning("%s: failed to register IO functions; exiting\n", __FUNCTION__);
      exit(-1);
   }


   err = ServiceCreatePublicConnection(&publicConn);
   if (VGAUTH_E_OK != err) {
      Warning("%s: failed to create public listen sock; exiting\n", __FUNCTION__);
      exit(-1);
   }

   err = ServiceIOStartListen(publicConn);
   if (VGAUTH_E_OK != err) {
      Warning("%s: failed to listen on public sock; exiting\n", __FUNCTION__);
      exit(-1);
   }

   err = ServiceIOPrepareMainLoop();
   if (VGAUTH_E_OK != err) {
      Warning("%s: failed to set up main loop; exiting\n", __FUNCTION__);
      exit(-1);
   }

   /*
    * This never comes back
    */
   Log("BEGIN SERVICE\n");
   err = ServiceIOMainLoop();
   if (VGAUTH_E_OK != err) {
      Warning("%s: failed to run main loop; exiting\n", __FUNCTION__);
      exit(-1);
   }

   // NOTREACHED
   return;
}