xref: /titanic_52/usr/src/lib/smbsrv/libmlsvc/common/mlsvc_init.c (revision 98a55d335316c9ad7a1e0095bfa1c3d0bbd4ab09)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/errno.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/smb_door_svc.h>
35 #include <smbsrv/smb_common_door.h>
36 #include <smbsrv/libsmb.h>
37 #include <smbsrv/libmlsvc.h>
38 #include <mlsvc.h>
39 
40 static void *mlsvc_keepalive(void *);
41 
42 static pthread_t mlsvc_keepalive_thr;
43 #define	MLSVC_KEEPALIVE_INTERVAL	(10 * 60)	/* 10 minutes */
44 
45 /*
46  * All NDR RPC service initialization is invoked from here.
47  * Returns 0 upon success.  Otherwise, returns -1.
48  */
49 int
50 mlsvc_init(void)
51 {
52 	pthread_attr_t tattr;
53 	int rc;
54 
55 	smb_proc_initsem();
56 
57 	if (smb_logon_init() != NT_STATUS_SUCCESS)
58 		return (-1);
59 
60 	if ((rc = smb_dclocator_init()) != 0)
61 		return (rc);
62 
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 
75 	(void) pthread_attr_init(&tattr);
76 	(void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
77 	rc = pthread_create(&mlsvc_keepalive_thr, &tattr,
78 	    mlsvc_keepalive, 0);
79 	(void) pthread_attr_destroy(&tattr);
80 	return (rc);
81 }
82 
83 void
84 mlsvc_fini(void)
85 {
86 	smb_logon_fini();
87 	svcctl_finalize();
88 	logr_finalize();
89 }
90 
91 /*ARGSUSED*/
92 static void *
93 mlsvc_keepalive(void *arg)
94 {
95 	unsigned long t;
96 
97 	for (;;) {
98 		(void) sleep(MLSVC_KEEPALIVE_INTERVAL);
99 
100 		if (smb_config_get_secmode() == SMB_SECMODE_DOMAIN)
101 			(void) srvsvc_gettime(&t);
102 	}
103 
104 	/*NOTREACHED*/
105 	return (NULL);
106 }
107