-int cac_LsaGetSidsFromNames(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, struct LsaGetSidsFromNames *op) {
- struct rpc_pipe_client *pipe_hnd = NULL;
- int result = -1;
-
- int i;
-
- /*buffers for outputs*/
- DOM_SID *sids = NULL;
- enum lsa_SidType *types = NULL;
-
- CacSidInfo *sids_out = NULL;
- char **unknown_out = NULL;
- int num_unknown = 0;
-
- int num_names;
-
- int found_idx = 0;
- int unknown_idx = 0;
-
- if(!hnd)
- return CAC_FAILURE;
-
- if(!hnd->_internal.ctx || !hnd->_internal.pipes[PI_LSARPC]) {
- hnd->status = NT_STATUS_INVALID_HANDLE;
- return CAC_FAILURE;
- }
-
- if(!mem_ctx || !op || !op->in.pol || !op->in.names) {
- hnd->status = NT_STATUS_INVALID_PARAMETER;
- return CAC_FAILURE;
- }
-
- num_names = op->in.num_names;
-
- pipe_hnd = cac_GetPipe(hnd, PI_LSARPC);
- if(!pipe_hnd) {
- hnd->status = NT_STATUS_INVALID_HANDLE;
- return CAC_FAILURE;
- }
-
-
- /*now actually lookup the names*/
- hnd->status = rpccli_lsa_lookup_names( pipe_hnd, mem_ctx, op->in.pol, num_names,
- (const char **)op->in.names, NULL, &sids, &types);
-
- if(NT_STATUS_IS_OK(hnd->status)) {
- /*this is the easy part, just make the out.sids array*/
- sids_out = TALLOC_ARRAY(mem_ctx, CacSidInfo, num_names);
- if(!sids_out) {
- errno = ENOMEM;
- hnd->status = NT_STATUS_NO_MEMORY;
- return CAC_FAILURE;
- }
-
- for(i = 0; i < num_names; i++) {
- sids_out[i].sid = sids[i];
- sids_out[i].name = talloc_strdup(mem_ctx, op->in.names[i]);
- sids_out[i].domain = NULL;
- }
-
- result = CAC_SUCCESS;
- }
- else if(NT_STATUS_V(hnd->status) == NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
- /*first find out how many couldn't be looked up*/
-
- for(i = 0; i < num_names; i++) {
- if(types[i] == SID_NAME_UNKNOWN) {
- num_unknown++;
- }
- }
-
- if( num_unknown >= num_names) {
- hnd->status = NT_STATUS_UNSUCCESSFUL;
- return CAC_FAILURE;
- }
-
- sids_out = TALLOC_ARRAY(mem_ctx, CacSidInfo, (num_names - num_unknown));
- if(!sids_out) {
- errno = ENOMEM;
- hnd->status = NT_STATUS_NO_MEMORY;
- return CAC_FAILURE;
- }
-
- unknown_out = TALLOC_ARRAY(mem_ctx, char *, num_unknown);
- if(!unknown_out) {
- errno = ENOMEM;
- hnd->status = NT_STATUS_NO_MEMORY;
- return CAC_FAILURE;
- }
-
- unknown_idx = found_idx = 0;
-
- /*now we can actually do the real work*/
- for(i = 0; i < num_names; i++) {
- if(types[i] != SID_NAME_UNKNOWN) {
- sids_out[found_idx].sid = sids[i];
- sids_out[found_idx].name = talloc_strdup(mem_ctx, op->in.names[i]);
- sids_out[found_idx].domain = NULL;
-
- found_idx++;
- }
- else { /*then this one didnt work out*/
- unknown_out[unknown_idx] = talloc_strdup(mem_ctx, op->in.names[i]);
-
- unknown_idx++;
- }
- }
-
- result = CAC_PARTIAL_SUCCESS;
- }
- else { /*then it failed for some reason*/
- return CAC_FAILURE;
- }
-
- op->out.num_found = num_names - num_unknown;
- op->out.sids = sids_out;
- op->out.unknown = unknown_out;
-
- return result;
-
+int cac_LsaGetSidsFromNames( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
+ struct LsaGetSidsFromNames *op )
+{
+ struct rpc_pipe_client *pipe_hnd = NULL;
+ int result = -1;
+
+ int i;
+
+ /*buffers for outputs */
+ DOM_SID *sids = NULL;
+ enum lsa_SidType *types = NULL;
+
+ CacSidInfo *sids_out = NULL;
+ char **unknown_out = NULL;
+ int num_unknown = 0;
+
+ int num_names;
+
+ int found_idx = 0;
+ int unknown_idx = 0;
+
+ if ( !hnd )
+ return CAC_FAILURE;
+
+ if ( !hnd->_internal.ctx || !hnd->_internal.pipes[PI_LSARPC] ) {
+ hnd->status = NT_STATUS_INVALID_HANDLE;
+ return CAC_FAILURE;
+ }
+
+ if ( !mem_ctx || !op || !op->in.pol || !op->in.names ) {
+ hnd->status = NT_STATUS_INVALID_PARAMETER;
+ return CAC_FAILURE;
+ }
+
+ num_names = op->in.num_names;
+
+ pipe_hnd = cac_GetPipe( hnd, PI_LSARPC );
+ if ( !pipe_hnd ) {
+ hnd->status = NT_STATUS_INVALID_HANDLE;
+ return CAC_FAILURE;
+ }
+
+
+ /*now actually lookup the names */
+ hnd->status =
+ rpccli_lsa_lookup_names( pipe_hnd, mem_ctx, op->in.pol,
+ num_names,
+ ( const char ** ) op->in.names, NULL,
+ &sids, &types );
+
+ if ( NT_STATUS_IS_OK( hnd->status ) ) {
+ /*this is the easy part, just make the out.sids array */
+ sids_out = TALLOC_ARRAY( mem_ctx, CacSidInfo, num_names );
+ if ( !sids_out ) {
+ errno = ENOMEM;
+ hnd->status = NT_STATUS_NO_MEMORY;
+ return CAC_FAILURE;
+ }
+
+ for ( i = 0; i < num_names; i++ ) {
+ sids_out[i].sid = sids[i];
+ sids_out[i].name =
+ talloc_strdup( mem_ctx, op->in.names[i] );
+ sids_out[i].domain = NULL;
+ }
+
+ result = CAC_SUCCESS;
+ } else if ( NT_STATUS_V( hnd->status ) ==
+ NT_STATUS_V( STATUS_SOME_UNMAPPED ) ) {
+ /*first find out how many couldn't be looked up */
+
+ for ( i = 0; i < num_names; i++ ) {
+ if ( types[i] == SID_NAME_UNKNOWN ) {
+ num_unknown++;
+ }
+ }
+
+ if ( num_unknown >= num_names ) {
+ hnd->status = NT_STATUS_UNSUCCESSFUL;
+ return CAC_FAILURE;
+ }
+
+ sids_out =
+ TALLOC_ARRAY( mem_ctx, CacSidInfo,
+ ( num_names - num_unknown ) );
+ if ( !sids_out ) {
+ errno = ENOMEM;
+ hnd->status = NT_STATUS_NO_MEMORY;
+ return CAC_FAILURE;
+ }
+
+ unknown_out = TALLOC_ARRAY( mem_ctx, char *, num_unknown );
+ if ( !unknown_out ) {
+ errno = ENOMEM;
+ hnd->status = NT_STATUS_NO_MEMORY;
+ return CAC_FAILURE;
+ }
+
+ unknown_idx = found_idx = 0;
+
+ /*now we can actually do the real work */
+ for ( i = 0; i < num_names; i++ ) {
+ if ( types[i] != SID_NAME_UNKNOWN ) {
+ sids_out[found_idx].sid = sids[i];
+ sids_out[found_idx].name =
+ talloc_strdup( mem_ctx,
+ op->in.names[i] );
+ sids_out[found_idx].domain = NULL;
+
+ found_idx++;
+ } else { /*then this one didnt work out */
+ unknown_out[unknown_idx] =
+ talloc_strdup( mem_ctx,
+ op->in.names[i] );
+
+ unknown_idx++;
+ }
+ }
+
+ result = CAC_PARTIAL_SUCCESS;
+ } else { /*then it failed for some reason */
+ return CAC_FAILURE;
+ }
+
+ op->out.num_found = num_names - num_unknown;
+ op->out.sids = sids_out;
+ op->out.unknown = unknown_out;
+
+ return result;
+