xref: /titanic_41/usr/src/lib/smbsrv/libmlsvc/common/mlsvc_init.c (revision aa98ce2c4ecbce8afe8b7b253a911ab24fdded32)
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  * Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
24  */
25 
26 #include <sys/errno.h>
27 #include <sys/tzfile.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <strings.h>
31 #include <string.h>
32 #include <rpc/xdr.h>
33 #include <synch.h>
34 #include <pthread.h>
35 #include <smbsrv/libsmb.h>
36 #include <smbsrv/libmlsvc.h>
37 #include <mlsvc.h>
38 
39 static void *mlsvc_timecheck(void *);
40 
41 #define	MLSVC_TIMECHECK_INTERVAL	(10 * SECSPERMIN) /* 10 minutes */
42 
43 /*
44  * All NDR RPC service initialization is invoked from here.
45  * Returns 0 upon success.  Otherwise, returns -1.
46  */
47 int
48 mlsvc_init(void)
49 {
50 	pthread_t tid;
51 	pthread_attr_t tattr;
52 	int rc;
53 
54 	smb_proc_initsem();
55 
56 	if (smb_logon_init() != NT_STATUS_SUCCESS)
57 		return (-1);
58 
59 	if ((rc = smb_dclocator_init()) != 0)
60 		return (rc);
61 
62 	smb_quota_init();
63 	smbrdr_initialize();
64 	srvsvc_initialize();
65 	wkssvc_initialize();
66 	lsarpc_initialize();
67 	netr_initialize();
68 	dssetup_initialize();
69 	samr_initialize();
70 	svcctl_initialize();
71 	winreg_initialize();
72 	logr_initialize();
73 	msgsvcsend_initialize();
74 	spoolss_initialize();
75 	netdfs_initialize();
76 
77 	(void) pthread_attr_init(&tattr);
78 	(void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
79 	rc = pthread_create(&tid, &tattr, mlsvc_timecheck, 0);
80 	(void) pthread_attr_destroy(&tattr);
81 	return (rc);
82 }
83 
84 void
85 mlsvc_fini(void)
86 {
87 	smb_logon_fini();
88 	spoolss_finalize();
89 	svcctl_finalize();
90 	logr_finalize();
91 	netdfs_finalize();
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 			continue;
106 
107 		/* Avoid interfering with DC discovery. */
108 		if (smb_ddiscover_wait() != 0)
109 			continue;
110 
111 		if (!smb_domain_getinfo(&di))
112 			continue;
113 
114 		ndr_srvsvc_timecheck(di.d_dc, di.d_primary.di_nbname);
115 	}
116 
117 	/*NOTREACHED*/
118 	return (NULL);
119 }
120