Exemple #1
0
int
nmh_get_credentials (char *host, char *user, int sasl, nmh_creds_t creds) {
    char *cred_style = context_find ("credentials");

    init_credentials_file ();
    creds->host = host;

    if (cred_style == NULL  ||  ! strcmp (cred_style, "legacy")) {
        if (sasl) {
            /* This is what inc.c and msgchk.c used to contain. */
            /* Only inc.c and msgchk.c do this.  smtp.c doesn't. */
            creds->user = user == NULL  ?  getusername ()  :  user;
            creds->password = getusername ();
        }
    } else if (! strncasecmp (cred_style, "file:", 5)) {
        /*
         * Determine user using the first of:
         * 1) -user switch
         * 2) matching host entry with login in a credentials file
         *    such as ~/.netrc
         * 3) interactively request from user (as long as the
         *    credentials file didn't have a "default" token)
         */
        creds->user = user;
    } else {
        admonish (NULL, "unknown credentials style %s", cred_style);
        return NOTOK;
    }

    ruserpass (host, &creds->user, &creds->password);
    return OK;
}
Exemple #2
0
void listasenaste(void) {
	int x,nummer,alla=TRUE,cnt=0,antal=MAXSENASTE;
	struct tm *ts;
	if(argument[0]=='-') {
		antal=atoi(&argument[1]);
		argument=hittaefter(argument);
	}
	if((nummer=parsenamn(argument))==-1) {
		puttekn("\r\n\nFinns ingen som heter så eller har det numret!\r\n",-1);
		return;
	} else if(nummer==-3) alla=TRUE;
	else alla=FALSE;
	puttekn("\r\n\n     Namn                            Utloggad     Tid   Läst Skr  Ul  Dl\r\n\n",-1);
	for(x=0;x<MAXSENASTE;x++) {
		if(!Servermem->senaste[x].utloggtid || (!alla && nummer!=Servermem->senaste[x].anv)) continue;
		if(!userexists(Servermem->senaste[x].anv)) continue;
		cnt++;
		ts=localtime(&Servermem->senaste[x].utloggtid);
		sprintf(outbuffer,"%-35s %02d/%02d %02d:%02d %3dmin  %4d %3d  %2d  %2d\r\n",
			getusername(Servermem->senaste[x].anv),ts->tm_mday,ts->tm_mon+1,ts->tm_hour,ts->tm_min,
			Servermem->senaste[x].tid_inloggad,Servermem->senaste[x].read,
			Servermem->senaste[x].write,Servermem->senaste[x].ul,
			Servermem->senaste[x].dl);
		if(puttekn(outbuffer,-1)) return;
		if(cnt>=antal) return;
	}
}
Exemple #3
0
void displaysay(void) {
	struct SayString *pekare,*oldpek;
	int textlen;
	char tmpchar;
	pekare=Servermem->say[nodnr];
	Servermem->say[nodnr]=NULL;
	while(pekare) {
		if(pekare->fromuser == -1) strcpy(outbuffer,"\a\r\n\nSystemmeddelande");
		else sprintf(outbuffer,"\a\r\n\n%s",getusername(pekare->fromuser));
		textlen = strlen(pekare->text);
		puttekn(outbuffer,-1);
		if((strlen(outbuffer) + textlen) < 79) {
			sprintf(outbuffer,": %s\r\n",pekare->text);
			puttekn(outbuffer,-1);
		} else {
			puttekn(":\n\r",-1);
			if(textlen <= MAXSAYTKN-1) puttekn(pekare->text,-1);
			else {
				tmpchar = pekare->text[MAXSAYTKN-1];
				pekare->text[MAXSAYTKN-1] = 0;
				puttekn(pekare->text,-1);
				pekare->text[MAXSAYTKN-1] = tmpchar;
				puttekn(&pekare->text[MAXSAYTKN-1],-1);
			}
		}
		oldpek=pekare;
		pekare=oldpek->NextSay;
		FreeMem(oldpek,sizeof(struct SayString));
	}
	eka('\n');
}
Exemple #4
0
void main () {
  
  char buf[1024];
  char *args[64];
  char pwd[128];
  
  init_banner();
  for (;;)
    {
      /*
       * Prompt for and read a command.
       */
      // user@host[pwd] : 
      printf ("%s@%s[%s]: ", getusername() , gethost(), getcwd(pwd, sizeof(pwd)) );

      if (gets (buf) == NULL)
	{
	  printf ("\n");
	  exit (0);
	}

      /*
       * Split the string into arguments.
       */
      
      parse (buf, args);

      /*
       * Execute the command.
       */
      
      execute (args);
    }
}
Exemple #5
0
long __saveds __regargs nik_update(struct XPR_UPDATE *update) {
    struct TransferFiles *tf, *tmptf;
    int equalulfiles = 0;

    if(update->xpru_updatemask & XPRU_FILENAME) {
        sprintf(outbuffer,"\r\nFör över %s\r\n",update->xpru_filename);
        conputtekn(outbuffer,-1);
        strcpy(xprfilnamn,update->xpru_filename);
        if(Servermem->action[nodnr]==UPLOAD || Servermem->action[nodnr]==DOWNLOAD) Servermem->vilkastr[nodnr] = FilePart(xprfilnamn);
    }
    if(update->xpru_updatemask & XPRU_FILESIZE) {
        sprintf(outbuffer,"Filens längd %d\r\n",update->xpru_filesize);
        conputtekn(outbuffer,-1);
        filesize=update->xpru_filesize;
    }
    if(update->xpru_updatemask & XPRU_MSG) {
        conputtekn(update->xpru_msg,-1);
        conputtekn("\r\n",-1);
    }
    if(update->xpru_updatemask & XPRU_ERRORMSG) {
        conputtekn(update->xpru_errormsg,-1);
        conputtekn("\r\n",-1);
    }
    if(update->xpru_updatemask & XPRU_DATARATE) cps=update->xpru_datarate;
    if(update->xpru_updatemask & XPRU_BYTES) {
        sprintf(outbuffer,"\rBytes: %d (%d cps)",update->xpru_bytes,update->xpru_datarate);
        conputtekn(outbuffer,-1);
        countbytes=update->xpru_bytes;
        if(countbytes == filesize && Servermem->action[nodnr]==UPLOAD) {
            tmptf = (struct TransferFiles *)tf_list.mlh_Head;
            while(tmptf)
            {
                if(!stricmp(tmptf->Filnamn,xprfilnamn))
                    equalulfiles = 1;
                tmptf = (struct TransferFiles *)tmptf->node.mln_Succ;
            }
            if(!equalulfiles)
            {
                if(!(tf=(struct TransferFiles *)AllocMem(sizeof(struct TransferFiles),MEMF_CLEAR))) {
                    puttekn("Kunde inte allokera en TransferFiles-struktur\n\r",-1);
                }
                else
                {
                    if(Servermem->cfg.logmask & LOG_RECFILE) {
                        LogEvent(USAGE_LOG, INFO, "Tog emot filen %s från %s",
                                 xprfilnamn, getusername(inloggad));
                    }
                    strcpy(tf->Filnamn,xprfilnamn);
                    tf->cps = cps;
                    AddTail((struct List *)&tf_list,(struct Node *)tf);
                    ulfiles++;
                }
            }

        }
    }
    return(0L);
}
Exemple #6
0
void
dtildepr(Char *dir)
{
    Char* user;
    if ((user = getusername(&dir)) != NULL)
	xprintf("~%-S%S", user, dir);
    else
	xprintf("%S", dir);
}
char* Client::logout(){
	string text;
	text.append("--logout--:");
	text.append(getusername());
	text.append(";");
    char * writable = new char[text.size() + 1];
    copy(text.begin(), text.end(), writable);
    writable[text.size()] = '\0';
    return writable;
}
Exemple #8
0
void initpersheader(void) {
        long tid,lappnr,length,x;
        struct tm *ts;
        struct User usr;
        char filnamn[40];
        Servermem->action[nodnr] = SKRIVER;
        Servermem->varmote[nodnr] = -1;
        memset(&brevspar,0,sizeof(struct ReadLetter));
        sprintf(brevspar.to,"%d",readhead.person);
        sprintf(brevspar.from,"%d",inloggad);
        readuser(readhead.person,&usr);
        if(usr.flaggor & LAPPBREV) {
                puttekn("\r\n\n",-1);
                lappnr=atoi(brevspar.to);
                sprintf(filnamn,"NiKom:Users/%d/%d/Lapp",lappnr/100,lappnr);
                if(!access(filnamn,0)) sendfile(filnamn);
                puttekn("\r\n",-1);
        }
        time(&tid);
        ts=localtime(&tid);
        sprintf(brevspar.date,"%2d%02d%02d %02d:%02d",ts->tm_year,ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min);
        strcpy(brevspar.systemid,"NiKom");
        sprintf(outbuffer,"\r\n\nMöte: %s\r\n",Servermem->cfg.brevnamn);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Lokalt brev,  %s\n\r",brevspar.date);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Avsändare: %s\r\n",getusername(inloggad));
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Mottagare: %s\n\r",getusername(readhead.person));
        puttekn(outbuffer,-1);
        puttekn("Ärende: ",-1);
        strcpy(brevspar.subject,readhead.arende);
        puttekn(brevspar.subject,-1);
        puttekn("\n\r",-1);
        if(Servermem->inne[nodnr].flaggor & STRECKRAD) {
                length=strlen(brevspar.subject);
                for(x=0;x<length+8;x++) outbuffer[x]='-';
                outbuffer[x]=0;
                puttekn(outbuffer,-1);
                puttekn("\r\n\n",-1);
        } else eka('\n');
}
Exemple #9
0
int sag(void) {
	int vem,x;
	char *quick;
	struct SayString *pekare,*oldpekare=NULL,*allocpekare;
	quick = strchr(argument,',');
	if(quick) *quick++ = 0;
	if((vem=parsenamn(argument))==-3) {
		puttekn("\r\n\nSkriv : Säg <användare>[,<meddelande>]\r\n\n",-1);
		return(0);
	}
	if(vem==-1) {
		puttekn("\r\n\nFinns ingen som heter så eller har det numret!\r\n\n",-1);
		return(0);
	}
	for(x=0;x<MAXNOD;x++) if(Servermem->inloggad[x]==vem) break;
	if(x==MAXNOD) {
		puttekn("\r\n\nPersonen är inte inloggad!\r\n",-1);
		return(0);
	}
	if(!quick) {
		puttekn("\r\n\nVad vill du säga?\r\n",-1);
		if(getstring(EKO,MAXSAYTKN-1,NULL)) return(1);
		if(!inmat[0]) return(0);
		if(Servermem->inloggad[x]==-1) {
			puttekn("\r\n\nTyvärr, personen har loggat ut.\r\n",-1);
			return(0);
		}
	}
	pekare=Servermem->say[x];
	if(pekare) sprintf(outbuffer,"\r\n%s har olästa meddelanden. Skickar meddelandet ändå.\r\n",getusername(vem));
	else sprintf(outbuffer,"\r\n%s meddelad\r\n",getusername(vem));
	puttekn(outbuffer,-1);
	Forbid();
	while(pekare) {
		oldpekare=pekare;
		pekare=oldpekare->NextSay;
	}
	if(!(allocpekare=(struct SayString *)AllocMem(sizeof(struct SayString),MEMF_PUBLIC | MEMF_CLEAR))) {
		Permit();
		puttekn("\r\n\nKunde inte allokera minne till meddelandet!\r\n\n",-1);
		return(0);
	}
	allocpekare->fromuser=inloggad;
	if(quick) strcpy(allocpekare->text,quick);
	else strcpy(allocpekare->text,inmat);
	if(Servermem->say[x]) oldpekare->NextSay=allocpekare;
	else Servermem->say[x]=allocpekare;
	Permit();
	return(0);
}
Exemple #10
0
void
ruserpass(
    char  *host,
    char **aname,
    char **apass
    )
{
    char  prompt[128];

//
//  We don't support some things needed to do this lookup. No real need to
//  do it anyway.
//
//  renv(host, aname, apass);

//
// BUGBUG: turned off for Beta. We haven't decided how to support the
//         netrc file yet (ie where does it live?).
//
    if (*aname == NULL || *apass == NULL)
        rnetrc(host, aname, apass);

    if (*aname == NULL) {
        if (getlogin(myname, 256) != 0) {
            exit(1);
        }
        //  sprintf( prompt, "Name (%s:%s): ", host, myname);
        //
        //   Nls Enabled ( MuraliK) 10-19-94
        //
        NlsSPrintf( IDS_USER_NAME_PROMPT, prompt, 128, host, myname);
        *aname = getusername(prompt);
        if ((*aname)[0] == '\0') {
            *aname = myname;
        }
    }

    if ((*aname != NULL) && (*apass == NULL)) {
        // sprintf(prompt, "Password (%s:%s): ", host, myname);
        //
        //   Nls Enabled ( MuraliK) 10-19-94
        //
        NlsSPrintf( IDS_USER_PASSWORD_PROMPT, prompt, 128, host, myname);
        *apass = getpass(prompt);
        if ((*apass)[0] == '\0') {
            exit(1);
        }
    }
}
int BlogObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = TSqlObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    
#ifndef QT_NO_PROPERTIES
     if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< int*>(_v) = getid(); break;
        case 1: *reinterpret_cast< QString*>(_v) = getusername(); break;
        case 2: *reinterpret_cast< QString*>(_v) = gettitle(); break;
        case 3: *reinterpret_cast< QString*>(_v) = getdescription(); break;
        case 4: *reinterpret_cast< QDateTime*>(_v) = getcreated_at(); break;
        case 5: *reinterpret_cast< QDateTime*>(_v) = getupdated_at(); break;
        case 6: *reinterpret_cast< int*>(_v) = getlock_revision(); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setid(*reinterpret_cast< int*>(_v)); break;
        case 1: setusername(*reinterpret_cast< QString*>(_v)); break;
        case 2: settitle(*reinterpret_cast< QString*>(_v)); break;
        case 3: setdescription(*reinterpret_cast< QString*>(_v)); break;
        case 4: setcreated_at(*reinterpret_cast< QDateTime*>(_v)); break;
        case 5: setupdated_at(*reinterpret_cast< QDateTime*>(_v)); break;
        case 6: setlock_revision(*reinterpret_cast< int*>(_v)); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 7;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Exemple #12
