xref: /titanic_44/usr/src/lib/smbsrv/libmlsvc/common/mlsvc_init.c (revision 01ef659d9b1ead333ef0adc346e7051f7eae7520)
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 	if (smb_logon_init() != NT_STATUS_SUCCESS)
56 		return (-1);
57 
58 	if ((rc = smb_dclocator_init()) != 0)
59 		return (rc);
60 
61 	srvsvc_initialize();
62 	wkssvc_initialize();
63 	lsarpc_initialize();
64 	netr_initialize();
65 	dssetup_initialize();
66 	samr_initialize();
67 	svcctl_initialize();
68 	winreg_initialize();
69 	logr_initialize();
70 	msgsvcsend_initialize();
71 	spoolss_initialize();
72 
73 	(void) pthread_attr_init(&tattr);
74 	(void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
75 	rc = pthread_create(&mlsvc_keepalive_thr, &tattr,
76 	    mlsvc_keepalive, 0);
77 	(void) pthread_attr_destroy(&tattr);
78 	return (rc);
79 }
80 
81 void
82 mlsvc_fini(void)
83 {
84 	smb_logon_fini();
85 }
86 
87 /*ARGSUSED*/
88 static void *
89 mlsvc_keepalive(void *arg)
90 {
91 	unsigned long t;
92 
93 	for (;;) {
94 		(void) sleep(MLSVC_KEEPALIVE_INTERVAL);
95 
96 		if (smb_config_get_secmode() == SMB_SECMODE_DOMAIN)
97 			(void) srvsvc_gettime(&t);
98 	}
99 
100 	/*NOTREACHED*/
101 	return (NULL);
102 }
103 
104 uint64_t
105 mlsvc_get_num_users(void)
106 {
107 	uint32_t n_users = 0;
108 
109 	(void) smb_kmod_get_usernum(&n_users);
110 	return ((uint64_t)n_users);
111 }
112 
113 /*
114  * The calling function must free the output parameter 'users'.
115  */
116 int
117 mlsvc_get_user_list(smb_ulist_t *ulist)
118 {
119 	return (smb_kmod_get_userlist(ulist));
120 }
121 
122 /*
123  * Downcall to the kernel that is executed upon share enable and disable.
124  */
125 int
126 mlsvc_set_share(int shrop, char *path, char *name)
127 {
128 	int rc;
129 
130 	switch (shrop) {
131 	case SMB_SHROP_ADD:
132 		rc = smb_kmod_share(path, name);
133 		break;
134 	case SMB_SHROP_DELETE:
135 		rc = smb_kmod_unshare(path, name);
136 		break;
137 	default:
138 		rc = EINVAL;
139 		break;
140 	}
141 	return (rc);
142 }
143