int set_policy_options(TSS_HPOLICY hPolicy, TSS_FLAG mode, char *prompt, UINT32 secret_len, BYTE *secret) { TSS_RESULT ret; BYTE *unicode_prompt; UINT32 len; ret = Tspi_Policy_SetSecret(hPolicy, mode, secret_len, secret); if (ret) { print_error(ret, gettext("Set policy secret")); return (ERR_FAIL); } if (prompt != NULL) { unicode_prompt = Trspi_Native_To_UNICODE((BYTE *)prompt, &len); ret = Tspi_SetAttribData(hPolicy, TSS_TSPATTRIB_POLICY_POPUPSTRING, NULL, len, unicode_prompt); if (ret) { print_error(ret, gettext("Set policy prompt")); return (ERR_FAIL); } } return (0); }
char *_getPasswd(const char *a_pszPrompt, int* a_iLen, BOOL a_bConfirm, BOOL a_bUseUnicode) { char *pszPrompt = (char *)a_pszPrompt; char *pszPasswd = NULL; char *pszRetPasswd = NULL; do { // Get password value from user - this is a static buffer // and should never be freed pszPasswd = getpass( pszPrompt ); if (!pszPasswd && pszRetPasswd) { shredPasswd( pszRetPasswd ); return NULL; } // If this is confirmation pass check for match if ( pszRetPasswd ) { // Matched work complete if ( strcmp( pszPasswd, pszRetPasswd ) == 0) goto out; // No match clean-up logMsg( _("Passwords didn't match\n") ); // pszPasswd will be cleaned up at out label shredPasswd( pszRetPasswd ); pszRetPasswd = NULL; goto out; } // Save this passwd for next pass and/or return val pszRetPasswd = strdup( pszPasswd ); if ( !pszRetPasswd ) goto out; pszPrompt = _("Confirm password: "); } while (a_bConfirm); out: if (pszRetPasswd) { *a_iLen = strlen(pszRetPasswd); if (a_bUseUnicode) { shredPasswd(pszRetPasswd); pszRetPasswd = (char *)Trspi_Native_To_UNICODE((BYTE *)pszPasswd, (unsigned int *)a_iLen); } } // pszPasswd is a static buffer, just clear it if ( pszPasswd ) memset( pszPasswd, 0, strlen( pszPasswd ) ); return pszRetPasswd; }
/* This function converts the machine name to a TSS_UNICODE string before * returning it, as Tspi_GetAttribData would like. We could do the conversion * in Tspi_GetAttribData, but we don't have access to the TSP context there */ TSS_RESULT obj_context_get_machine_name_attrib(TSS_HCONTEXT tspContext, UINT32 *size, BYTE **data) { struct tsp_object *obj; struct tr_context_obj *context; BYTE *utf_string; UINT32 utf_size; TSS_RESULT result; if ((obj = obj_list_get_obj(&context_list, tspContext)) == NULL) return TSPERR(TSS_E_INVALID_HANDLE); context = (struct tr_context_obj *)obj->data; if (context->machineNameLength == 0) { *data = NULL; *size = 0; } else { utf_size = context->machineNameLength; utf_string = Trspi_Native_To_UNICODE(context->machineName, &utf_size); if (utf_string == NULL) { result = TSPERR(TSS_E_INTERNAL_ERROR); goto done; } *data = calloc_tspi(obj->tspContext, utf_size); if (*data == NULL) { free(utf_string); LogError("malloc of %u bytes failed.", utf_size); result = TSPERR(TSS_E_OUTOFMEMORY); goto done; } *size = utf_size; memcpy(*data, utf_string, utf_size); free(utf_string); } result = TSS_SUCCESS; done: obj_list_put(&context_list); return result; }