⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadparm.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 5 页
字号:
{	const char *value = lp_get_parametric(lp_ctx, service, type, option);	if (value)		return lp_string(value);	return NULL;}/** * Return parametric option from a given service. Type is a part of option before ':' * Parametric option has following syntax: 'Type: option = value' * Returned value is allocated in 'lp_talloc' context */const char **lp_parm_string_list(TALLOC_CTX *mem_ctx,				 struct loadparm_context *lp_ctx,				 struct loadparm_service *service,				 const char *type,				 const char *option, const char *separator){	const char *value = lp_get_parametric(lp_ctx, service, type, option);	if (value != NULL)		return str_list_make(mem_ctx, value, separator);	return NULL;}/** * Return parametric option from a given service. Type is a part of option before ':' * Parametric option has following syntax: 'Type: option = value' */int lp_parm_int(struct loadparm_context *lp_ctx,		struct loadparm_service *service, const char *type,		const char *option, int default_v){	const char *value = lp_get_parametric(lp_ctx, service, type, option);	if (value)		return lp_int(value);	return default_v;}/** * Return parametric option from a given service. Type is a part of * option before ':'. * Parametric option has following syntax: 'Type: option = value'. */int lp_parm_bytes(struct loadparm_context *lp_ctx,		  struct loadparm_service *service, const char *type,		  const char *option, int default_v){	uint64_t bval;	const char *value = lp_get_parametric(lp_ctx, service, type, option);	if (value && conv_str_size(value, &bval)) {		if (bval <= INT_MAX) {			return (int)bval;		}	}	return default_v;}/** * Return parametric option from a given service. * Type is a part of option before ':' * Parametric option has following syntax: 'Type: option = value' */unsigned long lp_parm_ulong(struct loadparm_context *lp_ctx,			    struct loadparm_service *service, const char *type,			    const char *option, unsigned long default_v){	const char *value = lp_get_parametric(lp_ctx, service, type, option);	if (value)		return lp_ulong(value);	return default_v;}double lp_parm_double(struct loadparm_context *lp_ctx,		      struct loadparm_service *service, const char *type,		      const char *option, double default_v){	const char *value = lp_get_parametric(lp_ctx, service, type, option);	if (value != NULL)		return lp_double(value);	return default_v;}/** * Return parametric option from a given service. Type is a part of option before ':' * Parametric option has following syntax: 'Type: option = value' */bool lp_parm_bool(struct loadparm_context *lp_ctx,		  struct loadparm_service *service, const char *type,		  const char *option, bool default_v){	const char *value = lp_get_parametric(lp_ctx, service, type, option);	if (value != NULL)		return lp_bool(value);	return default_v;}/** * Initialise a service to the defaults. */static struct loadparm_service *init_service(TALLOC_CTX *mem_ctx, struct loadparm_service *sDefault){	struct loadparm_service *pservice =		talloc_zero(mem_ctx, struct loadparm_service);	copy_service(pservice, sDefault, NULL);	return pservice;}/** * Set a string value, deallocating any existing space, and allocing the space * for the string */static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src){	talloc_free(*dest);	if (src == NULL)		src = "";	*dest = talloc_strdup(mem_ctx, src);	if ((*dest) == NULL) {		DEBUG(0,("Out of memory in string_init\n"));		return false;	}	return true;}/** * Add a new service to the services array initialising it with the given * service. */struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx,				     const struct loadparm_service *pservice,				     const char *name){	int i;	struct loadparm_service tservice;	int num_to_alloc = lp_ctx->iNumServices + 1;	struct param_opt *data, *pdata;	tservice = *pservice;	/* it might already exist */	if (name) {		struct loadparm_service *service = getservicebyname(lp_ctx,								    name);		if (service != NULL) {			/* Clean all parametric options for service */			/* They will be added during parsing again */			data = service->param_opt;			while (data) {				pdata = data->next;				talloc_free(data);				data = pdata;			}			service->param_opt = NULL;			return service;		}	}	/* find an invalid one */	for (i = 0; i < lp_ctx->iNumServices; i++)		if (lp_ctx->services[i] == NULL)			break;	/* if not, then create one */	if (i == lp_ctx->iNumServices) {		struct loadparm_service **tsp;		tsp = talloc_realloc(lp_ctx, lp_ctx->services, struct loadparm_service *, num_to_alloc);		if (!tsp) {			DEBUG(0,("lp_add_service: failed to enlarge services!\n"));			return NULL;		} else {			lp_ctx->services = tsp;			lp_ctx->services[lp_ctx->iNumServices] = NULL;		}		lp_ctx->iNumServices++;	}	lp_ctx->services[i] = init_service(lp_ctx->services, lp_ctx->sDefault);	if (lp_ctx->services[i] == NULL) {		DEBUG(0,("lp_add_service: out of memory!\n"));		return NULL;	}	copy_service(lp_ctx->services[i], &tservice, NULL);	if (name != NULL)		string_set(lp_ctx->services[i], &lp_ctx->services[i]->szService, name);	return lp_ctx->services[i];}/** * Add a new home service, with the specified home directory, defaults coming * from service ifrom. */bool lp_add_home(struct loadparm_context *lp_ctx,		 const char *pszHomename,		 struct loadparm_service *default_service,		 const char *user, const char *pszHomedir){	struct loadparm_service *service;	service = lp_add_service(lp_ctx, default_service, pszHomename);	if (service == NULL)		return false;	if (!(*(default_service->szPath))	    || strequal(default_service->szPath, lp_ctx->sDefault->szPath)) {		service->szPath = talloc_strdup(service, pszHomedir);	} else {		service->szPath = string_sub_talloc(service, lp_pathname(default_service, lp_ctx->sDefault), "%H", pszHomedir); 	}	if (!(*(service->comment))) {		service->comment = talloc_asprintf(service, "Home directory of %s", user);	}	service->bAvailable = default_service->bAvailable;	service->bBrowseable = default_service->bBrowseable;	DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",		  pszHomename, user, service->szPath));	return true;}/** * Add the IPC service. */static bool lp_add_hidden(struct loadparm_context *lp_ctx, const char *name,			  const char *fstype){	struct loadparm_service *service = lp_add_service(lp_ctx, lp_ctx->sDefault, name);	if (service == NULL)		return false;	string_set(service, &service->szPath, tmpdir());	service->comment = talloc_asprintf(service, "%s Service (%s)",				fstype, lp_ctx->globals->szServerString);	string_set(service, &service->fstype, fstype);	service->iMaxConnections = -1;	service->bAvailable = true;	service->bRead_only = true;	service->bPrint_ok = false;	service->bBrowseable = false;	if (strcasecmp(fstype, "IPC") == 0) {		lp_do_service_parameter(lp_ctx, service, "ntvfs handler",					"default");	}	DEBUG(3, ("adding hidden service %s\n", name));	return true;}/** * Add a new printer service, with defaults coming from service iFrom. */bool lp_add_printer(struct loadparm_context *lp_ctx,		    const char *pszPrintername,		    struct loadparm_service *default_service){	const char *comment = "From Printcap";	struct loadparm_service *service;	service = lp_add_service(lp_ctx, default_service, pszPrintername);	if (service == NULL)		return false;	/* note that we do NOT default the availability flag to True - */	/* we take it from the default service passed. This allows all */	/* dynamic printers to be disabled by disabling the [printers] */	/* entry (if/when the 'available' keyword is implemented!).    */	/* the printer name is set to the service name. */	string_set(service, &service->szPrintername, pszPrintername);	string_set(service, &service->comment, comment);	service->bBrowseable = default_service->bBrowseable;	/* Printers cannot be read_only. */	service->bRead_only = false;	/* Printer services must be printable. */	service->bPrint_ok = true;	DEBUG(3, ("adding printer service %s\n", pszPrintername));	return true;}/** * Map a parameter's string representation to something we can use. * Returns False if the parameter string is not recognised, else TRUE. */static int map_parameter(const char *pszParmName){	int iIndex;	if (*pszParmName == '-')		return -1;	for (iIndex = 0; parm_table[iIndex].label; iIndex++)		if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)			return iIndex;	/* Warn only if it isn't parametric option */	if (strchr(pszParmName, ':') == NULL)		DEBUG(0, ("Unknown parameter encountered: \"%s\"\n", pszParmName));	/* We do return 'fail' for parametric options as well because they are	   stored in different storage	 */	return -1;}/**  return the parameter structure for a parameter*/struct parm_struct *lp_parm_struct(const char *name){	int parmnum = map_parameter(name);	if (parmnum == -1) return NULL;	return &parm_table[parmnum];}/**  return the parameter pointer for a parameter*/void *lp_parm_ptr(struct loadparm_context *lp_ctx,		  struct loadparm_service *service, struct parm_struct *parm){	if (service == NULL) {		if (parm->class == P_LOCAL)			return ((char *)lp_ctx->sDefault)+parm->offset;		else if (parm->class == P_GLOBAL)			return ((char *)lp_ctx->globals)+parm->offset;		else return NULL;	} else {		return ((char *)service) + parm->offset;	}}/** * Find a service by name. Otherwise works like get_service. */static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx, 					const char *pszServiceName){	int iService;	for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--)		if (lp_ctx->services[iService] != NULL &&		    strwicmp(lp_ctx->services[iService]->szService, pszServiceName) == 0) {			return lp_ctx->services[iService];		}	return NULL;}/** * Copy a service structure to another. * If pcopymapDest is NULL then copy all fields */static void copy_service(struct loadparm_service *pserviceDest,			 struct loadparm_service *pserviceSource,			 int *pcopymapDest){	int i;	bool bcopyall = (pcopymapDest == NULL);	struct param_opt *data, *pdata, *paramo;	bool not_added;	for (i = 0; parm_table[i].label; i++)		if (parm_table[i].offset != -1 && parm_table[i].class == P_LOCAL &&		    (bcopyall || pcopymapDest[i])) {			void *src_ptr =				((char *)pserviceSource) + parm_table[i].offset;			void *dest_ptr =				((char *)pserviceDest) + parm_table[i].offset;			switch (parm_table[i].type) {				case P_BOOL:					*(int *)dest_ptr = *(int *)src_ptr;					break;				case P_INTEGER:				case P_OCTAL:				case P_ENUM:					*(int *)dest_ptr = *(int *)src_ptr;					break;				case P_STRING:					string_set(pserviceDest,						   (char **)dest_ptr,						   *(char **)src_ptr);					break;				case P_USTRING:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -