xref: /titanic_41/usr/src/lib/smbsrv/libmlsvc/common/mlsvc_init.c (revision bbb1277b6ec1b0daad4e3ed1a2b891d3e2ece2eb)
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 	ndr_rpc_init();
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 
76 	(void) pthread_attr_init(&tattr);
77 	(void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
78 	rc = pthread_create(&mlsvc_keepalive_thr, &tattr,
79 	    mlsvc_keepalive, 0);
80 	(void) pthread_attr_destroy(&tattr);
81 	return (rc);
82 }
83 
84 void
85 mlsvc_fini(void)
86 {
87 	smb_logon_fini();
88 	svcctl_finalize();
89 	logr_finalize();
90 	ndr_rpc_fini();
91 }
92 
93 /*ARGSUSED*/
94 static void *
95 mlsvc_keepalive(void *arg)
96 {
97 	unsigned long t;
98 
99 	for (;;) {
100 		(void) sleep(MLSVC_KEEPALIVE_INTERVAL);
101 
102 		if (smb_config_get_secmode() == SMB_SECMODE_DOMAIN)
103 			(void) srvsvc_gettime(&t);
104 	}
105 
106 	/*NOTREACHED*/
107 	return (NULL);
108 }
109