Ejemplo n.º 1
0
/* Read and initialize global index */
int
index_initialize(char *path)
{
    FILE *fp;
    WINDOW *w = NULL;

    if (!index_initted) {
	w = savescr();
	dialog_clear_norefresh();
	have_volumes = FALSE;
	low_volume = high_volume = 0;

	/* Got any media? */
	if (!mediaVerify()) {
	    restorescr(w);
	    return DITEM_FAILURE;
	}

	/* Does it move when you kick it? */
	if (!DEVICE_INIT(mediaDevice)) {
	    restorescr(w);
	    return DITEM_FAILURE;
	}

	dialog_clear_norefresh();
	msgNotify("Attempting to fetch %s file from selected media.", path);
	fp = DEVICE_GET(mediaDevice, path, TRUE);
	if (!fp) {
	    msgConfirm("Unable to get packages/INDEX file from selected media.\n\n"
		       "This may be because the packages collection is not available\n"
		       "on the distribution media you've chosen, most likely an FTP site\n"
		       "without the packages collection mirrored.  Please verify that\n"
		       "your media, or your path to the media, is correct and try again.");
	    DEVICE_SHUTDOWN(mediaDevice);
	    restorescr(w);
	    return DITEM_FAILURE;
	}
	dialog_clear_norefresh();
	msgNotify("Located INDEX, now reading package data from it...");
	index_init(&Top, &Plist);
	if (index_read(fp, &Top)) {
	    msgConfirm("I/O or format error on packages/INDEX file.\n"
		       "Please verify media (or path to media) and try again.");
	    fclose(fp);
	    restorescr(w);
	    return DITEM_FAILURE;
	}
	fclose(fp);
	index_sort(&Top);
	index_initted = TRUE;
	restorescr(w);
    }
    return DITEM_SUCCESS;
}
Ejemplo n.º 2
0
//!							响应加入联盟
void GameFaction::OnJoinUnion(GameUnion *pUnion)
{
	assert(NULL != pUnion);
	if(NULL == pUnion)
		return;
	m_FacBaseData.SuperiorGuid = pUnion->GetExID();

	CMessage msgNotify(MSG_S2C_UNION_Notify_Creation);
	msgNotify.Add(GetExID());
	msgNotify.Add(pUnion->GetExID());
	msgNotify.Add(pUnion->GetName());

	CMessage msgBaseData(MSG_S2C_UNION_Notify_BaseData);
	pUnion->AddBaseToMsg(&msgBaseData);

	CMessage msgOneMember(MSG_S2C_UNION_Notify_AllMemberData);
	if(pUnion->AddOneMemberToMsg(GetExID(), &msgOneMember))
		return;

	map<CGUID, tagFacMemInfo>::iterator ite = m_mapMemInfo.begin();
	for ( ; ite != m_mapMemInfo.end(); ++ite)
	{
		CPlayer *pPlayer = GetGame()->FindPlayer(ite->first);
		if(NULL != pPlayer)
		{
			pPlayer->SetUnionID(pUnion->GetExID());
			msgNotify.SendToAround(pPlayer);
			msgBaseData.SendToPlayer(pPlayer->GetExID());
			msgOneMember.SendToPlayer(pPlayer->GetExID());
		}
	}
}
Ejemplo n.º 3
0
//! 添加一个添加我为联系人的人
void LinkmanGroup::AddCompriseMePlayer(tagLinkman_DB &Linkman, const char *pOptName)
{
	m_mapAddMe[Linkman.OwnerGUID] = Linkman;
	
	//! 通知被添加玩家
	if (m_pSetup->m_NotifySetup.bMessage_AddAim)
	{
		CMessage msgNotify(MSG_S2C_LINKMAN_OTHER_HANDLE);
		msgNotify.Add(m_pSetup->m_uID);
		msgNotify.Add(pOptName);
		msgNotify.Add((LONG)eLHT_Add);
		msgNotify.SendToPlayer(m_OwnerGuid);
	}
}
Ejemplo n.º 4
0
//! 删除一个添加我为联系人的人
void LinkmanGroup::DelCompriseMePlayer(const CGUID &PlayerGuid, const char *pOptName)
{
	map<CGUID, tagLinkman_DB>::iterator ite = m_mapAddMe.find(PlayerGuid);
	if(m_mapAddMe.end() == ite) return;
	m_mapAddMe.erase(ite);

	//! 通知被删除玩家
	if (m_pSetup->m_NotifySetup.bMessage_AddAim)
	{
		CMessage msgNotify(MSG_S2C_LINKMAN_OTHER_HANDLE);
		msgNotify.Add(m_pSetup->m_uID);
		msgNotify.Add(pOptName);
		msgNotify.Add((LONG)eLHT_Del);
		msgNotify.SendToPlayer(m_OwnerGuid);
	}
}
Ejemplo n.º 5
0
//! 响应联盟解散
void GameFaction::OnDisbandUnion(void)
{
	m_FacBaseData.SuperiorGuid = NULL_GUID;

	CMessage msgNotify(MSG_S2C_UNION_Notify_Disband);
	msgNotify.Add(GetExID());

	map<CGUID, tagFacMemInfo>::iterator ite = m_mapMemInfo.begin();
	for ( ; ite != m_mapMemInfo.end(); ++ite)
	{
		CPlayer *pPlayer = GetGame()->FindPlayer(ite->first);
		if(NULL != pPlayer)
		{
			pPlayer->SetUnionID(NULL_GUID);
			msgNotify.SendToAround(pPlayer);
		}
	}
}
Ejemplo n.º 6
0
/* For a given string, call it or spit out an undefined command diagnostic */
int
dispatchCommand(char *str)
{
    int i;
    char *cp;

    if (!str || !*str) {
	msgConfirm("Null or zero-length string passed to dispatchCommand");
	return DITEM_FAILURE;
    }
    /* If it's got a newline, trim it */
    if ((cp = index(str, '\n')) != NULL)
	*cp = '\0';

    /* If it's got a `=' sign in there, assume it's a variable setting */
    if (index(str, '=')) {
	if (isDebug())
	    msgDebug("dispatch: setting variable `%s'\n", str);
	variable_set(str, 0);
	i = DITEM_SUCCESS;
    }
    else {
	/* A command might be a pathname if it's encoded in argv[0], which
	   we also support */
	if ((cp = rindex(str, '/')) != NULL)
	    str = cp + 1;
	if (isDebug())
	    msgDebug("dispatch: calling resword `%s'\n", str);
	if (!call_possible_resword(str, NULL, &i)) {
	    msgNotify("Warning: No such command ``%s''", str);
	    i = DITEM_FAILURE;
	}
	/*
	 * Allow a user to prefix a command with "noError" to cause
	 * us to ignore any errors for that one command.
	 */
	if (i != DITEM_SUCCESS && variable_get(VAR_NO_ERROR))
	    i = DITEM_SUCCESS;
	variable_unset(VAR_NO_ERROR);
    }
    return i;
}
Ejemplo n.º 7
0
int
index_extract(Device *dev, PkgNodePtr top, PkgNodePtr who, Boolean depended,
    int current_volume)
{
    int status = DITEM_SUCCESS;
    Boolean notyet = FALSE;
    PkgNodePtr tmp2;
    IndexEntryPtr id = who->data;
    WINDOW *w;

    /* 
     * Short-circuit the package dependency checks.  We're already
     * maintaining a data structure of installed packages, so if a
     * package is already installed, don't try to check to make sure
     * that all of its dependencies are installed.  At best this
     * wastes a ton of cycles and can cause minor delays between
     * package extraction.  At worst it can cause an infinite loop with
     * a certain faulty INDEX file. 
     */

    if (id->installed == 1 || (have_volumes && id->vol_checked == current_volume))
	return DITEM_SUCCESS;

    w = savescr();
    if (id && id->deps && strlen(id->deps)) {
	char t[2048 * 8], *cp, *cp2;

	SAFE_STRCPY(t, id->deps);
	cp = t;
	while (cp && DITEM_STATUS(status) == DITEM_SUCCESS) {
	    if ((cp2 = index(cp, ' ')) != NULL)
		*cp2 = '\0';
	    if ((tmp2 = index_search(top, cp, NULL)) != NULL) {
		status = index_extract(dev, top, tmp2, TRUE, current_volume);
		if (DITEM_STATUS(status) != DITEM_SUCCESS) {
		    /* package probably on a future disc volume */
		    if (status & DITEM_CONTINUE) {
			status = DITEM_SUCCESS;
			notyet = TRUE;
		    } else if (variable_get(VAR_NO_CONFIRM))
			msgNotify("Loading of dependent package %s failed", cp);
		    else
			msgConfirm("Loading of dependent package %s failed", cp);
		}
	    }
	    else if (!package_installed(cp)) {
		if (variable_get(VAR_NO_CONFIRM))
		    msgNotify("Warning: %s is a required package but was not found.", cp);
		else
		    msgConfirm("Warning: %s is a required package but was not found.", cp);
	    }
	    if (cp2)
		cp = cp2 + 1;
	    else
		cp = NULL;
	}
    }

    /*
     * If iterating through disc volumes one at a time indicate failure if
     * dependency install failed due to package being on a higher volume
     * numbered disc, but that we should continue anyway.  Note that this
     * package has already been processed for this disc volume so we don't
     * need to do it again.
     */

    if (notyet) {
    	restorescr(w);
	id->vol_checked = current_volume;
	return DITEM_FAILURE | DITEM_CONTINUE;
    }

    /*
     * Done with the deps?  Try to load the real m'coy.  If iterating
     * through a multi-volume disc set fail the install if the package
     * is on a higher numbered volume to cut down on disc switches the
     * user needs to do, but indicate caller should continue processing
     * despite error return.  Note this package was processed for the
     * current disc being checked.
     */

    if (DITEM_STATUS(status) == DITEM_SUCCESS) {
	/* Prompt user if the package is not available on the current volume. */
	if(mediaDevice->type == DEVICE_TYPE_CDROM) {
	    if (current_volume != 0 && id->volume > current_volume) {
		restorescr(w);
		id->vol_checked = current_volume;
		return DITEM_FAILURE | DITEM_CONTINUE;
	    }
	    while (id->volume != dev->volume) {
		if (!msgYesNo("This is disc #%d.  Package %s is on disc #%d\n"
			  "Would you like to switch discs now?\n", dev->volume,
			  id->name, id->volume)) {
		    DEVICE_SHUTDOWN(mediaDevice);
		    msgConfirm("Please remove disc #%d from your drive, and add disc #%d\n",
			dev->volume, id->volume);
		    DEVICE_INIT(mediaDevice);
		} else {
		    restorescr(w);
		    return DITEM_FAILURE;
		}
	    }
	}
	status = package_extract(dev, who->name, depended);
	if (DITEM_STATUS(status) == DITEM_SUCCESS)
	    id->installed = 1;
    }
    restorescr(w);
    return status;
}
Ejemplo n.º 8
0
int
msgSimpleNotify(const char *str)
{
    msgNotify("%s", str);
    return DITEM_SUCCESS;
}
Ejemplo n.º 9
0
static void
addUser(WINDOW *ds_win)
{
    char tmp[256], *msg;
    int pfd[2], ipfd[2], i, j;
    ssize_t l;
    size_t amnt;
    pid_t pid;
    /*
     * Maximal list:
     * pw user add -m -n uname -g grp -u uid -c comment -d homedir -s shell -G grplist -h 0
     */
    char *vec[21] =
    {
	"pw", "user", "add", "-m", "-n", /* ... */
    };
#define VEC_UNAME 5

    msgNotify("Adding user \"%s\"...", uname);

    pipe (pfd);
    pipe (ipfd);
    if ((pid = fork()) == 0)
    {
	/* The kiddy. */
	dup2(ipfd[0], 0);
	dup2(pfd[1], 1);
	dup2(pfd[1], 2);
	for (i = getdtablesize(); i > 2; i--)
	    close(i);

	vec[i = VEC_UNAME] = uname;
	i++;
#define ADDVEC(var, option) do { if (strlen(var) > 0) { vec[i++] = option; vec[i++] = var; } } while (0)
	ADDVEC(ugroup, "-g");
	ADDVEC(uid, "-u");
	ADDVEC(gecos, "-c");
	ADDVEC(homedir, "-d");
	ADDVEC(shell, "-s");
	ADDVEC(umemb, "-G");
	if (passwd[0]) {
	    vec[i++] = "-h";
	    vec[i++] = "0";
	}
	vec[i] = 0;

	execv("/usr/sbin/pw", vec);
	msgDebug("Cannot execv() /usr/sbin/pw.\n");
	_exit(99);
    }
    else
    {
	/* The oldie. */
	close(pfd[1]);
	close(ipfd[0]);

	if (passwd[0])
	    write(ipfd[1], passwd, strlen(passwd));
	close(ipfd[1]);
	amnt = sizeof tmp;
	i = 0;
	while((l = read(pfd[0], &tmp[i], amnt)) > 0)
	{
	    amnt -= l;
	    i += l;
	    if (amnt == 0)
	    {
		close(pfd[0]);
		break;
	    }
	}
	close(pfd[0]);
	tmp[i] = '\0';
	waitpid(pid, &i, 0);
	if (WIFSIGNALED(i))
	{
	    j = WTERMSIG(i);
	    msg = "The `pw' command exited with signal %d.\n";
	    goto sysfail;
	}
	else if((j = WEXITSTATUS(i)))
	{
	    i = 0;
	    if(strncmp(tmp, "pw: ", 4) == 0)
		i = 4;
	    tmp[sizeof tmp - 1] = '\0';	/* sanity */
	    if (j == EX_DATAERR || j == EX_NOUSER || j == EX_SOFTWARE)
		msgConfirm("The `pw' command exited with an error status.\n"
			   "Its error message was:\n\n%s",
			   &tmp[i]);
	    else
	    {
		msg = "The `pw' command exited with unexpected status %d.\n";
	sysfail:
		msgDebug(msg, j);
		msgDebug("Command stdout and stderr was:\n\n%s", tmp);
		msgConfirm(msg, j);
	    }
	}
	else if (!passwd[0])
	    msgConfirm("You will need to enter a password for this user\n"
		       "later, using the passwd(1) command from the shell.\n\n"
		       "The account for `%s' is currently still disabled.",
		       uname);
    }
#undef VEC_UNAME
#undef ADDVEC
}
Ejemplo n.º 10
0
static void
addGroup(WINDOW *ds_win)
{
    char tmp[256];
    int pfd[2], i;
    ssize_t l;
    size_t amnt;
    pid_t pid;
    char *vec[8] =
    {
	"pw", "group", "add", "-n", 0, "-g", 0, 0
    };
#define VEC_GNAME 4
#define VEC_GID 6

    msgNotify("Adding group \"%s\"...", gname);

    pipe (pfd);
    if ((pid = fork()) == 0)
    {
	/* The kiddy. */
	dup2(pfd[1], 1);
	dup2(pfd[1], 2);
	for (i = getdtablesize(); i > 2; i--)
	    close(i);

	vec[VEC_GNAME] = gname;

	if (strlen(gid) > 0)
	    vec[VEC_GID] = gid;
	else
	    vec[VEC_GID - 1] = 0;

	execv("/usr/sbin/pw", vec);
	msgDebug("Cannot execv() /usr/sbin/pw.\n");
	_exit(99);
    }
    else
    {
	/* The oldie. */
	close(pfd[1]);
	amnt = sizeof tmp;
	i = 0;
	while((l = read(pfd[0], &tmp[i], amnt)) > 0)
	{
	    amnt -= l;
	    i += l;
	    if (amnt == 0)
	    {
		close(pfd[0]);
		break;
	    }
	}
	close(pfd[0]);
	tmp[i] = '\0';
	waitpid(pid, &i, 0);
	if (WIFSIGNALED(i))
	    msgDebug("pw(8) exited with signal %d.\n", WTERMSIG(i));
	else if(WEXITSTATUS(i))
	{
	    i = 0;
	    if(strncmp(tmp, "pw: ", 4) == 0)
		i = 4;
	    tmp[sizeof tmp - 1] = '\0';	/* sanity */
	    msgConfirm("The `pw' command exited with an error status.\n"
		       "Its error message was:\n\n%s",
		       &tmp[i]);
	}
    }
#undef VEC_GNAME
#undef VEC_GID
}
Ejemplo n.º 11
0
static int
createFtpUser(void)
{
    struct passwd *tpw;
    struct group  *tgrp;
    char pwline[256];
    char *tptr;
    int gid;
    FILE *fptr;
    
    if ((gid = atoi(tconf.group)) <= 0) {
	if (!(tgrp = getgrnam(tconf.group))) {
	    /* group does not exist, create it by name */
	    
	    tptr = msgGetInput("14", "What group ID to use for group %s ?", tconf.group);
	    if (tptr && *tptr && ((gid = atoi(tptr)) > 0)) {
		if ((fptr = fopen(_PATH_GROUP,"a"))) {
		    fprintf(fptr,"%s:*:%d:%s\n",tconf.group,gid,FTP_NAME);
		    fclose(fptr);
		}
	    }
	    else
		gid = FTP_GID;
	}
	else
	    gid = tgrp->gr_gid;
    }
    else if (!getgrgid(gid)) {
	/* group does not exist, create it by number */
	
	tptr = msgGetInput("ftp", "What group name to use for gid %d ?", gid);
	if (tptr && *tptr) {
	    SAFE_STRCPY(tconf.group, tptr);
	    if ((tgrp = getgrnam(tconf.group))) {
		gid = tgrp->gr_gid;
	    }
	    else if ((fptr = fopen(_PATH_GROUP,"a"))) {
		fprintf(fptr,"%s:*:%d:%s\n",tconf.group,gid,FTP_NAME);
		fclose(fptr);
	    }
	}
    }
    
    if ((tpw = getpwnam(FTP_NAME))) {
	if (tpw->pw_uid != FTP_UID)
	    msgConfirm("FTP user already exists with a different uid.");
	
	return DITEM_SUCCESS; 	/* succeeds if already exists */
    }
    
    sprintf(pwline, "%s:*:%s:%d::0:0:%s:%s:/nonexistent\n", FTP_NAME, tconf.uid, gid, tconf.comment, tconf.homedir);
    
    fptr = fopen(_PATH_MASTERPASSWD,"a");
    if (! fptr) {
	msgConfirm("Could not open master password file.");
	return DITEM_FAILURE;
    }
    fprintf(fptr, "%s", pwline);
    fclose(fptr);
    msgNotify("Remaking password file: %s", _PATH_MASTERPASSWD);
    vsystem("pwd_mkdb -p %s", _PATH_MASTERPASSWD);
    return DITEM_SUCCESS | DITEM_RESTORE;
}