0
void listabrev(void) {
        BPTR fh;
        int anv,x,first;
        char filnamn[50],namn[50];
        struct ReadLetter listhead;
        if(argument[0]) {
                anv=parsenamn(argument);
                if(anv==-1) {
                        puttekn("\n\n\rFinns ingen sådan användare!\n\r",-1);
                        return;
                }
        } else anv=inloggad;
        first=getfirstletter(anv);
        x=getnextletter(anv)-1;
        sprintf(outbuffer,"\n\n\rLägsta brev: %d  Högsta brev: %d\n\n\r",first,x);
        puttekn(outbuffer,-1);
        puttekn("Namn                              Text   Datum  Ärende\n\r",-1);
        puttekn("-------------------------------------------------------------------------\r\n",-1);
        for(;x>=first;x--) {
                sprintf(filnamn,"NiKom:Users/%d/%d/%d.letter",anv/100,anv,x);
                if(!(fh=Open(filnamn,MODE_OLDFILE))) {
                        sprintf(outbuffer,"\n\rKunde inte öppna %s\n\r",filnamn);
                        puttekn(outbuffer,-1);
                        return;
                }
                if(readletterheader(fh,&listhead)) {
                        sprintf(outbuffer,"\n\rKunde inte läsa %s\n\r",filnamn);
                        puttekn(outbuffer,-1);
                        Close(fh);
                        return;
                }
                Close(fh);
                listhead.subject[26]=0;
                listhead.date[6]=0;
                if(!strcmp(listhead.systemid,"NiKom")) {
                        if(anv!=inloggad && inloggad!=atoi(listhead.from)) continue;
                        strcpy(namn,getusername(atoi(listhead.from)));
                        sprintf(outbuffer,"%-34s%5d %s %s\r\n",namn,x,listhead.date,listhead.subject);
                } else if(!strcmp(listhead.systemid,"Fido")) {
                        if(anv!=inloggad) continue;
                        sprintf(outbuffer,"%-34s%5d %s %s\r\n",listhead.from,x,listhead.date,listhead.subject);
                } else sprintf(outbuffer,"%s%5d\r\n","<Okänd brevtyp>",x);
                if(puttekn(outbuffer,-1)) return;
        }
}
Exemple #13
0
int setPrompt(char *format)
{
    if (format == NULL) {
        char *username = getusername(getuid());
        char hostname[BUFSIZE];
        char *tmp = malloc((BUFSIZE+1) * sizeof(char));

        gethostname(hostname, BUFSIZE);
        snprintf(tmp, BUFSIZE, "%s%s@%s > %s", RED, username, hostname, CLEAR);

        if (prompt != NULL) free(prompt);
        free(username);
        prompt = tmp;
    } else
        prompt = format;

    return 0;
}
Exemple #14
0
void setinfo()

