xref: /illumos-gate/usr/src/lib/smbsrv/libmlsvc/common/mlsvc_init.c (revision c3e9074d863038c38dc15c3af85b017f42133816)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #include <sys/errno.h>
26 #include <sys/tzfile.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <strings.h>
30 #include <string.h>
31 #include <rpc/xdr.h>
32 #include <synch.h>
33 #include <pthread.h>
34 #include <smbsrv/libsmb.h>
35 #include <smbsrv/libmlsvc.h>
36 #include <mlsvc.h>
37 
38 static void *mlsvc_timecheck(void *);
39 
40 #define	MLSVC_TIMECHECK_INTERVAL	(10 * SECSPERMIN) /* 10 minutes */
41 
42 /*
43  * All NDR RPC service initialization is invoked from here.
44  * Returns 0 upon success.  Otherwise, returns -1.
45  */
46 int
47 mlsvc_init(void)
48 {
49 	pthread_t tid;
50 	pthread_attr_t tattr;
51 	int rc;
52 
53 	smb_proc_initsem();
54 
55 	if (smb_logon_init() != NT_STATUS_SUCCESS)
56 		return (-1);
57 
58 	if ((rc = smb_dclocator_init()) != 0)
59 		return (rc);
60 
61 	smb_quota_init();
62 	ndr_rpc_init();
63 	srvsvc_initialize();
64 	wkssvc_initialize();
65 	lsarpc_initialize();
66 	netr_initialize();
67 	dssetup_initialize();
68 	samr_initialize();
69 	svcctl_initialize();
70 	winreg_initialize();
71 	logr_initialize();
72 	msgsvcsend_initialize();
73 	spoolss_initialize();
74 	netdfs_initialize();
75 
76 	(void) pthread_attr_init(&tattr);
77 	(void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
78 	rc = pthread_create(&tid, &tattr, mlsvc_timecheck, 0);
79 	(void) pthread_attr_destroy(&tattr);
80 	return (rc);
81 }
82 
83 void
84 mlsvc_fini(void)
85 {
86 	smb_logon_fini();
87 	spoolss_finalize();
88 	svcctl_finalize();
89 	logr_finalize();
90 	netdfs_finalize();
91 	ndr_rpc_fini();
92 	smb_quota_fini();
93 }
94 
95 /*ARGSUSED*/
96 static void *
97 mlsvc_timecheck(void *arg)
98 {
99 	smb_domainex_t di;
100 
101 	for (;;) {
102 		(void) sleep(MLSVC_TIMECHECK_INTERVAL);
103 
104 		if (smb_config_get_secmode() == SMB_SECMODE_DOMAIN) {
105 			if (!smb_domain_getinfo(&di))
106 				continue;
107 
108 			ndr_srvsvc_timecheck(di.d_dc, di.d_primary.di_nbname);
109 		}
110 	}
111 
112 	/*NOTREACHED*/
113 	return (NULL);
114 }
115