Exemple #1
0
void DormantNodeView::DetachedFromWindow() {
	D_HOOK(("DormantNodeView::DetachedFromWindow()\n"));

	// delete the lists contents
	_freeList();

	// Stop watching the MediaRoster for flavor changes
	BMediaRoster *roster = BMediaRoster::CurrentRoster();
	if (roster) {
		BMessenger messenger(this, Window());
		roster->StopWatching(messenger, B_MEDIA_FLAVORS_CHANGED);
	}
}
Exemple #2
0
int
_updateldap(
	const char *action,
	const char *host,
	const char *binddn,
	const char *passwd,
	const char *printername,
	const char *printserver,
	const char *extensions,
	const char *comment,
	const char *isdefault)

{
	ns_printer_t *printer;
	ns_bsd_addr_t *addr;
	ns_cred_t *cred;

	char *item = NULL;
	char **attrList = NULL;

	int status;

	if (printserver == NULL) {
		/* printserver not given so use host */
		printserver = host;
	}

	cred = (ns_cred_t *)malloc(sizeof (*cred));
	(void) memset(cred, '\0', sizeof (*cred));
	cred->passwd = strdup((char *)passwd);
	cred->binddn = strdup((char *)binddn);
	cred->host = strdup((char *)host);

	cred->passwdType = NS_PW_INSECURE; /* use default */
	cred->port = 0;		/* use default */
	cred->domainDN = NULL;	/* use default */

	if (strcmp(action, "delete") == 0) {
		/*
		 * Delete printer object from LDAP directory DIT
		 */

		if ((printer = (ns_printer_t *)
		    ns_printer_get_name(printername, "ldap")) == NULL) {
			return (0);
		}

		printer->attributes = NULL;
		printer->nsdata = malloc(sizeof (NS_LDAPDATA));
		if (printer->nsdata == NULL) {
			return (1);
		}
		((NS_LDAPDATA *)(printer->nsdata))->attrList = NULL;
		printer->cred = cred;
		printer->source = strdup("ldap");
		status = ns_printer_put(printer);
		free(printer->nsdata);
		(void) ns_printer_destroy(printer);

		if (status != 0) {
			return (status);
		}

		if ((printer = (ns_printer_t *)
		    ns_printer_get_name("_default", "ldap")) != NULL) {
			char *dflt = (char *)
			    ns_get_value_string("use", printer);
			if ((dflt != NULL) &&
			    (strcmp(dflt, printername) == 0)) {
				printer->attributes = NULL;
				printer->nsdata = malloc(sizeof (NS_LDAPDATA));
				if (printer->nsdata == NULL) {
					(void) ns_printer_destroy(printer);
					return (1);
				}
		((NS_LDAPDATA *)(printer->nsdata))->attrList = NULL;
				printer->cred = cred;
				printer->source = strdup("ldap");
				status = ns_printer_put(printer);
				free(printer->nsdata);
				if (status != 0) {
					(void) ns_printer_destroy(printer);
					return (status);
				}
			}

			(void) ns_printer_destroy(printer);
		}
		return (0);

	} else if (strcmp(action, "add") == 0) {
		/*
		 * Add new printer object into LDAP directory DIT
		 */

		printer = (ns_printer_t *)malloc(sizeof (*printer));
		if (printer == NULL) {
			return (1);
		}
		(void) memset(printer, 0, sizeof (*printer));
		printer->name = strdup((char *)printername);
		printer->source = strdup("ldap");

		printer->cred = cred;

		/* set BSD address in attribute list */

		if (extensions == NULL) {
			item = (char *)malloc(strlen("bsdaddr") +
						strlen(printserver) +
						strlen(printername) +
						strlen("Solaris") + 6);
		} else {
			item = (char *)malloc(strlen("bsdaddr") +
						strlen(printserver) +
						strlen(printername) +
						strlen(extensions) + 6);
		}
		if (item == NULL) {
			(void) ns_printer_destroy(printer);
			return (1);
		}

		if (extensions == NULL) {
			sprintf(item, "%s=%s,%s,%s", "bsdaddr",
				printserver, printername, "Solaris");
		} else {
			sprintf(item, "%s=%s,%s,%s", "bsdaddr",
				printserver, printername, extensions);
		}

		attrList = (char **)list_append((void**)attrList,
						(void *)item);
		if ((comment != NULL) && (strlen(comment) > 0)) {
			item = (char *)malloc(strlen("description") +
							strlen(comment) + 4);
			if (item == NULL) {
				(void) ns_printer_destroy(printer);
				return (1);
			}
			sprintf(item, "%s=%s", "description", comment);
			attrList = (char **)list_append((void**)attrList,
							(void *)item);
		}

		printer->attributes = NULL;
		printer->nsdata = malloc(sizeof (NS_LDAPDATA) + 2);
		if (printer->nsdata == NULL) {
			(void) ns_printer_destroy(printer);
			return (1);
		}
		((NS_LDAPDATA *)(printer->nsdata))->attrList = attrList;

		status = ns_printer_put(printer);
		_freeList(&attrList);
		if (status != 0) {
			free(printer->nsdata);
			(void) ns_printer_destroy(printer);
			return (status);
		}

		if (strcmp(isdefault, "true") == 0) {
			(void) free(printer->name);

			printer->name = strdup("_default");
			printer->attributes = NULL;

			attrList = NULL;
			item = (char *)malloc(strlen("use") +
						strlen(printername) + 4);
			if (item == NULL) {
				(void) ns_printer_destroy(printer);
				return (1);
			}
			sprintf(item, "%s=%s", "use", printername);
			attrList = (char **)list_append((void**)attrList,
							(void *)item);

			((NS_LDAPDATA *)(printer->nsdata))->attrList = attrList;

			status = ns_printer_put(printer);
			_freeList(&attrList);
			free(printer->nsdata);
			if (status != 0) {
				(void) ns_printer_destroy(printer);
				return (status);
			}
		}
		(void) ns_printer_destroy(printer);
		return (0);
	}

	/*
	 * Modify printer object in the LDAP directory DIT
	 */

	if ((printer = (ns_printer_t *)
	    ns_printer_get_name(printername, "ldap")) == NULL) {
		return (1);
	}
	printer->cred = cred;
	printer->source = strdup("ldap");

	if ((comment != NULL) && (strlen(comment) > 0)) {
		item = (char *)malloc(strlen("description") +
						strlen(comment) + 4);
		if (item == NULL) {
			(void) ns_printer_destroy(printer);
			return (1);
		}
		sprintf(item, "%s=%s", "description", comment);
		attrList = (char **)list_append((void**)attrList, (void *)item);
	} else {
		item = (char *)malloc(strlen("description") + 4);
		if (item == NULL) {
			(void) ns_printer_destroy(printer);
			return (1);
		}
		sprintf(item, "%s=", "description");
		attrList = (char **)list_append((void**)attrList, (void *)item);
	}

	printer->attributes = NULL;
	printer->nsdata = malloc(sizeof (NS_LDAPDATA));
	if (printer->nsdata == NULL) {
		(void) ns_printer_destroy(printer);
		return (1);
	}
	((NS_LDAPDATA *)(printer->nsdata))->attrList = attrList;

	status = ns_printer_put(printer);
	_freeList(&attrList);
	free(printer->nsdata);
	if (status != 0) {
		(void) ns_printer_destroy(printer);
		return (status);
	}

	/*
	 * Handle the default printer.
	 */
	if ((printer = (ns_printer_t *)
	    ns_printer_get_name("_default", "ldap")) != NULL) {
		char *dflt = (char *)ns_get_value_string("use", printer);

		printer->source = strdup("ldap");
		printer->cred = cred;
		if (strcmp(printername, dflt) == 0) {
			if (strcmp(isdefault, "false") == 0) {
				/*
				 * We were the default printer but not
				 * any more. So delete the default entry
				 */
				printer->attributes = NULL;
				printer->nsdata = malloc(sizeof (NS_LDAPDATA));
				if (printer->nsdata == NULL) {
					(void) ns_printer_destroy(printer);
					return (1);
				}
			((NS_LDAPDATA *)(printer->nsdata))->attrList = NULL;
				status = ns_printer_put(printer);
				free(printer->nsdata);
				if (status != 0) {
					(void) ns_printer_destroy(printer);
					return (status);
				}
			}
		} else if (strcmp(isdefault, "true") == 0) {
			/*
			 * Modify this default entry to use us.
			 */
			printer->attributes = NULL;
			printer->nsdata = malloc(sizeof (NS_LDAPDATA));
			if (printer->nsdata == NULL) {
				(void) ns_printer_destroy(printer);
				return (1);
			}
			attrList = NULL;
			item = (char *)malloc(strlen("use") +
						strlen(printername) + 4);
			if (item == NULL) {
				(void) ns_printer_destroy(printer);
				return (1);
			}
			sprintf(item, "%s=%s", "use", printername);
			attrList = (char **)list_append((void**)attrList,
							(void *)item);

			((NS_LDAPDATA *)(printer->nsdata))->attrList = attrList;

			status = ns_printer_put(printer);
			_freeList(&attrList);
			free(printer->nsdata);

			if (status != 0) {
				(void) ns_printer_destroy(printer);
				return (status);
			}
		}
	} else if (strcmp(isdefault, "true") == 0) {
		/*
		 * No default entry existed and we need one.
		 */
		printer = (ns_printer_t *)malloc(sizeof (*printer));
		(void) memset(printer, 0, sizeof (*printer));
		printer->name = strdup("_default");
		printer->source = strdup("ldap");
		printer->cred = cred;

		printer->nsdata = malloc(sizeof (NS_LDAPDATA));
		if (printer->nsdata == NULL) {
			(void) ns_printer_destroy(printer);
			return (1);
		}

		attrList = NULL;
		item = (char *)malloc(strlen("use") + strlen(printername) + 4);
		if (item == NULL) {
			(void) ns_printer_destroy(printer);
			return (1);
		}
		sprintf(item, "%s=%s", "use", printername);
		attrList = (char **)list_append((void**)attrList, (void *)item);

		((NS_LDAPDATA *)(printer->nsdata))->attrList = attrList;

		status = ns_printer_put(printer);
		_freeList(&attrList);
		free(printer->nsdata);

		if (status != 0) {
			(void) ns_printer_destroy(printer);
			return (status);
		}
	}

	(void) ns_printer_destroy(printer);
	return (0);
}