{
	static bool init = false;
	if (! init)
	{
		time_t now = time((time_t *) (0));
		strftime (info.thisyear, 5, "%Y", localtime(& now));
		strftime (info.thisdate, DATETIME_MAX, DAYTIME, localtime(& now));
		strlwr (info.thisdate);
		gethostname (info.hostname, HOSTNAME_MAX);
		getusername (info.username, USERNAME_MAX, getuid());
		sprintf (info.released, "  Released %s by %s for private use;", info.thisyear, PROJECT);
		sprintf (info.licensed, "  Licensed is %s version 2 only;", LICENSE);
		sprintf (info.packaged, "  Packaged as %s-%s.%s by %s;", PACKAGE, VERSION, RELEASE, CONTACT);
		init = true;
	}
	return;
}
Exemple #15
0
void listaarende(void) {
	char *nextarg=argument,namn[50],kom[10];
	int x,dir=-1,from=-1,baratexter=FALSE;
	struct Mote *motpek;
	struct Header lahead;
	struct tm *ts;
	if(mote2==-1) {
		sprintf(outbuffer,"\n\n\rAnvänd 'Lista Brev' i %s\n\r",Servermem->cfg.brevnamn);
		puttekn(outbuffer,-1);
		return;
	}
	while(nextarg[0]) {
		if(nextarg[0]=='-') {
			if(nextarg[1]=='t' || nextarg[1]=='T') baratexter=TRUE;
			else if(nextarg[1]=='f' || nextarg[1]=='F') {
				dir=1;
				if(from<0) from=-2;
			}
		} else if(isdigit(nextarg[0])) from=atoi(nextarg);
		nextarg=hittaefter(nextarg);
	}
	motpek=getmotpek(mote2);
	if(motpek->type==MOTE_FIDO) {
		fidolistaarende(motpek,dir);
		return;
	}
	puttekn("\r\n\nNamn                              Text    Kom   Datum  Ärende",-1);
	puttekn("\r\n-------------------------------------------------------------------------\r\n",-1);
	if(from==-1) from=Servermem->info.hightext;
	else if(from==-2) from=Servermem->info.lowtext;
	for(x=from;x>=Servermem->info.lowtext && x<=Servermem->info.hightext;x+=dir) {
		if(Servermem->texts[x%MAXTEXTS]!=mote2) continue;
		if(readtexthead(x,&lahead)) return;
		if(lahead.kom_till_nr!=-1 && baratexter) continue;
		strcpy(namn,getusername(lahead.person));
		lahead.arende[22]=0;
		ts=localtime(&lahead.tid);
		if(lahead.kom_till_nr==-1) strcpy(kom,"   -");
		else sprintf(kom,"%d",lahead.kom_till_nr);
		sprintf(outbuffer,"%-34s%6d %6s %02d%02d%02d %s\r\n",namn,lahead.nummer,kom,ts->tm_year,ts->tm_mon+1,ts->tm_mday,lahead.arende);
		if(puttekn(outbuffer,-1)) return;
	}
}
Exemple #16
0
void executeCommand(struct Kommando *cmd) {
  int afterRexxScript;
  if(cmd->before) {
    sendautorexx(cmd->before);
  }
  if(cmd->logstr[0]) {
    LogEvent(USAGE_LOG, INFO, "%s %s", getusername(inloggad), cmd->logstr);
  }
  if(cmd->vilkainfo[0]) {
    Servermem->action[nodnr] = GORNGTANNAT;
    Servermem->vilkastr[nodnr] = cmd->vilkainfo;
  }
  // Save 'after' in case the command to execute is to reload the config and
  // cmd is not a valid pointer anymore when DoExecuteCommand() returns.
  afterRexxScript = cmd->after; 
  DoExecuteCommand(cmd);
  if(afterRexxScript) {
    sendautorexx(afterRexxScript);
  }
}
Exemple #17
0
void Cmd_FootNote(void) {
  int textId, confId, editRet;
  struct Header textHeader;

  if(argument[0] == '\0') {
    SendString("\n\n\rSkriv: Fotnot <text nummer>\n\r");
    return;
  }
  textId = atoi(argument);
  confId = GetConferenceForText(textId);
  if(confId == -1) {
    SendString("\n\n\rFinns ingen sådan text.\n\r");
    return;
  }
  if(readtexthead(textId,&textHeader)) {
    return;
  }
  if(textHeader.person != inloggad
     && !MayAdminConf(confId, inloggad, &Servermem->inne[nodnr])) {
    SendString("\r\n\nDu kan bara lägga till fotnoter på dina egna texter.\r\n\n");
    return;
  }
  if(textHeader.footNote != 0) {
    SendString("\n\n\rTexten har redan en fotnot.\n\r");
    return;
  }

  SendString("\n\n\rFotnot till text %d av %s\n\r",
             textId, getusername(textHeader.person));
  if((editRet = edittext(NULL)) != 0) {
    return;
  }

  if(saveFootNoteLines(textId, &textHeader)) {
    writetexthead(textId, &textHeader);
  }
  freeeditlist();
}
Exemple #18
0
static void
printdirs(int dflag)
{
    struct directory *dp;
    Char   *s, *user;
    int     idx, len, cur;

    dp = dcwd;
    idx = 0;
    cur = 0;
    do {
	if (dp == &dhead)
	    continue;
	if (dflag & DIR_VERT) {
	    xprintf("%d\t", idx++);
	    cur = 0;
	}
	s = dp->di_name;		
	user = NULL;
	if (!(dflag & DIR_LONG) && (user = getusername(&s)) != NULL)
	    len = (int) (Strlen(user) + Strlen(s) + 2);
	else
	    len = (int) (Strlen(s) + 1);

	cur += len;
	if ((dflag & DIR_LINE) && cur >= TermH - 1 && len < TermH) {
	    xputchar('\n');
	    cur = len;
	}
	if (user) 
	    xprintf("~%S", user);
	xprintf("%-S%c", s, (dflag & DIR_VERT) ? '\n' : ' ');
    } while ((dp = dp->di_prev) != dcwd);
    if (!(dflag & DIR_VERT))
	xputchar('\n');
}
Exemple #19
0
void main(int argc,char *argv[]) {
    int going=TRUE,forsok=2,car=1,x,connectbps, i, tmp;
    struct NodeType *nt;
    char *tmppscreen,commandstring[100], configname[50] = "NiKom:DatoCfg/SerNode.cfg";
    FILE *fil;
    if(argc>1) for(x=1; x<argc; x++) {
            if(argv[x][0]=='-') {
                if(argv[x][1]=='G') getty=TRUE;
                else if(argv[x][1]=='B') gettybps=atoi(&argv[x][2]);
                else if(argv[x][1]=='C') connectbps = atoi(&argv[x][2]);
            } else strcpy(configname,argv[x]);
        }
    if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
        cleanup(ERROR,"Kunde inte öppna intuition.library\n");
    if(!(UtilityBase=OpenLibrary("utility.library",37L)))
        cleanup(ERROR,"Kunde inte öppna utility.library\n");
    if(!(NiKomBase=OpenLibrary("nikom.library",0L)))
        cleanup(ERROR,"Kunde inte öppna nikom.library\n");
    if(!initnode(NODSER)) cleanup(ERROR,"Kunde inte registrera noden i Servern\n");
    if(!(nikomnodeport = CreateMsgPort()))
        cleanup(ERROR,"Kunde inte skapa NiKomNode-porten");
    sprintf(nikomnodeportnamn,"NiKomNode%d",nodnr);
    nikomnodeport->mp_Node.ln_Name = nikomnodeportnamn;
    nikomnodeport->mp_Node.ln_Pri = 1;
    AddPort(nikomnodeport);
    sprintf(rexxportnamn,"NiKomPreRexx%d",nodnr);
    if(!(rexxport=(struct MsgPort *)CreateMsgPort()))
        cleanup(ERROR,"Kunde inte öppna RexxPort\n");
    rexxport->mp_Node.ln_Name=rexxportnamn;
    rexxport->mp_Node.ln_Pri=50;
    AddPort(rexxport);
    if(!(RexxSysBase=(struct RsxLib *)OpenLibrary("rexxsyslib.library",0L)))
        cleanup(ERROR,"Kunde inte öppna rexxsyslib.library\n");
    getnodeconfig(configname);
    if(pubscreen[0]=='-') tmppscreen=NULL;
    else tmppscreen=pubscreen;
    if(!(NiKwind=openmywindow(tmppscreen)))
        cleanup(ERROR,"Kunde inte öppna fönstret\n");
    if(getty) dtespeed = gettybps;
    else dtespeed = highbaud;
    if(!OpenIO(NiKwind)) cleanup(ERROR,"Couldn't setup IO");
    strcpy(Servermem->nodid[nodnr],nodid);
    conreqtkn();
    serreqtkn();
    Delay(50);
    for(;;) {
        inloggad=-1;
        Servermem->idletime[nodnr] = time(NULL);
        Servermem->inloggad[nodnr]=-1;
        if(getty) Servermem->connectbps[nodnr] = connectbps;
        else waitconnect();
        Servermem->idletime[nodnr] = time(NULL);
        Servermem->inloggad[nodnr]=-2; /* Sätt till <Uppringd> för att även hantera -getty-fallet */
reloginspec:
        updateinactive();
        Servermem->inne[nodnr].flaggor = Servermem->cfg.defaultflags;
        if(!getty) Delay(100);
        Servermem->inne[nodnr].rader=0;
        Servermem->inne[nodnr].chrset = CHRS_LATIN1;
        sendfile("NiKom:Texter/Inlogg.txt");
        if(Servermem->cfg.ar.preinlogg) sendrexx(Servermem->cfg.ar.preinlogg);
        car=TRUE;
        Servermem->inne[nodnr].chrset = 0;
        memset(commandhistory,0,1000);
        going=1;
        while(going && going<=Servermem->cfg.logintries) {
            putstring("\r\nNamn: ",-1,0);
            if(getstring(EKO,40,NULL)) {
                car=FALSE;
                break;
            }
            if(!stricmp(inmat,Servermem->cfg.ny)
                    && !(Servermem->cfg.cfgflags & NICFG_CLOSEDBBS)) {
                tmp = RegisterNewUser();
                if(tmp == 2) {
                    goto panik;
                }
                car = tmp ? 0 : 1;
                going=FALSE;
            } else if((inloggad=parsenamn(inmat))>=0) {
                if(readuser(inloggad,&Servermem->inne[nodnr])) {
                    puttekn("Error reading user data.\r\n", -1);
                    goto panik;
                }
                // TODO: Extract password loop. Should be identical to in NiKomCon.c
                forsok=2;
                while(forsok) {
                    puttekn("\r\nLösen: ",-1);
                    if(Servermem->inne[nodnr].flaggor & STAREKOFLAG)
                    {
                        if(getstring(STAREKO,15,NULL)) {
                            car=FALSE;
                            break;
                        }
                    }
                    else
                    {
                        if(getstring(EJEKO,15,NULL)) {
                            car=FALSE;
                            break;
                        }
                    }
                    if(CheckPassword(inmat, Servermem->inne[nodnr].losen))
                    {
                        forsok=FALSE;
                        going=FALSE;
                    } else forsok--;
                }
                if(going && (Servermem->cfg.logmask & LOG_FAILINLOGG)) {
                    LogEvent(USAGE_LOG, WARN, "Nod %d, %s angivet som namn, fel lösen.",
                             nodnr, getusername(inloggad));
                }
                if(going) going++;
            } else if(inloggad==-1) puttekn("\r\nHittar ej namnet\r\n",-1);
        }
        if(!car) {
            if(getty) cleanup(OK,"");
            disconnect();
            continue;
        }
        if(going) {
            putstring("\n\n\rTyvärr. Du har försökt maximalt antal gånger att logga in. Kopplar ned.\n\r",-1,0);
            goto panik;      /* Urrk vad fult. :-) */
        }
        Servermem->inloggad[nodnr]=inloggad;
        Servermem->idletime[nodnr] = time(NULL);
        if((nt = selectNodeType()) == NULL) {
            goto panik;
        }
        abortinactive();
        abortserial();

        sprintf(commandstring,"%s -N%d -B%d %s",nt->path,nodnr,dtespeed,configname);
        CloseConsole();
        CloseWindow(NiKwind);
        NiKwind = NULL;
        RemPort(nikomnodeport);

        i = 0;
        if(Servermem->connectbps[nodnr] > 0)
        {
            while(Servermem->info.bps[i] != Servermem->connectbps[nodnr] && Servermem->info.bps[i] > 0 && i<49)
                i++;

            if(i<49)
            {
                if(Servermem->info.bps[i] == Servermem->connectbps[nodnr])
                    Servermem->info.antbps[i]++;
                else
                {
                    Servermem->info.bps[i] = Servermem->connectbps[nodnr];
                    Servermem->info.antbps[i]++;
                }
            }

            if(!(fil = fopen("NiKom:datocfg/sysinfo.dat","w")))
            {
                /* putstring("Kunde inte spara nya sysinfo.dat..\n",-1,0); */
            }

            if(fwrite((void *)&Servermem->info,sizeof(Servermem->info),1,fil) != 1)
            {
                /* putstring("Kunde inte skriva till nya sysinfo.dat....\n",-1,0); */
            }
            fclose(fil);
        }

        nodestate = SystemTags(commandstring, SYS_UserShell, TRUE, TAG_DONE);
        AddPort(nikomnodeport);
        if(!getty || (nodestate & NIKSTATE_RELOGIN)) {
            if(!(NiKwind = openmywindow(tmppscreen))) cleanup(ERROR,"Kunde inte öppna fönstret\n");
            OpenConsole(NiKwind);
        }
        serreqtkn();
        if(nodestate & NIKSTATE_RELOGIN) goto reloginspec;
panik:
        Delay(hangupdelay);
        if(getty) cleanup(OK,"");
        disconnect();
    }
}
Exemple #20
0
void sparabrev(void) {
        BPTR fh,lock=NULL;
        struct EditLine *elpek;
        char bugbuf[100],orgfilename[50],*motstr;
        int till,nr,mot;
        Servermem->inne[nodnr].skrivit++;
        Servermem->info.skrivna++;
        Statstr.write++;
        till=atoi(brevspar.to);
        if((nr=updatenextletter(till))==-1) {
                freeeditlist();
                return;
        }
        sprintf(orgfilename,"NiKom:Users/%d/%d/%d.letter",till/100,till,nr);
        if(!(fh=Open(orgfilename,MODE_NEWFILE))) {
                puttekn("\n\n\rKunde inte öppna brevet\n\r",-1);
                freeeditlist();
                return;
        }
        strcpy(bugbuf,"System-ID: NiKom\n");
        FPuts(fh,bugbuf);
        sprintf(bugbuf,"From: %d\n",inloggad);
        FPuts(fh,bugbuf);
        sprintf(bugbuf,"To: %s\n",brevspar.to);
        FPuts(fh,bugbuf);
        if(brevspar.reply[0]) {
                sprintf(bugbuf,"Reply: %s\n",brevspar.reply);
                FPuts(fh,bugbuf);
        }
        sprintf(bugbuf,"Date: %s\n",brevspar.date);
        FPuts(fh,bugbuf);
        sprintf(bugbuf,"Subject: %s\n",brevspar.subject);
        FPuts(fh,bugbuf);
        for(elpek=(struct EditLine *)edit_list.mlh_Head;elpek->line_node.mln_Succ;elpek=(struct EditLine *)elpek->line_node.mln_Succ) {
                if(FPuts(fh,elpek->text)==-1) {
                        puttekn("\n\n\rFel vid skrivandet av brevet\n\r",-1);
                        break;
                }
                FPutC(fh,'\n');
        }
        Close(fh);
        freeeditlist();
        sprintf(outbuffer,"\r\nBrevet fick nummer %d hos %s\r\n",nr,getusername(till));
        puttekn(outbuffer,-1);
        if(Servermem->cfg.logmask & LOG_BREV) {
                strcpy(bugbuf,getusername(inloggad));
                sprintf(outbuffer,"%s skickar brev %d till %s",bugbuf,nr,getusername(till));
                logevent(outbuffer);
        }
        motstr=hittaefter(brevspar.to);
        if(motstr[0]) {
                if(!(lock=Lock(orgfilename,ACCESS_READ))) {
                        puttekn("\n\n\rKunde inte få ett lock för brevet\n\r",-1);
                        return;
                }
        }
        while(motstr[0]) {
                mot=atoi(motstr);
                if((nr=updatenextletter(mot))==-1) {
                        UnLock(lock);
                        return;
                }
                sprintf(bugbuf,"NiKom:Users/%d/%d/%d.letter",mot/100,mot,nr);
                if(!MakeLink(bugbuf,lock,FALSE)) {
                        puttekn("\n\n\rKunde inte skapa länk till brevet\n\r",-1);
                        UnLock(lock);
                        return;
                }
                sprintf(outbuffer,"\r\nBrevet fick nummer %d hos %s\r\n",nr,getusername(mot));
                puttekn(outbuffer,-1);
                if(Servermem->cfg.logmask & LOG_BREV) {
                        strcpy(bugbuf,getusername(inloggad));
                        sprintf(outbuffer,"%s skickar brev %d till %s",bugbuf,nr,getusername(mot));
                        logevent(outbuffer);
                }
                motstr=hittaefter(motstr);
        }
        if(lock) UnLock(lock);
}
Exemple #21
0
int fido_brev(char *tillpers,char *adr,struct Mote *motpek) {
        int length=0,x=0,editret,chrs;
        struct FidoDomain *fd;
        struct FidoText *komft,ft;
        struct MinNode *first, *last;
        char *foo,tmpfrom[100],fullpath[100],filnamn[20],subject[80],msgid[50],tkn;
        if(!(Servermem->inne[nodnr].grupper & Servermem->fidodata.mailgroups) &&
                Servermem->inne[nodnr].status < Servermem->fidodata.mailstatus) {
                puttekn("\n\n\rDu har ingen rätt att skicka FidoNet NetMail.\n\r",-1);
                return(0);
        }
        Servermem->action[nodnr] = SKRIVER;
        Servermem->varmote[nodnr] = -1;
        memset(&ft,0,sizeof(struct FidoText));
        if(!tillpers) { /* Det handlar om en kommentar */
                if(motpek) { /* Det är en personlig kommentar */
                        strcpy(fullpath,motpek->dir);
                        sprintf(filnamn,"%d.msg",senast_text_nr - motpek->renumber_offset);
                        AddPart(fullpath,filnamn,99);
                        komft = ReadFidoTextTags(fullpath,RFT_HeaderOnly,TRUE,TAG_DONE);
                        if(!komft) {
                                puttekn("\n\n\rTexten finns inte.\n\r",-1);
                                return(0);
                        }
                        strcpy(ft.touser,komft->fromuser);
                        ft.tozone = komft->fromzone;
                        ft.tonet = komft->fromnet;
                        ft.tonode = komft->fromnode;
                        ft.topoint = komft->frompoint;
                        strcpy(subject,komft->subject);
                        strcpy(msgid,komft->msgid);
                        FreeFidoText(komft);
                } else { /* Det är en kommentar av ett brev */
                        strcpy(tmpfrom,brevread.from);
                        foo=strchr(tmpfrom,'(');
                        if(!foo) {
                                puttekn("\n\n\rDen kommenterade texten saknar adress!\n\r",-1);
                                return(0);
                        }
                        *(foo-1)='\0';
                        foo++;
                        strcpy(ft.touser,tmpfrom);
                        ft.tozone=getzone(foo);
                        ft.tonet=getnet(foo);
                        ft.tonode=getnode(foo);
                        ft.topoint=getpoint(foo);
                        strcpy(subject,brevread.subject);
                        strcpy(msgid,brevread.messageid);

                }
        } else { /* Det är ett helt nytt brev */
                strcpy(ft.touser,tillpers);
                sprattgok(ft.touser);
                ft.tozone=getzone(adr);
                ft.tonet=getnet(adr);
                ft.tonode=getnode(adr);
                ft.topoint=getpoint(adr);
        }
        fd = getfidodomain(0,ft.tozone);
        if(!fd) {
                puttekn("\n\n\rDu kan inte skriva brev till den zonen.\n\r",-1);
                return(0);
        }
        if(!tillpers && !motpek) {
                foo = strchr(brevread.to,'(')+1;
                ft.fromzone = getzone(foo);
                ft.fromnet = getnet(foo);
                ft.fromnode = getnode(foo);
                ft.frompoint = getpoint(foo);
        } else {
                ft.fromzone = fd->zone;
                ft.fromnet = fd->net;
                ft.fromnode = fd->node;
                ft.frompoint = fd->point;
        }
        ft.attribut = FIDOT_PRIVATE | FIDOT_LOCAL;
        makefidousername(ft.fromuser,inloggad);
        makefidodate(ft.date);
        sprintf(outbuffer,"\r\n\nMöte: %s\r\n",Servermem->cfg.brevnamn);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Fido-nätbrev,  %s\n\r",ft.date);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Avsändare: %s (%d:%d/%d.%d)\r\n",ft.fromuser,ft.fromzone,ft.fromnet,ft.fromnode,ft.frompoint);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Mottagare: %s (%d:%d/%d.%d)\n\r",ft.touser,ft.tozone,ft.tonet,ft.tonode,ft.topoint);
        puttekn(outbuffer,-1);
        puttekn("Ärende: ",-1);
        if(!tillpers) {
                if(!strncmp(subject,"Re:",3)) strcpy(ft.subject,subject);
                else sprintf(ft.subject,"Re: %s",subject);
                puttekn(ft.subject,-1);
        } else {
                if(getstring(EKO,40,NULL)) return(1);
                if(!inmat[0]) {
                        eka('\n');
                        return(0);
                }
                strcpy(ft.subject,inmat);
        }
        puttekn("\r\n",-1);
        if(Servermem->inne[nodnr].flaggor & STRECKRAD) {
                length=strlen(ft.subject);
                for(x=0;x<length+8;x++) outbuffer[x]='-';
                outbuffer[x]=0;
                puttekn(outbuffer,-1);
                puttekn("\r\n\n",-1);
        } else puttekn("\n",-1);
        crashmail = FALSE;
        editret = edittext(NULL);
        if(editret==1) return(1);
        if(editret==2) return(0);
        if(crashmail) ft.attribut |= FIDOT_CRASH;
        Servermem->inne[nodnr].skrivit++;
        Servermem->info.skrivna++;
        Statstr.write++;
        puttekn("\n\n\rTill vilken teckenuppsättning ska brevet konverteras?\r\n\n",-1);
        puttekn("1: ISO Latin 8-bitars tecken (Default)\n\r",-1);
        puttekn("2: IBM PC 8-bitars tecken\r\n",-1);
        puttekn("3: Macintosh 8-bitars tecken\r\n",-1);
        puttekn("4: Svenska 7-bitars tecken\r\n\n",-1);
        puttekn("Val: ",-1);
        for(;;) {
                tkn=gettekn();
                if(tkn==13 || tkn==10) tkn='1';
                if(tkn >= '1' && tkn <= '4') break;
        }
        sprintf(outbuffer,"%c\r\n\n",tkn);
        puttekn(outbuffer,-1);
        switch(tkn) {
                case '1' : chrs=CHRS_LATIN1; break;
                case '2' : chrs=CHRS_CP437; break;
                case '3' : chrs=CHRS_MAC; break;
                case '4' : chrs=CHRS_SIS7; break;
        }
        NewList((struct List *)&ft.text);
        first =  edit_list.mlh_Head;
        last = edit_list.mlh_TailPred;
        ft.text.mlh_Head = first;
        ft.text.mlh_TailPred = last;
        last->mln_Succ = (struct MinNode *)&ft.text.mlh_Tail;
        first->mln_Pred = (struct MinNode *)&ft.text;
        if(tillpers) x = WriteFidoTextTags(&ft,WFT_MailDir,Servermem->fidodata.matrixdir,
                                                      WFT_Domain,fd->domain,
                                                      WFT_CharSet,chrs,
                                                      TAG_DONE);
        else x = WriteFidoTextTags(&ft,WFT_MailDir,Servermem->fidodata.matrixdir,
                                            WFT_Domain,fd->domain,
                                            WFT_Reply,msgid,
                                            WFT_CharSet,chrs,
                                            TAG_DONE);
        sprintf(outbuffer,"Brevet fick nummer %d\r\n\n",x);
        puttekn(outbuffer,-1);
        if(Servermem->cfg.logmask & LOG_BREV) {
                strcpy(tmpfrom,getusername(inloggad));
                sprintf(outbuffer,"%s skickar brev %d till %s (%d:%d/%d.%d)",tmpfrom,x,ft.touser,ft.tozone,ft.tonet,ft.tonode,ft.topoint);
                logevent(outbuffer);
        }
        puttekn("Vill du ha en kopia av brevet i din egen brevlåda? ",-1);
        if(jaellernej('j','n',2)) savefidocopy(&ft,inloggad);
        while(first=(struct MinNode *)RemHead((struct List *)&ft.text)) FreeMem(first,sizeof(struct EditLine));
        NewList((struct List *)&edit_list);
        return(0);
}
Exemple #22
0
int initbrevheader(int tillpers) {
        int length=0,x=0,lappnr;
        long tid,tempmott;
        struct tm *ts;
        struct User usr;
        char filnamn[40],*mottagare,tempbuf[10],*vemskrev;
        Servermem->action[nodnr] = SKRIVER;
        Servermem->varmote[nodnr] = -1;
        memset(&brevspar,0,sizeof(struct ReadLetter));
        if(tillpers==-1) {
                strcpy(brevspar.to,brevread.from);
                mottagare=brevread.to;
                while(mottagare[0]) {
                        tempmott=atoi(mottagare);
                        if(tempmott==inloggad || recisthere(brevspar.to,tempmott)) {
                                mottagare=hittaefter(mottagare);
                                continue;
                        }
                        sprintf(tempbuf," %d",tempmott);
                        strcat(brevspar.to,tempbuf);
                        mottagare=hittaefter(mottagare);
                }
                sprintf(brevspar.reply,"%d %d %s",senast_brev_anv,senast_brev_nr,brevread.from);
        } else {
                sprintf(brevspar.to,"%d",tillpers);
        }
        sprintf(brevspar.from,"%d",inloggad);
        readuser(atoi(brevspar.to),&usr);
        if(usr.flaggor & LAPPBREV) {
                puttekn("\r\n\n",-1);
                lappnr=atoi(brevspar.to);
                sprintf(filnamn,"NiKom:Users/%d/%d/Lapp",lappnr/100,lappnr);
                if(!access(filnamn,0)) sendfile(filnamn);
                puttekn("\r\n",-1);
        }
        time(&tid);
        ts=localtime(&tid);
        sprintf(brevspar.date,"%2d%02d%02d %02d:%02d",ts->tm_year,ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min);
        strcpy(brevspar.systemid,"NiKom");
        sprintf(outbuffer,"\r\n\nMöte: %s\r\n",Servermem->cfg.brevnamn);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Lokalt brev,  %s\n\r",brevspar.date);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Avsändare: %s\r\n",getusername(inloggad));
        puttekn(outbuffer,-1);
        if(brevspar.reply[0]) {
                vemskrev=hittaefter(hittaefter(brevspar.reply));
                sprintf(outbuffer,"Kommentar till en text av %s\r\n",getusername(atoi(vemskrev)));
                puttekn(outbuffer,-1);
        }
        mottagare=brevspar.to;
        while(mottagare[0]) {
                sprintf(outbuffer,"Mottagare: %s\n\r",getusername(atoi(mottagare)));
                puttekn(outbuffer,-1);
                mottagare=hittaefter(mottagare);
        }
        puttekn("Ärende: ",-1);
        if(tillpers==-1) {
                strcpy(brevspar.subject,brevread.subject);
                puttekn(brevspar.subject,-1);
        } else {
                if(getstring(EKO,40,NULL)) return(1);
                if(!inmat[0]) {
                        eka('\n');
                        return(2);
                }
                strcpy(brevspar.subject,inmat);
        }
        puttekn("\r\n",-1);
        if(Servermem->inne[nodnr].flaggor & STRECKRAD) {
                length=strlen(brevspar.subject);
                for(x=0;x<length+8;x++) outbuffer[x]='-';
                outbuffer[x]=0;
                puttekn(outbuffer,-1);
                puttekn("\r\n\n",-1);
        } else puttekn("\n",-1);
        return(0);
}
Exemple #23
0
void visafidobrev(struct ReadLetter *brevread, BPTR fh, int brev, int anv) {
        int length,x;
        char textbuf[100];
        if(anv!=inloggad && Servermem->inne[nodnr].status<Servermem->cfg.st.brev) {
                puttekn("\n\n\rDu har inte rätt att läsa det brevet!\n\r",-1);
                return;
        }
        Servermem->inne[nodnr].read++;
        Servermem->info.lasta++;
        Statstr.read++;
        sprintf(outbuffer,"\r\n\nText %d  i %s hos %s\r\n",brev,Servermem->cfg.brevnamn,getusername(anv));
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Fido-nätbrev,  %s\n\r",brevread->date);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Avsändare: %s\r\n",brevread->from);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Mottagare: %s\n\r",brevread->to);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Ärende: %s\r\n",brevread->subject);
        puttekn(outbuffer,-1);
        if(Servermem->inne[nodnr].flaggor & STRECKRAD) {
                length=strlen(outbuffer);
                for(x=0;x<length-2;x++) outbuffer[x]='-';
                outbuffer[x]=0;
                puttekn(outbuffer,-1);
                puttekn("\r\n\n",-1);
        } else puttekn("\n",-1);

        while(FGets(fh,textbuf,99)) {
                if(textbuf[0]==1) {
                        if(!(Servermem->inne[nodnr].flaggor & SHOWKLUDGE)) continue;
                        puttekn("^A",-1);
                        if(puttekn(&textbuf[1],-1)) break;
                } else {
                        if(puttekn(textbuf,-1)) break;
                }
                eka('\r');
        }
        Close(fh);
        sprintf(outbuffer,"\r\n(S**t på text %d av %s)\r\n",brev,brevread->from);
        puttekn(outbuffer,-1);
        senast_text_typ=BREV;
        senast_brev_nr=brev;
        senast_brev_anv=anv;
}
Exemple #24
0
void visabrev(int brev,int anv) {
        BPTR fh;
        int x,length=0,tillmig=FALSE;
        char filnamn[40],*mottagare,textbuf[100],*vemskrev;
        sprintf(filnamn,"NiKom:Users/%d/%d/%d.letter",anv/100,anv,brev);
        if(!(fh=Open(filnamn,MODE_OLDFILE))) {
                sprintf(outbuffer,"\n\n\rKunde inte öppna %s\n\r",filnamn);
                puttekn(outbuffer,-1);
                return;
        }
        readletterheader(fh,&brevread);
        if(!strncmp(brevread.systemid,"Fido",4)) {
                visafidobrev(&brevread,fh,brev,anv);
                return;
        }
        mottagare=brevread.to;
        while(mottagare[0]) {
                if(inloggad==atoi(mottagare)) {
                        tillmig=TRUE;
                        break;
                }
                mottagare=hittaefter(mottagare);
        }
        if(!tillmig && inloggad!=atoi(brevread.from) && Servermem->inne[nodnr].status<Servermem->cfg.st.brev) {
                puttekn("\n\n\rDu har inte rätt att läsa det brevet!\n\r",-1);
                return;
        }
        Servermem->inne[nodnr].read++;
        Servermem->info.lasta++;
        Statstr.read++;
        sprintf(outbuffer,"\r\n\nText %d  i %s hos %s\r\n",brev,Servermem->cfg.brevnamn,getusername(anv));
        puttekn(outbuffer,-1);
        if(!strncmp(brevread.systemid,"NiKom",5)) sprintf(outbuffer,"Lokalt brev,  %s\n\r",brevread.date);
        else sprintf(outbuffer,"<Okänd brevtyp>  %s\n\r",brevread.date);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Avsändare: %s\r\n",getusername(atoi(brevread.from)));
        puttekn(outbuffer,-1);
        if(brevread.reply[0]) {
                vemskrev=hittaefter(hittaefter(brevread.reply));
                sprintf(outbuffer,"Kommentar till en text av %s\r\n",getusername(atoi(vemskrev)));
                puttekn(outbuffer,-1);
        }
        mottagare=brevread.to;
        while(mottagare[0]) {
                sprintf(outbuffer,"Mottagare: %s\n\r",getusername(atoi(mottagare)));
                puttekn(outbuffer,-1);
                mottagare=hittaefter(mottagare);
        }
        sprintf(outbuffer,"Ärende: %s\r\n",brevread.subject);
        puttekn(outbuffer,-1);
        if(Servermem->inne[nodnr].flaggor & STRECKRAD) {
                length=strlen(outbuffer);
                for(x=0;x<length-2;x++) outbuffer[x]='-';
                outbuffer[x]=0;
                puttekn(outbuffer,-1);
                puttekn("\r\n\n",-1);
        } else puttekn("\n",-1);

        while(FGets(fh,textbuf,99)) {
                if(puttekn(textbuf,-1)) break;
                eka('\r');
        }
        Close(fh);
        sprintf(outbuffer,"\r\n(S**t på text %d av %s)\r\n",brev,getusername(atoi(brevread.from)));
        puttekn(outbuffer,-1);
        senast_text_typ=BREV;
        senast_brev_nr=brev;
        senast_brev_anv=anv;
}
Exemple #25
0
int sendbinfile(void) {
    struct TransferFiles *tf;
    int xprreturkod,cnt=0;
    if(!(XProtocolBase=(struct Library *)OpenLibrary("xprzmodem.library",0L)))
    {
        puttekn("\r\n\nKunde inte öppna xprzmodem.library!\r\n",-1);
        return(2);
    }
    if(!(xio=(struct XPR_IO *)AllocMem(sizeof(struct XPR_IO),MEMF_PUBLIC | MEMF_CLEAR))) {
        puttekn("\r\n\nKunde inte allokera en io-struktur\r\n",-1);
        CloseLibrary(XProtocolBase);
        return(2);
    }
    puttekn("\r\nDu kan börja ta emot med Zmodem.\r\n",-1);
    puttekn("Tryck Ctrl-X några gånger för att avbryta.\r\n",-1);
    AbortIO((struct IORequest *)serreadreq);
    WaitIO((struct IORequest *)serreadreq);
    if(!CheckIO((struct IORequest *)inactivereq)) {
        AbortIO((struct IORequest *)inactivereq);
        WaitIO((struct IORequest *)inactivereq);
    }

    xpr_setup(xio);
    xio->xpr_filename=zinitstring;
    XProtocolSetup(xio);
    xio->xpr_filename="Hejhopp";
    xprreturkod=XProtocolSend(xio);
    Delay(30);
    XProtocolCleanup(xio);
    CloseLibrary(XProtocolBase);
    if(!CheckIO((struct IORequest *)serreadreq)) {
        AbortIO((struct IORequest *)serreadreq);
        WaitIO((struct IORequest *)serreadreq);
        printf("Serreadreq avbruten!!\n");
    }
    if(!CheckIO((struct IORequest *)timerreq)) {
        AbortIO((struct IORequest *)timerreq);
        WaitIO((struct IORequest *)timerreq);
        printf("Timerreq avbruten!!\n");
    }
    FreeMem(xio,sizeof(struct XPR_IO));
    Delay(100);
    serchangereq->IOSer.io_Command=CMD_CLEAR;
    DoIO((struct IORequest *)serchangereq);
    serchangereq->IOSer.io_Command=CMD_FLUSH;
    DoIO((struct IORequest *)serchangereq);
    serreqtkn();
    updateinactive();
    if(Servermem->cfg.logmask & LOG_SENDFILE) {
        for(tf=(struct TransferFiles *)tf_list.mlh_Head; tf->node.mln_Succ; tf=(struct TransferFiles *)tf->node.mln_Succ)
            if(tf->sucess) {
                LogEvent(USAGE_LOG, INFO, "Skickar filen %s till %s",
                         tf->path, getusername(inloggad));
            }
    }
    for(tf=(struct TransferFiles *)tf_list.mlh_Head; tf->node.mln_Succ; tf=(struct TransferFiles *)tf->node.mln_Succ)
        if(tf->sucess) cnt++;
    if(cnt==1) strcpy(outbuffer,"\n\n\rFörde över 1 fil.\n\n\r");
    else sprintf(outbuffer,"\n\n\rFörde över %d filer.\n\n\r",cnt);
    puttekn(outbuffer,-1);
    return(0);
}
Exemple #26
0
int upload(void) {	/* Ändrad för nikfiles.data 960707 JÖ */
    int area,ret,editret,dirnr;
    long tid;
    struct EditLine *el;
    FILE *fp;
    __aligned struct FileInfoBlock info;
    struct Fil *allokpek;
    char nikfilename[100],errbuff[100],filnamn[50],tmpfullname[100], outbuffer[81];
    UBYTE tn;
    struct TransferFiles *tf;

    if(Servermem->cfg.ar.preup1) sendautorexx(Servermem->cfg.ar.preup1);
    if(area2==-1) {
        puttekn("\r\nI vilken area? ",-1);
    } else {
        sprintf(outbuffer,"\r\nI vilken area? (<RETURN> för %s)",Servermem->areor[area2].namn);
        puttekn(outbuffer,-1);
    }
    if(getstring(EKO,40,NULL)) return(1);
    if((area=parsearea(inmat))==-1) {
        puttekn("\n\rFinns ingen sådan area!\n\r",-1);
        return(0);
    } else if(area==-3) {
        if(area2==-1) return(0);
        area=area2;
    }
    if(!arearatt(area, inloggad, &Servermem->inne[nodnr])) {
        puttekn("\n\rFinns ingen sådan area!\n\r",-1);
        return(0);
    }
    if((Servermem->areor[area].flaggor & AREA_NOUPLOAD) && (Servermem->inne[nodnr].status < Servermem->cfg.st.laddaner)) {
        puttekn("\n\n\rDu har ingen rätt att ladda upp till den arean!\n\r",-1);
        return(0);
    }
    Servermem->action[nodnr] = UPLOAD;
    Servermem->varmote[nodnr] = area;
    Servermem->vilkastr[nodnr] = NULL;
    if(ret=recbinfile(Servermem->cfg.ultmp)) {
        while(tf=(struct TransferFiles *)RemHead((struct List *)&tf_list))
            FreeMem(tf,sizeof(struct TransferFiles));
        if(carrierdropped()) return(1);
        return(0);
    }

    /* printf("Filnamn = %s\n",FilePart(tf->Filnamn));
    printf("Cps = %d\n\n",tf->cps); */

    for(tf=(struct TransferFiles *)tf_list.mlh_Head; tf->node.mln_Succ; tf=(struct TransferFiles *)tf->node.mln_Succ) {
        strcpy(xprfilnamn,tf->Filnamn);
        if(stcgfn(filnamn,xprfilnamn)>40) puttekn("\r\nVARNING! Filnamnet större än 40 tecken!\r\n",-1);
        if(!filnamn[0]) {
            puttekn("\r\n\nHmm... Filen har inget namn. Skriv ett brev till sysop.\r\n",-1);
            continue;
        }
        if(!valnamn(filnamn,area,errbuff)) {
            for(;;) {
                puttekn(errbuff,-1);
                puttekn("\r\nNytt namn: ",-1);
                if(getstring(EKO,40,NULL)) {
                    DeleteFile(xprfilnamn);
                    return(1);
                }
                if(!inmat[0]) continue;
                if(valnamn(inmat,area,errbuff)) break;
            }
            strcpy(filnamn,inmat);
            sprintf(tmpfullname,"%s%s",Servermem->cfg.ultmp,filnamn);
            if(!Rename(xprfilnamn,tmpfullname)) {
                sprintf(outbuffer,"\r\n\nKunde inte döpa om filen från '%s'\r\ntill '%s'.\r\n",xprfilnamn,tmpfullname);
                puttekn(outbuffer,-1);
                DeleteFile(xprfilnamn);
                continue;
            }
        } else strcpy(tmpfullname,xprfilnamn);
        if(!(allokpek=(struct Fil *)AllocMem(sizeof(struct Fil),MEMF_PUBLIC | MEMF_CLEAR))) {
            puttekn("\r\n\nKunde inte allokera minne för filen!\r\n",-1);
            continue;
        }
        time(&tid);
        allokpek->tid=allokpek->validtime=tid;
        allokpek->uppladdare=inloggad;
        if(dfind(&info,tmpfullname,0)) {
            sprintf(outbuffer,"\r\nHittar inte filen %s!\r\n",tmpfullname);
            puttekn(outbuffer,-1);
            FreeMem(allokpek,sizeof(struct Fil));
            continue;
        }
        allokpek->size=info.fib_Size;

        sprintf(outbuffer,"\r\n\r\nFilnamn: %s", filnamn);
        puttekn(outbuffer,-1);
        puttekn("\r\nVilken status ska behövas för att ladda ner filen? (0)",-1);
        if(getstring(EKO,3,NULL)) {
            FreeMem(allokpek,sizeof(struct Fil));
            return(1);
        }
        allokpek->status=atoi(inmat);
        if(Servermem->inne[nodnr].status >= Servermem->cfg.st.filer) {
            puttekn("\n\rSka filen valideras? ",-1);
            if(jaellernej('j','n',1)) puttekn("Ja",-1);
            else {
                puttekn("Nej",-1);
                allokpek->flaggor|=FILE_NOTVALID;
            }
            puttekn("\n\rSka filen ha fri download? ",-1);
            if(jaellernej('j','n',2)) {
                puttekn("Ja",-1);
                allokpek->flaggor|=FILE_FREEDL;
            } else puttekn("Nej",-1);
        } else if(Servermem->cfg.cfgflags & NICFG_VALIDATEFILES) allokpek->flaggor|=FILE_NOTVALID;
        sendfile("NiKom:Texter/Nyckelhjälp.txt");
        puttekn("\r\nVilka söknycklar ska filen ha? (? för att få en lista)\r\n",-1);
        if(editkey(allokpek->nycklar)) {
            FreeMem(allokpek,sizeof(struct Fil));
            return(1);
        }
        puttekn("\r\nBeskrivning:\r\n",-1);
        if(getstring(EKO,70,NULL)) {
            FreeMem(allokpek,sizeof(struct Fil));
            return(1);
        }
        strcpy(allokpek->beskr,inmat);
        dirnr = ChooseDirectoryInFileArea(
                    area, allokpek->nycklar, allokpek->size);
        if(dirnr==-1) {
            puttekn("\r\n\nKunde inte hitta något lämpligt directory för filen!\r\n",-1);
            DeleteFile(tmpfullname);
            FreeMem(allokpek,sizeof(struct Fil));
            continue;
        }
        allokpek->dir=dirnr;
        strcpy(allokpek->namn,filnamn);
        sprintf(inmat,"%s %s",tmpfullname,Servermem->areor[area].dir[dirnr]);
        argument=inmat;
        sendrexx(10);
        AddTail((struct List *)&Servermem->areor[area].ar_list,(struct Node *)allokpek);
        if(writefiles(area)) {
            puttekn("\r\n\nKunde inte skriva till datafilen\r\n",-1);

        }

        Servermem->inne[nodnr].upload++;
        Statstr.ul++;
        if(Servermem->cfg.logmask & LOG_UPLOAD) {
            LogEvent(USAGE_LOG, INFO, "%s laddar upp %s",
                     getusername(inloggad), allokpek->namn);
        }
        if(Servermem->cfg.ar.postup1) sendautorexx(Servermem->cfg.ar.postup1);
        puttekn("\r\n\nVill du skriva en längre beskrivning? (J/n) ",-1);
        while((tn=gettekn())!='j' && tn!='J' && tn!='n' && tn!='N' && tn!=13);
        if(tn=='j' || tn=='J') {
            puttekn("\r\n\nOk, går in i editorn.\r\n",-1);
            if((editret=edittext(NULL))==1) return(1);
            else if(editret==2) continue;
            sprintf(nikfilename,"%slongdesc/%s.long",Servermem->areor[area].dir[dirnr],filnamn);
            if(!(fp=fopen(nikfilename,"w"))) {
                puttekn("\r\n\nKunde inte öppna longdesc-filen\r\n",-1);
                freeeditlist();
                continue;
            }
            for(el=(struct EditLine *)edit_list.mlh_Head; el->line_node.mln_Succ; el=(struct EditLine *)el->line_node.mln_Succ) {
                if(fputs(el->text,fp)) {
                    freeeditlist();
                    fclose(fp);
                    continue;
                }
                fputc('\n',fp);
            }
            freeeditlist();
            fclose(fp);
            puttekn("\r\n",-1);
            allokpek->flaggor|=FILE_LONGDESC;
            updatefile(area,allokpek);
        }
    }

    while(tf=(struct TransferFiles *)RemHead((struct List *)&tf_list))
        FreeMem(tf,sizeof(struct TransferFiles));

    return(0);
}
Exemple #27
0
/**
 * @brief
 * 	perm_granted_admin_and_name: returns 0 if permission mask in 'disallow' has
 *	been granted to only admin-type of accounts and 'owner'. 'owner' can be
 *	set to NULL. Otherwise, it will return the values EPERM or EACCESS with
 *	error message returned in 'errmsg'.
 */
