r16546: Fix bug #3865 reported by jason@ncac.gwu.edu.
[jerry/samba.git] / source / libmsrpc / libmsrpc_internal.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  MS-RPC client internal functions
4  *  Copyright (C) Chris Nicholls              2005.
5  *  
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21
22 #include "libmsrpc.h"
23 #include "libmsrpc_internal.h"
24
25 /*used to get a struct rpc_pipe_client* to be passed into rpccli* calls*/
26 struct rpc_pipe_client *cac_GetPipe(CacServerHandle *hnd, int pi_idx) {
27    SMBCSRV *srv = NULL;
28    struct rpc_pipe_client *pipe_hnd = NULL;
29
30    if(!hnd)
31       return NULL;
32
33    if(hnd->_internal.pipes[pi_idx] == False) {
34       hnd->status = NT_STATUS_INVALID_HANDLE;
35       return NULL;
36    }
37
38    srv = cac_GetServer(hnd);
39    if(!srv) {
40       hnd->status = NT_STATUS_INVALID_CONNECTION;
41       return NULL;
42    }
43
44    pipe_hnd = srv->cli.pipe_list;
45
46    while(pipe_hnd != NULL && pipe_hnd->pipe_idx != pi_idx)
47       pipe_hnd = pipe_hnd->next;
48
49    return pipe_hnd;
50 }
51
52 /*takes a string like HKEY_LOCAL_MACHINE\HARDWARE\ACPI and returns the reg_type code and then a pointer to the start of the path (HARDWARE)*/
53 int cac_ParseRegPath(char *path, uint32 *reg_type, char **key_name) {
54
55    if(!path)
56       return CAC_FAILURE;
57
58    if(strncmp(path, "HKLM", 4) == 0) {
59       *reg_type = HKEY_LOCAL_MACHINE;
60       *key_name = (path[4] == '\\') ? path + 5 : NULL;
61    }
62    else if(strncmp(path, "HKEY_LOCAL_MACHINE", 18) == 0) {
63       *reg_type = HKEY_LOCAL_MACHINE;
64       *key_name = (path[18] == '\\') ? path + 19 : NULL;
65    }
66    else if(strncmp(path, "HKCR", 4) == 0) {
67       *reg_type = HKEY_CLASSES_ROOT;
68       *key_name = (path[4] == '\\') ? path + 5 : NULL;
69    }
70    else if(strncmp(path, "HKEY_CLASSES_ROOT", 17) == 0) {
71       *reg_type = HKEY_CLASSES_ROOT;
72       *key_name = (path[17] == '\\') ? path + 18 : NULL;
73    }
74    else if(strncmp(path, "HKU", 3) == 0) {
75       *reg_type = HKEY_USERS;
76       *key_name = (path[3] == '\\') ? path + 4 : NULL;
77    }
78    else if(strncmp(path, "HKEY_USERS", 10) == 0) {
79       *reg_type = HKEY_USERS;
80       *key_name = (path[10] == '\\') ? path + 11 : NULL;
81    }
82    else if(strncmp(path, "HKPD", 4) == 0) {
83       *reg_type = HKEY_PERFORMANCE_DATA;
84       *key_name = (path[4] == '\\') ? path + 5 : NULL;
85    }
86    else if(strncmp(path, "HKEY_PERFORMANCE_DATA", 21) == 0) {
87       *reg_type = HKEY_PERFORMANCE_DATA;
88       *key_name = (path[21] == '\\') ? path + 22 : NULL;
89    }
90    else {
91       return CAC_FAILURE;
92    }
93
94    return CAC_SUCCESS;
95 }
96
97
98
99 RPC_DATA_BLOB *cac_MakeRpcDataBlob(TALLOC_CTX *mem_ctx, uint32 data_type, REG_VALUE_DATA data) {
100    RPC_DATA_BLOB *blob = NULL;
101    int i;
102    uint32 size = 0;
103    uint8 *multi = NULL;
104    uint32 multi_idx = 0;
105
106    blob = talloc(mem_ctx, RPC_DATA_BLOB);
107
108    if(!blob) {
109       errno = ENOMEM;
110       return NULL;
111    }
112
113    switch(data_type) {
114       case REG_SZ:
115          init_rpc_blob_str(blob, data.reg_sz, strlen(data.reg_sz ) + 1);
116          break;
117
118       case REG_EXPAND_SZ:
119          init_rpc_blob_str(blob, data.reg_expand_sz, strlen(data.reg_sz) + 1);
120          break;
121
122       case REG_BINARY:
123          init_rpc_blob_bytes(blob, data.reg_binary.data, data.reg_binary.data_length);
124          break;
125
126       case REG_DWORD:
127          init_rpc_blob_uint32(blob, data.reg_dword);
128          break;
129          
130       case REG_DWORD_BE:
131          init_rpc_blob_uint32(blob, data.reg_dword_be);
132          break;
133          
134       case REG_MULTI_SZ:
135          /*need to find the size*/
136          for(i = 0; i < data.reg_multi_sz.num_strings; i++) {
137             size += strlen(data.reg_multi_sz.strings[i]) + 1;
138          }
139
140          /**need a whole bunch of unicode strings in a row (seperated by null characters), with an extra null-character on the end*/
141
142          multi = TALLOC_ZERO_ARRAY(mem_ctx, uint8, (size + 1)*2); /*size +1 for the extra null character*/
143          if(!multi) {
144             errno = ENOMEM;
145             break;
146          }
147          
148          /*do it using rpcstr_push()*/
149          multi_idx = 0;
150          for(i = 0; i < data.reg_multi_sz.num_strings; i++) {
151             size_t len = strlen(data.reg_multi_sz.strings[i]) + 1;
152
153             rpcstr_push((multi + multi_idx), data.reg_multi_sz.strings[i], len * 2, STR_TERMINATE);
154
155             /* x2 becuase it is a uint8 buffer*/
156             multi_idx += len * 2;
157          }
158             
159          /*now initialize the buffer as binary data*/
160          init_rpc_blob_bytes(blob, multi, (size + 1)*2);
161
162          break;
163
164       default:
165          TALLOC_FREE(blob);
166          blob = NULL;
167          return NULL;
168    }
169
170    if(!(blob->buffer)) {
171       TALLOC_FREE(blob);
172       return NULL;
173    }
174
175    return blob;
176 }
177
178 /*turns a string in a uint16 array to a char array*/
179 char *cac_unistr_to_str(TALLOC_CTX *mem_ctx, uint16 *src, int num_bytes) {
180    char *buf;
181    
182    int i = 0;
183
184    uint32 str_len = 0;
185    
186    /*don't allocate more space than we need*/
187    while( (str_len) < num_bytes/2 && src[str_len] != 0x0000)
188       str_len++;
189
190    /*need room for a '\0'*/
191    str_len++;
192
193    buf = talloc_array(mem_ctx, char, str_len);
194    if(!buf) {
195       return NULL;
196    }
197
198    for(i = 0; i < num_bytes/2; i++) {
199       buf[i] = ((char *)src)[2*i];
200    }
201
202    buf[str_len - 1] = '\0';
203
204    return buf;
205 }
206
207 REG_VALUE_DATA *cac_MakeRegValueData(TALLOC_CTX *mem_ctx, uint32 data_type, REGVAL_BUFFER buf) {
208    REG_VALUE_DATA *data;
209
210    uint32 i;
211
212    /*all of the following used for MULTI_SZ data*/
213    uint32 size       = 0;
214    uint32 len        = 0;
215    uint32 multi_idx  = 0;
216    uint32 num_strings= 0;
217    char **strings    = NULL;
218
219    data = talloc(mem_ctx, REG_VALUE_DATA);
220    if(!data) {
221       errno = ENOMEM;
222       return NULL;
223    }
224
225    switch (data_type) {
226       case REG_SZ:
227          data->reg_sz = cac_unistr_to_str(mem_ctx, buf.buffer, buf.buf_len);
228          if(!data->reg_sz) {
229             TALLOC_FREE(data);
230             errno = ENOMEM;
231             data = NULL;
232          }
233             
234          break;
235
236       case REG_EXPAND_SZ:
237          data->reg_expand_sz = cac_unistr_to_str(mem_ctx, buf.buffer, buf.buf_len);
238
239          if(!data->reg_expand_sz) {
240             TALLOC_FREE(data);
241             errno = ENOMEM;
242             data = NULL;
243          }
244             
245          break;
246
247       case REG_BINARY:
248          size = buf.buf_len;
249
250          data->reg_binary.data_length = size;
251
252          data->reg_binary.data = talloc_memdup(mem_ctx, buf.buffer, size);
253          if(!data->reg_binary.data) {
254             TALLOC_FREE(data);
255             errno = ENOMEM;
256             data = NULL;
257          }
258          break;
259
260       case REG_DWORD:
261          data->reg_dword = *((uint32 *)buf.buffer);
262          break;
263
264       case REG_DWORD_BE:
265          data->reg_dword_be = *((uint32 *)buf.buffer);
266          break;
267
268       case REG_MULTI_SZ:
269          size = buf.buf_len;
270
271          /*find out how many strings there are. size is # of bytes and we want to work uint16*/
272          for(i = 0; i < (size/2 - 1); i++) {
273             if(buf.buffer[i] == 0x0000)
274                num_strings++;
275
276             /*buffer is suppsed to be terminated with \0\0, but it might not be*/
277             if(buf.buffer[i] == 0x0000 && buf.buffer[i + 1] == 0x0000)
278                break;
279          }
280          
281          strings = talloc_array(mem_ctx, char *, num_strings);
282          if(!strings) {
283             errno = ENOMEM;
284             TALLOC_FREE(data);
285             break;
286          }
287
288          if(num_strings == 0) /*then our work here is done*/
289             break;
290
291          for(i = 0; i < num_strings; i++) {
292             /*find out how many characters are in this string*/
293             len = 0;
294             /*make sure we don't go past the end of the buffer and keep looping until we have a uni \0*/
295             while( multi_idx + len < size/2 && buf.buffer[multi_idx + len] != 0x0000)
296                len++;
297
298             /*stay aware of the \0\0*/
299             len++;
300
301             strings[i] = TALLOC_ZERO_ARRAY(mem_ctx, char, len);
302
303             /*pull out the unicode string*/
304             rpcstr_pull(strings[i], (buf.buffer + multi_idx) , len, -1, STR_TERMINATE);
305
306             /*keep track of where we are in the bigger array*/
307             multi_idx += len;
308          }
309
310          data->reg_multi_sz.num_strings = num_strings;
311          data->reg_multi_sz.strings     = strings;
312
313          break;
314
315       default:
316          TALLOC_FREE(data);
317          data = NULL;
318    }
319
320    return data;
321 }
322
323 SAM_USERINFO_CTR *cac_MakeUserInfoCtr(TALLOC_CTX *mem_ctx, CacUserInfo *info) {
324    SAM_USERINFO_CTR *ctr = NULL;
325
326    /*the flags we are 'setting'- include/passdb.h*/
327    uint32 flags = ACCT_USERNAME | ACCT_FULL_NAME | ACCT_PRIMARY_GID | ACCT_ADMIN_DESC | ACCT_DESCRIPTION |
328                      ACCT_HOME_DIR | ACCT_HOME_DRIVE | ACCT_LOGON_SCRIPT | ACCT_PROFILE | ACCT_WORKSTATIONS |
329                       ACCT_FLAGS;
330
331    NTTIME logon_time;
332    NTTIME logoff_time;
333    NTTIME kickoff_time;
334    NTTIME pass_last_set_time;
335    NTTIME pass_can_change_time;
336    NTTIME pass_must_change_time;
337
338    UNISTR2 user_name;
339    UNISTR2 full_name;
340    UNISTR2 home_dir;
341    UNISTR2 dir_drive;
342    UNISTR2 log_scr;
343    UNISTR2 prof_path;
344    UNISTR2 desc;
345    UNISTR2 wkstas;
346    UNISTR2 mung_dial;
347    UNISTR2 unk;
348
349    ctr = talloc(mem_ctx, SAM_USERINFO_CTR);
350    if(!ctr)
351       return NULL;
352
353    ZERO_STRUCTP(ctr->info.id23);
354
355    ctr->info.id21 = talloc(mem_ctx, SAM_USER_INFO_21);
356    if(!ctr->info.id21)
357       return NULL;
358
359    ctr->switch_value = 21;
360
361    ZERO_STRUCTP(ctr->info.id21);
362
363    unix_to_nt_time(&logon_time, info->logon_time);
364    unix_to_nt_time(&logoff_time, info->logoff_time);
365    unix_to_nt_time(&kickoff_time, info->kickoff_time);
366    unix_to_nt_time(&pass_last_set_time, info->pass_last_set_time);
367    unix_to_nt_time(&pass_can_change_time, info->pass_can_change_time);
368    unix_to_nt_time(&pass_must_change_time, info->pass_must_change_time);
369
370    /*initialize the strings*/
371    init_unistr2(&user_name, info->username, UNI_STR_TERMINATE);
372    init_unistr2(&full_name, info->full_name, UNI_STR_TERMINATE);
373    init_unistr2(&home_dir, info->home_dir, UNI_STR_TERMINATE);
374    init_unistr2(&dir_drive, info->home_drive, UNI_STR_TERMINATE);
375    init_unistr2(&log_scr, info->logon_script, UNI_STR_TERMINATE);
376    init_unistr2(&prof_path, info->profile_path, UNI_STR_TERMINATE);
377    init_unistr2(&desc, info->description, UNI_STR_TERMINATE);
378    init_unistr2(&wkstas, info->workstations, UNI_STR_TERMINATE);
379    init_unistr2(&unk, "\0", UNI_STR_TERMINATE);
380    init_unistr2(&mung_dial, info->dial, UNI_STR_TERMINATE);
381
382    /*manually set passmustchange*/
383    ctr->info.id21->passmustchange = (info->pass_must_change) ? 0x01 : 0x00;
384
385    init_sam_user_info21W(ctr->info.id21,
386                          &logon_time,
387                          &logoff_time,
388                          &kickoff_time,
389                          &pass_last_set_time,
390                          &pass_can_change_time,
391                          &pass_must_change_time,
392                          &user_name,
393                          &full_name,
394                          &home_dir,
395                          &dir_drive,
396                          &log_scr,
397                          &prof_path,
398                          &desc,
399                          &wkstas,
400                          &unk,
401                          &mung_dial,
402                          info->lm_password,
403                          info->nt_password,
404                          info->rid,
405                          info->group_rid,
406                          info->acb_mask,
407                          flags,
408                          168, /*logon divs*/
409                          info->logon_hours,
410                          info->bad_passwd_count,
411                          info->logon_count);
412
413    return ctr;
414    
415 }
416
417 char *talloc_unistr2_to_ascii(TALLOC_CTX *mem_ctx, UNISTR2 str) {
418    char *buf = NULL;
419
420    if(!mem_ctx)
421       return NULL;
422
423    buf = talloc_array(mem_ctx, char, (str.uni_str_len + 1));
424    if(!buf)
425       return NULL;
426
427    unistr2_to_ascii(buf, &str, str.uni_str_len + 1);
428
429    return buf;
430 }
431
432 CacUserInfo *cac_MakeUserInfo(TALLOC_CTX *mem_ctx, SAM_USERINFO_CTR *ctr) {
433    CacUserInfo *info = NULL;
434    SAM_USER_INFO_21 *id21 = NULL;
435
436    if(!ctr || ctr->switch_value != 21)
437       return NULL;
438
439    info = talloc(mem_ctx, CacUserInfo);
440    if(!info)
441       return NULL;
442
443    id21 = ctr->info.id21;
444
445    ZERO_STRUCTP(info);
446
447    info->logon_time = nt_time_to_unix(&id21->logon_time);
448    info->logoff_time = nt_time_to_unix(&id21->logoff_time);
449    info->kickoff_time = nt_time_to_unix(&id21->kickoff_time);
450    info->pass_last_set_time = nt_time_to_unix(&id21->pass_last_set_time);
451    info->pass_can_change_time = nt_time_to_unix(&id21->pass_can_change_time);
452    info->pass_must_change_time = nt_time_to_unix(&id21->pass_must_change_time);
453
454    info->username = talloc_unistr2_to_ascii(mem_ctx, id21->uni_user_name);
455    if(!info->username)
456       return NULL;
457
458    info->full_name = talloc_unistr2_to_ascii(mem_ctx, id21->uni_full_name);
459    if(!info->full_name)
460       return NULL;
461    
462    info->home_dir = talloc_unistr2_to_ascii(mem_ctx, id21->uni_home_dir);
463    if(!info->home_dir)
464       return NULL;
465    
466    info->home_drive = talloc_unistr2_to_ascii(mem_ctx, id21->uni_dir_drive);
467    if(!info->home_drive)
468       return NULL;
469
470    info->logon_script = talloc_unistr2_to_ascii(mem_ctx, id21->uni_logon_script);
471    if(!info->logon_script)
472       return NULL;
473
474    info->profile_path = talloc_unistr2_to_ascii(mem_ctx, id21->uni_profile_path);
475    if(!info->profile_path)
476       return NULL;
477    
478    info->description = talloc_unistr2_to_ascii(mem_ctx, id21->uni_acct_desc);
479    if(!info->description)
480       return NULL;
481    
482    info->workstations = talloc_unistr2_to_ascii(mem_ctx, id21->uni_workstations);
483    if(!info->workstations)
484       return NULL;
485
486    info->dial = talloc_unistr2_to_ascii(mem_ctx, id21->uni_munged_dial);
487    if(!info->dial)
488       return NULL;
489
490    info->rid = id21->user_rid;
491    info->group_rid = id21->group_rid;
492    info->acb_mask = id21->acb_info;
493    info->bad_passwd_count = id21->bad_password_count;
494    info->logon_count = id21->logon_count;
495
496    memcpy(info->nt_password, id21->nt_pwd, 8);
497    memcpy(info->lm_password, id21->lm_pwd, 8);
498    
499    info->logon_hours = talloc_memdup(mem_ctx, &(id21->logon_hrs), sizeof(LOGON_HRS));
500    if(!info->logon_hours)
501       return NULL;
502
503    info->pass_must_change = (id21->passmustchange) ? True : False;
504
505    return info;
506 }
507
508 CacGroupInfo *cac_MakeGroupInfo(TALLOC_CTX *mem_ctx, GROUP_INFO_CTR *ctr) {
509    CacGroupInfo *info = NULL;
510
511    if(!mem_ctx || !ctr || ctr->switch_value1 != 1)
512       return NULL;
513
514    info = talloc(mem_ctx, CacGroupInfo);
515    if(!info)
516       return NULL;
517
518    info->name = talloc_unistr2_to_ascii(mem_ctx, ctr->group.info1.uni_acct_name);
519    if(!info->name)
520       return NULL;
521
522    info->description = talloc_unistr2_to_ascii(mem_ctx, ctr->group.info1.uni_acct_desc);
523    if(!info->description)
524       return NULL;
525
526    info->num_members = ctr->group.info1.num_members;
527
528    return info;
529 }
530
531 GROUP_INFO_CTR *cac_MakeGroupInfoCtr(TALLOC_CTX *mem_ctx, CacGroupInfo *info) {
532    GROUP_INFO_CTR *ctr = NULL;
533
534    if(!mem_ctx || !info)
535       return NULL;
536
537    ctr = talloc(mem_ctx, GROUP_INFO_CTR);
538    if(!ctr)
539       return NULL;
540
541    ctr->switch_value1 = 1;
542
543    init_samr_group_info1(&(ctr->group.info1), info->name, info->description, info->num_members);
544
545    return ctr;
546 }
547
548 CacAliasInfo *cac_MakeAliasInfo(TALLOC_CTX *mem_ctx, ALIAS_INFO_CTR ctr) {
549    CacGroupInfo *info = NULL;
550
551    if(!mem_ctx || ctr.level != 1)
552       return NULL;
553
554    info = talloc(mem_ctx, CacAliasInfo);
555    if(!info)
556       return NULL;
557
558    info->name = talloc_unistr2_to_ascii(mem_ctx, *(ctr.alias.info1.name.string));
559    if(!info->name)
560       return NULL;
561
562    info->description = talloc_unistr2_to_ascii(mem_ctx, *(ctr.alias.info1.description.string));
563    if(!info->name)
564       return NULL;
565
566    info->num_members = ctr.alias.info1.num_member;
567
568    return info;
569 }
570
571 ALIAS_INFO_CTR *cac_MakeAliasInfoCtr(TALLOC_CTX *mem_ctx, CacAliasInfo *info) {
572    ALIAS_INFO_CTR *ctr = NULL;
573
574    if(!mem_ctx || !info)
575       return NULL;
576
577    ctr = talloc(mem_ctx, ALIAS_INFO_CTR);
578    if(!ctr)
579       return NULL;
580
581    ctr->level = 1;
582
583    init_samr_alias_info1(&(ctr->alias.info1), info->name, info->num_members, info->description);
584
585    return ctr;
586 }
587
588 CacDomainInfo *cac_MakeDomainInfo(TALLOC_CTX *mem_ctx, SAM_UNK_INFO_1 *info1, SAM_UNK_INFO_2 *info2, SAM_UNK_INFO_12 *info12) {
589    CacDomainInfo *info = NULL;
590
591    if(!mem_ctx || !info1 || !info2 || !info12)
592       return NULL;
593
594    info = talloc(mem_ctx, CacDomainInfo);
595    if(!info)
596       return NULL;
597
598    info->min_pass_length = info1->min_length_password;
599    info->pass_history    = info1->password_history;
600
601    cac_InitCacTime(&(info->expire), info1->expire);
602    cac_InitCacTime(&(info->min_pass_age), info1->min_passwordage);
603
604    info->server_role       = info2->server_role;
605    info->num_users         = info2->num_domain_usrs;
606    info->num_domain_groups = info2->num_domain_grps;
607    info->num_local_groups  = info2->num_local_grps;
608
609    /*if these have been ZERO'd out we need to know. uni_str_len will be 0*/
610    if(info2->uni_comment.uni_str_len == 0) {
611       info->comment = talloc_strdup(mem_ctx, "\0");
612    }
613    else {
614       info->comment = talloc_unistr2_to_ascii(mem_ctx, info2->uni_comment);
615    }
616
617    if(info2->uni_domain.uni_str_len == 0) {
618       info->domain_name = talloc_strdup(mem_ctx, "\0");
619    }
620    else {
621       info->domain_name = talloc_unistr2_to_ascii(mem_ctx, info2->uni_domain);
622    }
623
624    if(info2->uni_server.uni_str_len == 0) {
625       info->server_name = talloc_strdup(mem_ctx, "\0");
626    }
627    else {
628       info->server_name = talloc_unistr2_to_ascii(mem_ctx, info2->uni_server);
629    }
630
631
632    cac_InitCacTime(&(info->lockout_duration), info12->duration);
633    cac_InitCacTime(&(info->lockout_reset), info12->reset_count);
634    info->num_bad_attempts = info12->bad_attempt_lockout;
635
636    return info;
637 }
638
639 char *cac_unistr_ascii(TALLOC_CTX *mem_ctx, UNISTR src) {
640    char *buf;
641    uint32 len;
642
643    if(!mem_ctx || !src.buffer)
644       return NULL;
645
646    len = unistrlen(src.buffer) + 1;
647
648    buf = TALLOC_ZERO_ARRAY(mem_ctx, char, len);
649    if(!buf)
650       return NULL;
651
652    rpcstr_pull(buf, src.buffer, len, -1, STR_TERMINATE);
653
654    return buf;
655 }
656
657 CacService *cac_MakeServiceArray(TALLOC_CTX *mem_ctx, ENUM_SERVICES_STATUS *svc, uint32 num_services) {
658    int i;
659    CacService *services = NULL;
660
661    if(!mem_ctx || !svc)
662       return NULL;
663
664    services = TALLOC_ZERO_ARRAY(mem_ctx, CacService, num_services);
665    if(!services)
666       return NULL;
667
668    for(i = 0; i < num_services; i++) {
669       services[i].service_name = cac_unistr_ascii(mem_ctx, svc[i].servicename);
670       services[i].display_name = cac_unistr_ascii(mem_ctx, svc[i].displayname);
671
672       if(!services[i].service_name || !services[i].display_name)
673          return NULL;
674
675       services[i].status = svc[i].status;
676    }
677
678    return services;
679 }
680
681 int cac_InitCacServiceConfig(TALLOC_CTX *mem_ctx, SERVICE_CONFIG *src, CacServiceConfig *dest) {
682    if(!src || !dest)
683       return CAC_FAILURE;
684
685    dest->exe_path = talloc_unistr2_to_ascii(mem_ctx, *src->executablepath);
686    if(!dest->exe_path)
687       return CAC_FAILURE;
688
689    dest->load_order_group = talloc_unistr2_to_ascii(mem_ctx, *src->loadordergroup);
690    if(!dest->load_order_group)
691       return CAC_FAILURE;
692
693    dest->dependencies = talloc_unistr2_to_ascii(mem_ctx, *src->dependencies);
694    if(!dest->dependencies)
695       return CAC_FAILURE;
696
697    dest->start_name = talloc_unistr2_to_ascii(mem_ctx, *src->startname);
698    if(!dest->start_name)
699       return CAC_FAILURE;
700
701    dest->display_name = talloc_unistr2_to_ascii(mem_ctx, *src->displayname);
702    if(!dest->display_name)
703       return CAC_FAILURE;
704
705    dest->type = src->service_type;
706    dest->start_type = src->start_type;
707    dest->error_control = src->error_control;
708    dest->tag_id = src->tag_id;
709
710    return CAC_SUCCESS;
711 }