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