int
perm_granted_admin_and_owner(char *path, int disallow, char *owner, char *errmsg)
{
	int	rc;
	DWORD	i, j;
	SID	*powner = NULL;
	char	*powner_s = NULL;

	ACL	   *pdacl = NULL;
	SECURITY_DESCRIPTOR *psd = NULL;
	ACL_SIZE_INFORMATION	sizeInfo;
	ACCESS_ALLOWED_ACE	*pace;
	int			violate = 0;
	struct	accessinfo	*allowed = NULL;
	struct  accessinfo	*denied = NULL;
	int			mask;
	char			*name;
	SID			*esid = getusersid("Everyone");

	if (GetNamedSecurityInfo(path, SE_FILE_OBJECT,
		OWNER_SECURITY_INFORMATION|DACL_SECURITY_INFORMATION,
		&powner, 0, &pdacl, 0, &psd) != ERROR_SUCCESS) {
		errno = GetLastError();
		rc = errno;
		sprintf(errmsg, "GetNameSecurityInfo on file %s failed", path);
		goto chkerr;
	}

	/* is owner SID a privilege user? */
	powner_s = getusername(powner);
	if (powner_s == NULL)
		powner_s = getgrpname(powner);

	if (powner_s != NULL) {
		if ( !sidIsAdminPrivilege(powner) || \
			( (owner != NULL) && strcmp(owner, powner_s) != 0 )  ) {
			rc = EPERM;
			sprintf(errmsg, "File %s not owned by user %s or an admin-type user!",
				path, owner);
			goto chkerr;
		}
	}

	/* make sure perm mask granted only to privilege groups or the
	 special 'owner' */

	GetAclInformation(pdacl, &sizeInfo, sizeof(sizeInfo),
		AclSizeInformation);

	allowed = (struct accessinfo *)malloc(sizeof(struct accessinfo)*sizeInfo.AceCount);
	denied = (struct accessinfo *)malloc(sizeof(struct accessinfo)*sizeInfo.AceCount);

	if (allowed == NULL || denied == NULL) {
		rc = errno;
		strcpy(errmsg, "malloc of allowed or denied struct failed!");
		goto chkerr;
	}

	accessinfo_init(allowed, sizeInfo.AceCount);
	accessinfo_init(denied, sizeInfo.AceCount);

	for (i=0; i < sizeInfo.AceCount; i++) {

		GetAce(pdacl, i, (void **)&pace);
		name = getgrpname_full((SID *)&pace->SidStart);
		if (name == NULL)
			name = getusername((SID *)&pace->SidStart);

		/* later, we need to also check denied access which */
		/* overrides allowed access. */
		if ( pace->Header.AceType == ACCESS_ALLOWED_ACE_TYPE &&\
			 (mask=(pace->Mask & disallow)) && \
			 ( EqualSid((SID *)&pace->SidStart, esid) || \
			sid2rid((SID *)&pace->SidStart) != \
					 SECURITY_CREATOR_OWNER_RID ) && \
			(!sidIsAdminPrivilege( (SID *)&pace->SidStart)) || \
   			((owner != NULL) && strcmp(name, owner) != 0) ) {
			(void)accessinfo_add(allowed, sizeInfo.AceCount,
				name, (mask & 0xFFFF));
		} else if (pace->Header.AceType == ACCESS_DENIED_ACE_TYPE) {
			(void)accessinfo_add(denied, sizeInfo.AceCount,
				name, (pace->Mask & 0xFFFF));
		} else {
			if (name) {
				(void)free(name);
			}
		}
	}
	/* validate */
	for (i=0; i < sizeInfo.AceCount; i++) {
		for (j=0; j < sizeInfo.AceCount; j++) {
			if( allowed[i].group == NULL || \
						denied[j].group == NULL )
				continue;

			if (strcmp(allowed[i].group, denied[j].group) == 0)
				allowed[i].mask &= ~denied[j].mask;
			/* unset the denied mask from allowed */
		}
	}


	if (!accessinfo_mask_allzero(allowed, sizeInfo.AceCount)) {
		rc = EACCES;
		sprintf(errmsg, "File %s has following disallowed perm masks: ",
			path);
		strcat(errmsg, accessinfo_values(allowed, sizeInfo.AceCount));
		goto chkerr;
	}

	rc = 0;

chkerr:
	if (powner_s)(void)free(powner_s);
	/* NOTE: powner and pdacl hang off of psd, so a free of psd would */
	/* automatically free them */
	if (psd) LocalFree(psd);
	if (allowed) accessinfo_free(allowed, sizeInfo.AceCount);
	if (denied) accessinfo_free(denied, sizeInfo.AceCount);
	if (esid) LocalFree(esid);

	return (rc);
}
Exemple #28
0
int
perm_granted(char *path, int perm_mask, char *user, char *realuser)
{
	int	rc;
	DWORD	i, j;
	ACL	   *pdacl = NULL;
	SECURITY_DESCRIPTOR *psd = NULL;
	ACL_SIZE_INFORMATION	sizeInfo;
	ACCESS_ALLOWED_ACE	*pace;
	struct	accessinfo	*allowed = NULL;
	struct  accessinfo	*denied = NULL;
	int			mask;
	char			*name;
	SID			*usid;

	if (GetNamedSecurityInfo(path, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
		0, 0, &pdacl, 0, &psd) != ERROR_SUCCESS) {
		errno = GetLastError();
		rc = 1;
		goto perm_chkerr;
	}

	usid = getusersid2(user, realuser);
	if (usid == NULL) {
		rc = 2;
		goto perm_chkerr;
	}

	/* make sure perm mask granted only to privilege groups or the
	 special 'owner' */

	GetAclInformation(pdacl, &sizeInfo, sizeof(sizeInfo),
		AclSizeInformation);

	allowed = (struct accessinfo *)malloc(sizeof(struct accessinfo)*sizeInfo.AceCount);
	denied = (struct accessinfo *)malloc(sizeof(struct accessinfo)*sizeInfo.AceCount);

	if (allowed == NULL || denied == NULL) {
		rc = 3;
		goto perm_chkerr;
	}

	accessinfo_init(allowed, sizeInfo.AceCount);
	accessinfo_init(denied, sizeInfo.AceCount);

	for (i=0; i < sizeInfo.AceCount; i++) {

		GetAce(pdacl, i, (void **)&pace);
		name = getgrpname_full((SID *)&pace->SidStart);
		if (name == NULL)
			name = getusername((SID *)&pace->SidStart);

		/* later, we need to also check denied access which */
		/* overrides allowed access. */
		if ( (pace->Header.AceType == ACCESS_ALLOWED_ACE_TYPE) && \
			(mask=(pace->Mask & perm_mask)) && \
			     EqualSid((SID *)&pace->SidStart, usid) ) {
			(void)accessinfo_add(allowed, sizeInfo.AceCount,
				name, (mask & 0xFFFF));
		} else if (pace->Header.AceType == ACCESS_DENIED_ACE_TYPE) {
			(void)accessinfo_add(denied, sizeInfo.AceCount,
				name, (pace->Mask & 0xFFFF));
		} else {
			if (name) {
				(void)free(name);
			}
		}

	}
	/* filter the allowed pool so that none appear in denied */
	for (i=0; i < sizeInfo.AceCount; i++) {
		for (j=0; j < sizeInfo.AceCount; j++) {
			if( allowed[i].group == NULL || \
						denied[j].group == NULL )
				continue;

			if (strcmp(allowed[i].group, denied[j].group) == 0)
				allowed[i].mask &= ~denied[j].mask;
			/* unset the denied mask from allowed */
		}
	}

	/* now filter perm_mask to those specified in allowed */
	for (i=0; i < sizeInfo.AceCount; i++) {
		if (allowed[i].group == NULL)
			continue;

		/* unset the allowed mask from perm_mask */
		perm_mask &= ~allowed[i].mask;
	}

	if (perm_mask != 0) {
		rc = 4;
		goto perm_chkerr;
	}

	rc = 0;

perm_chkerr:
	if (pdacl) LocalFree(pdacl);
	if (psd) LocalFree(psd);
	if (allowed) accessinfo_free(allowed, sizeInfo.AceCount);
	if (denied) accessinfo_free(denied, sizeInfo.AceCount);
	if (usid) LocalFree(usid);

	return (rc);
}
Exemple #29
0
int main(int argc, char ** argv)
{
	int c;
	int flags = MS_MANDLOCK; /* no need to set legacy MS_MGC_VAL */
	char * orgoptions = NULL;
	char * share_name = NULL;
	char * ipaddr = NULL;
	char * uuid = NULL;
	char * mountpoint = NULL;
	char * options;
	char * resolved_path;
	char * temp;
	int rc;
	int rsize = 0;
	int wsize = 0;
	int nomtab = 0;
	int uid = 0;
	int gid = 0;
	int optlen = 0;
	int orgoptlen = 0;
	int retry = 0; /* set when we have to retry mount with uppercase */
	struct stat statbuf;
	struct utsname sysinfo;
	struct mntent mountent;
	FILE * pmntfile;

	/* setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE); */

	if(argc && argv) {
		thisprogram = argv[0];
	} else {
		mount_cifs_usage();
		exit(1);
	}

	if(thisprogram == NULL)
		thisprogram = "mount.cifs";

	uname(&sysinfo);
	/* BB add workstation name and domain and pass down */

/* #ifdef _GNU_SOURCE
	printf(" node: %s machine: %s sysname %s domain %s\n", sysinfo.nodename,sysinfo.machine,sysinfo.sysname,sysinfo.domainname);
#endif */
	if(argc > 2) {
		share_name = argv[1];
		mountpoint = argv[2];
	}

	/* add sharename in opts string as unc= parm */

	while ((c = getopt_long (argc, argv, "afFhilL:no:O:rsSU:vVwt:",
			 longopts, NULL)) != -1) {
		switch (c) {
/* No code to do the following  options yet */
/*	case 'l':
		list_with_volumelabel = 1;
		break;
	case 'L':
		volumelabel = optarg;
		break; */
/*	case 'a':	       
		++mount_all;
		break; */

		case '?':
		case 'h':	 /* help */
			mount_cifs_usage ();
			exit(1);
		case 'n':
		    ++nomtab;
		    break;
		case 'b':
			flags |= MS_BIND;
			break;
		case 'm':
			flags |= MS_MOVE;
			break;
		case 'o':
			orgoptions = strdup(optarg);
		    break;
		case 'r':  /* mount readonly */
			flags |= MS_RDONLY;
			break;
		case 'U':
			uuid = optarg;
			break;
		case 'v':
			++verboseflag;
			break;
		case 'V':	   
			printf ("mount.cifs version: %s.%s%s\n",
			MOUNT_CIFS_VERSION_MAJOR,
			MOUNT_CIFS_VERSION_MINOR,
			MOUNT_CIFS_VENDOR_SUFFIX);
			if(mountpassword) {
				memset(mountpassword,0,64);
			}
			exit (0);
		case 'w':
			flags &= ~MS_RDONLY;
			break;
		case 'R':
			rsize = atoi(optarg) ;
			break;
		case 'W':
			wsize = atoi(optarg);
			break;
		case '1':
			if (isdigit(*optarg)) {
				char *ep;

				uid = strtoul(optarg, &ep, 10);
				if (*ep) {
					printf("bad uid value \"%s\"\n", optarg);
					exit(1);
				}
			} else {
				struct passwd *pw;

				if (!(pw = getpwnam(optarg))) {
					printf("bad user name \"%s\"\n", optarg);
					exit(1);
				}
				uid = pw->pw_uid;
				endpwent();
			}
			break;
		case '2':
			if (isdigit(*optarg)) {
				char *ep;

				gid = strtoul(optarg, &ep, 10);
				if (*ep) {
					printf("bad gid value \"%s\"\n", optarg);
					exit(1);
				}
			} else {
				struct group *gr;

				if (!(gr = getgrnam(optarg))) {
					printf("bad user name \"%s\"\n", optarg);
					exit(1);
				}
				gid = gr->gr_gid;
				endpwent();
			}
			break;
		case 'u':
			got_user = 1;
			user_name = optarg;
			break;
		case 'd':
			domain_name = optarg; /* BB fix this - currently ignored */
			got_domain = 1;
			break;
		case 'p':
			if(mountpassword == NULL)
				mountpassword = calloc(65,1);
			if(mountpassword) {
				got_password = 1;
				strncpy(mountpassword,optarg,64);
			}
			break;
		case 'S':
			get_password_from_file(0 /* stdin */,NULL);
			break;
		case 't':
			break;
		default:
			printf("unknown mount option %c\n",c);
			mount_cifs_usage();
			exit(1);
		}
	}

	if((argc < 3) || (share_name == NULL) || (mountpoint == NULL)) {
		mount_cifs_usage();
		exit(1);
	}

	if (getenv("PASSWD")) {
		if(mountpassword == NULL)
			mountpassword = calloc(65,1);
		if(mountpassword) {
			strncpy(mountpassword,getenv("PASSWD"),64);
			got_password = 1;
		}
	} else if (getenv("PASSWD_FD")) {
		get_password_from_file(atoi(getenv("PASSWD_FD")),NULL);
	} else if (getenv("PASSWD_FILE")) {
		get_password_from_file(0, getenv("PASSWD_FILE"));
	}

        if (orgoptions && parse_options(&orgoptions, &flags))
                return -1;
	ipaddr = parse_server(&share_name);
	if((ipaddr == NULL) && (got_ip == 0)) {
		printf("No ip address specified and hostname not found\n");
		return -1;
	}
	
	/* BB save off path and pop after mount returns? */
	resolved_path = malloc(PATH_MAX+1);
	if(resolved_path) {
		/* Note that if we can not canonicalize the name, we get
		another chance to see if it is valid when we chdir to it */
		if (realpath(mountpoint, resolved_path)) {
			mountpoint = resolved_path; 
		}
	}
	if(chdir(mountpoint)) {
		printf("mount error: can not change directory into mount target %s\n",mountpoint);
		return -1;
	}

	if(stat (".", &statbuf)) {
		printf("mount error: mount point %s does not exist\n",mountpoint);
		return -1;
	}

	if (S_ISDIR(statbuf.st_mode) == 0) {
		printf("mount error: mount point %s is not a directory\n",mountpoint);
		return -1;
	}

	if((getuid() != 0) && (geteuid() == 0)) {
		if((statbuf.st_uid == getuid()) && (S_IRWXU == (statbuf.st_mode & S_IRWXU))) {
#ifndef CIFS_ALLOW_USR_SUID
			/* Do not allow user mounts to control suid flag
			for mount unless explicitly built that way */
			flags |= MS_NOSUID | MS_NODEV;
#endif						
		} else {
			printf("mount error: permission denied or not superuser and mount.cifs not installed SUID\n"); 
			return -1;
		}
	}

	if(got_user == 0) {
		user_name = getusername();
		got_user = 1;
	}
       
	if(got_password == 0) {
		mountpassword = getpass("Password: "******"No server share name specified\n");
		printf("\nMounting the DFS root for server not implemented yet\n");
                exit(1);
	}
	if(user_name)
		optlen += strlen(user_name) + 6;
	if(ipaddr)
		optlen += strlen(ipaddr) + 4;
	if(mountpassword)
		optlen += strlen(mountpassword) + 6;
	options = malloc(optlen + 10 + 64 /* space for commas in password */ + 8 /* space for domain=  , domain name itself was counted as part of the length username string above */);

	if(options == NULL) {
		printf("Could not allocate memory for mount options\n");
		return -1;
	}
		

	options[0] = 0;
	strncat(options,"unc=",4);
	strcat(options,share_name);
	/* scan backwards and reverse direction of slash */
	temp = strrchr(options, '/');
	if(temp > options + 6)
		*temp = '\\';
	if(ipaddr) {
		strncat(options,",ip=",4);
		strcat(options,ipaddr);
	}

	if(user_name) {
		/* check for syntax like user=domain\user */
		if(got_domain == 0)
			domain_name = check_for_domain(&user_name);
		strncat(options,",user="******",domain=",8);
			strcat(options,domain_name);
		}
	}
	if(mountpassword) {
		/* Commas have to be doubled, or else they will
		look like the parameter separator */
/*		if(sep is not set)*/
		if(retry == 0)
			check_for_comma(&mountpassword);
		strncat(options,",pass="******",ver=",5);
	strcat(options,MOUNT_CIFS_VERSION_MAJOR);

	if(orgoptions) {
		strcat(options,",");
		strcat(options,orgoptions);
	}
	if(verboseflag)
		printf("\nmount.cifs kernel mount options %s \n",options);
	if(mount(share_name, mountpoint, "cifs", flags, options)) {
	/* remember to kill daemon on error */
		char * tmp;

		switch (errno) {
		case 0:
			printf("mount failed but no error number set\n");
			break;
		case ENODEV:
			printf("mount error: cifs filesystem not supported by the system\n");
			break;
		case ENXIO:
			if(retry == 0) {
				retry = 1;
				tmp = share_name;
				while (*tmp && !(((unsigned char)tmp[0]) & 0x80)) {
					*tmp = toupper((unsigned char)*tmp);
		        		tmp++;
				}
				if(!*tmp) {
					printf("retrying with upper case share name\n");
					goto mount_retry;
				}
			}
		default:
			
			printf("mount error %d = %s\n",errno,strerror(errno));
		}
		printf("Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)\n");
		if(mountpassword) {
			memset(mountpassword,0,64);
		}
		return -1;
	} else {
		pmntfile = setmntent(MOUNTED, "a+");
		if(pmntfile) {
			mountent.mnt_fsname = share_name;
			mountent.mnt_dir = mountpoint; 
			mountent.mnt_type = CONST_DISCARD(char *,"cifs"); 
			mountent.mnt_opts = malloc(220);
			if(mountent.mnt_opts) {
				char * mount_user = getusername();
				memset(mountent.mnt_opts,0,200);
				if(flags & MS_RDONLY)
					strcat(mountent.mnt_opts,"ro");
				else
					strcat(mountent.mnt_opts,"rw");
				if(flags & MS_MANDLOCK)
					strcat(mountent.mnt_opts,",mand");
				if(flags & MS_NOEXEC)
					strcat(mountent.mnt_opts,",noexec");
				if(flags & MS_NOSUID)
					strcat(mountent.mnt_opts,",nosuid");
				if(flags & MS_NODEV)
					strcat(mountent.mnt_opts,",nodev");
				if(flags & MS_SYNCHRONOUS)
					strcat(mountent.mnt_opts,",synch");
				if(mount_user) {
					if(getuid() != 0) {
						strcat(mountent.mnt_opts,",user="******"could not update mount table\n");
		}
	}
Exemple #30
0
static ACL *
create_secure_dacl(char *user, ACCESS_MASK mask, SID *owner_sid)
{

	DWORD rids[1] = {0};
	gid_t grp[_MAX_GROUPS] = {0};
	int i = 0;
	int k = 0;
	int cbAcl = 0;
	ACL *ndacl = NULL;
	char logb[LOG_BUF_SIZE] = {'\0' };

	rids[0] = DOMAIN_ALIAS_RID_ADMINS;
	k = getgids(getlogin(), grp, rids);

	if ((k < _MAX_GROUPS) && (owner_sid != NULL)) {
		grp[k] = sid_dup(owner_sid);
		if (grp[k] == NULL) {
			sprintf(logb, "failed to copy owner_sid");
			log_err(-1, __func__, logb);
			return NULL;
		}
		k++;
	}

	if (user != NULL && mask != 0) {
		SID *sid = getgrpsid(user);
		if (sid == NULL)
			sid = getusersid(user);
		if (sid) {
			if (k == _MAX_GROUPS) {
				grp[k-1] = sid;
			} else {
				grp[k] = sid;
				k++;
			}
		}

	}

	cbAcl = sizeof(ACL);
	for (i = 0 ; i < k; i++) {
		// subtract ACE.SidStart from the size
		int cbAce = sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD);
		// add this ACE's SID length
		cbAce += GetLengthSid(grp[i]);
		// add the length of each ACE to the total ACL length
		cbAcl += cbAce;
	}

	ndacl = (ACL *)malloc(cbAcl);
	if (ndacl == NULL) {
		sprintf(logb, "failed to malloc %d bytes", cbAcl);
		log_err(-1, __func__, logb);
		return NULL;
	}
	InitializeAcl(ndacl, cbAcl, ACL_REVISION);

	for (i=0; i < k; i++) {
		char *name = getgrpname_full(grp[i]);

		if (name == NULL)
			name = getusername(grp[i]);

		if (name == NULL)
			continue;

		if (user != NULL && mask != 0 && i == (k-1)) {
			if (AddAccessAllowedAce(ndacl, ACL_REVISION, mask | 0x00100000, grp[i]) == 0) {
				sprintf(logb, "failed to add %d to %s", mask,
					name);
				log_err(-1, __func__, logb);
			}

		} else {
			if (AddAccessAllowedAce(ndacl, ACL_REVISION,
				READS_MASK | WRITES_MASK | STANDARD_RIGHTS_ALL, grp[i]) == 0) {
				sprintf(logb, "failed to add WRITES_MASK and READS_MASK to %s", name);
				log_err(-1, __func__, logb);
			}
		}
		(void)free(name);
		LocalFree(grp[i]);
	}
	return (ndacl);
}