void MAIN::Start(){ try{ //lock //EnterCriticalSection(&cs); //while(MESSAGE *Data = getmessage()){ while(map<string,wstring> *Data=getmessage()){ RUNNER_OUT* rData; try{ rData = work(Data); }catch(runtime_error e){ stringstream ss; ss<<e.what()<<" "<<GetLastError(); rData=(RUNNER_OUT*)new BYTE[ss.str().length()+4]; rData->sz=ss.str().length(); strcpy(rData->DATA,ss.str().c_str()); } sendback(rData,sizeof(RUNNER_OUT)+rData->sz-1); delete Data; delete[] rData; } } catch(runtime_error e){ if(WSAGetLastError()){ Log->Report(e.what(),WSAGetLastError()); } } //unlock //DELETE_TEMP Delete; //Delete.Start(); //LeaveCriticalSection(&cs); }
void s_enable_dest(char *m, MESG *md) { char *printer; ushort status; register PSTATUS *pps; getmessage (m, S_ENABLE_DEST, &printer); syslog(LOG_DEBUG, "s_enable_dest(%s)", (printer ? printer : "NULL")); /* * Have we seen this printer before? */ if ((pps = search_ptable(printer))) if (enable(pps) == -1) status = MERRDEST; else status = MOK; else status = MNODEST; mputm (md, R_ENABLE_DEST, status); return; }
void s_alloc_files(char *m, MESG *md) /* funcdef */ { char *file_prefix; ushort_t count; mode_t old_msk; /* * Bugid 4140311 * Set umask to 0 before creating files. */ old_msk = umask((mode_t)0); getmessage(m, S_ALLOC_FILES, &count); syslog(LOG_DEBUG, "s_alloc_files(%d)", count); if ((file_prefix = _alloc_files(count, (char *)0, md->uid, md->gid))) { mputm(md, R_ALLOC_FILES, MOK, file_prefix); add_flt_act(md, FLT_FILES, file_prefix, count); } else if (errno == EEXIST) mputm(md, R_ALLOC_FILES, MERRDEST, ""); else mputm(md, R_ALLOC_FILES, MNOMEM, ""); (void) umask(old_msk); }
/* * The client is sending a peer connection to retrieve label information * from. This is used in the event that the client is an intermediary for * the actual requestor in a Trusted environment. */ void s_pass_peer_connection(char *m, MESG *md) { short status = MTRANSMITERR; char *dest; struct strrecvfd recv_fd; (void) getmessage(m, S_PASS_PEER_CONNECTION); syslog(LOG_DEBUG, "s_pass_peer_connection()"); memset(&recv_fd, NULL, sizeof (recv_fd)); if (ioctl(md->readfd, I_RECVFD, &recv_fd) == 0) { int fd = recv_fd.fd; if (get_peer_label(fd, &md->slabel) == 0) { if (md->admin == 1) md->admin = -1; /* turn off query privilege */ status = MOK; } close(fd); } mputm(md, R_PASS_PEER_CONNECTION, status); }
static ngx_int_t ngx_cat_body_filter(ngx_http_request_t *r, ngx_chain_t *chain) { ngx_http_cat_t *conf; conf = ngx_http_get_module_loc_conf(r, ngx_cat_filter_module); if(conf->enable == 1){ send_times ++; char buf[SENDOUTBUFSIZE]; memset(buf, 0, SENDOUTBUFSIZE); if(r->upstream == NULL){ getmessage(r, buf); } else{ if(r->upstream->state->response_length || r->upstream->state->status == NGX_HTTP_BAD_GATEWAY || r->upstream->state->status == NGX_HTTP_SERVICE_UNAVAILABLE || r->upstream->state->status == NGX_HTTP_GATEWAY_TIME_OUT){ getupstreammessage(r, buf); } else{ if(!start_upstream_sec){ start_upstream_sec = r->upstream->state->response_sec; start_upstream_msec = r->upstream->state->response_msec; } } } } return ngx_http_next_body_filter(r, chain); }
/* 進站水球宣傳 */ int m_loginmsg(void) { char msg[100]; move(21,0); clrtobot(); if(SHM->loginmsg.pid && SHM->loginmsg.pid != currutmp->pid) { outs("目前已經有以下的 進站水球設定請先協調好再設定.."); getmessage(SHM->loginmsg); } getdata(22, 0, "進站水球:本站活動,不干擾使用者為限,設定者離站自動取消,確定要設?(y/N)", msg, 3, LCECHO); if(msg[0]=='y' && getdata_str(23, 0, "設定進站水球:", msg, 56, DOECHO, SHM->loginmsg.last_call_in)) { SHM->loginmsg.pid=currutmp->pid; /*站長不多 就不管race condition */ strlcpy(SHM->loginmsg.last_call_in, msg, sizeof(SHM->loginmsg.last_call_in)); strlcpy(SHM->loginmsg.userid, cuser.userid, sizeof(SHM->loginmsg.userid)); } return 0; }
int main(int argc, char *argv[]) { window demo; demo.width = 400; demo.height = 300; UI_createWindow(&demo, "Demo", 0); message msg; int step = 0; while (1) { int i, j; for (i = 0; i < 300; ++i) for (j = 0; j < 400; ++j) { RGB * t = demo.window_buf + (i * 400) + j; t->R = (i + j + step) % 255; t->B = (i + step) % 200 + 25; t->G = (step - j) % 100 + 100; } step++; drawAllWidget(&demo); if (getmessage(demo.handler, &msg) != 0) { if (msg.msg_type == WM_WINDOW_CLOSE) { UI_destroyWindow(&demo); break; } } } // mainLoop(&editor); return 0; }
void handle (int sock) { getmessage(sock); int n = write(sock,"I got your message\n",19); if (n < 0) { perror("ERROR writing to socket"); exit(1); } }
int getkey (int interval) { int message; double rem, target; // prevent strange behaviour due to programmer mistakes if (interval < 0) interval = -1; switch (interval) { case -1: while (1) { message = getmessage (-1); if (IS_KEY (message) && message > 0) break; } break; case 0: while (TRUE) { message = getmessage (0); if (message == 0) break; if (IS_KEY (message)) break; } break; default: target = clock1 () + ((double)interval)/1000.; message = -1; while (TRUE) { rem = target - clock1(); if (rem <= 0.) break; message = getmessage ((int)(rem*1000.)); if (IS_KEY(message) && message > 0) break; } } return message; }
void s_disable_dest(char *m, MESG *md) { char *destination, *reason, *req_id = 0; ushort when, status; register PSTATUS *pps; getmessage (m, S_DISABLE_DEST, &destination, &reason, &when); syslog(LOG_DEBUG, "s_disable_dest(%s, %s, %d)", (destination ? destination : "NULL"), (reason ? reason : "NULL"), when); /* * Have we seen this printer before? */ if ((pps = search_ptable(destination))) { /* * If we are to cancel a currently printing request, * we will send back the request's ID. * Save a copy of the ID before calling "disable()", * in case the disabling loses it (e.g. the request * might get attached to another printer). (Actually, * the current implementation won't DETACH the request * from this printer until the child process responds, * but a future implementation might.) */ if (pps->request && when == 2) req_id = Strdup(pps->request->secure->req_id); if (disable(pps, reason, (int)when) == -1) { if (req_id) { Free (req_id); req_id = 0; } status = MERRDEST; } else status = MOK; } else status = MNODEST; mputm (md, R_DISABLE_DEST, status, NB(req_id)); if (req_id) Free (req_id); return; }
void s_move_dest(char *m, MESG *md) { char *dest; char *fromdest; RSTATUS *rp; char *found = (char *)0; short num_ok = 0; (void) getmessage(m, S_MOVE_DEST, &fromdest, &dest); syslog(LOG_DEBUG, "s_move_dest(%s, %s)", (fromdest ? fromdest : "NULL"), (dest ? dest : "NULL")); if (!search_pstatus(fromdest) && !search_cstatus(fromdest)) { mputm(md, R_MOVE_DEST, MNODEST, fromdest, 0); return; } if (!(search_pstatus(dest)) && !(search_cstatus(dest))) { mputm(md, R_MOVE_DEST, MNODEST, dest, 0); return; } if (STREQU(dest, fromdest)) { mputm(md, R_MOVE_DEST, MOK, "", 0); return; } for (rp = Request_List; rp != NULL; rp = rp->next) { if ((STREQU(rp->request->destination, fromdest)) && (!(rp->request->outcome & (RS_DONE|RS_CHANGING|RS_NOTIFYING)))) { if (mv_file(rp, dest) == MOK) { num_ok++; continue; } } if (found) mputm(md, R_MOVE_DEST, MMORERR, found, 0); found = rp->secure->req_id; } if (found) mputm(md, R_MOVE_DEST, MERRDEST, found, num_ok); else mputm(md, R_MOVE_DEST, MOK, "", num_ok); }
void s_reject_dest(char *m, MESG *md) { char *destination, *reason; ushort status; register PSTATUS *pps; register CSTATUS *pcs; getmessage (m, S_REJECT_DEST, &destination, &reason); syslog(LOG_DEBUG, "s_reject_dest(%s, %s)", (destination ? destination : "NULL"), (reason ? reason : "NULL")); /* * Have we seen this destination as a printer? */ if ((pps = search_ptable(destination))) if (pps->status & PS_REJECTED) status = MERRDEST; else { pps->status |= PS_REJECTED; (void) time (&pps->rej_date); load_str (&pps->rej_reason, reason); dump_pstatus (); status = MOK; } /* * Have we seen this destination as a class? */ else if ((pcs = search_ctable(destination))) if (pcs->status & CS_REJECTED) status = MERRDEST; else { pcs->status |= CS_REJECTED; (void) time (&pcs->rej_date); load_str (&pcs->rej_reason, reason); dump_cstatus (); status = MOK; } else status = MNODEST; mputm (md, R_REJECT_DEST, status); return; }
void s_cancel_request(char *m, MESG *md) { char *req_id, *rid; short status; (void) getmessage(m, S_CANCEL_REQUEST, &req_id); syslog(LOG_DEBUG, "s_cancel_request(%s)", (req_id ? req_id : "NULL")); if ((rid = _cancel(md, "", "", req_id)) != NULL) Free(rid); status = (short)errno; mputm(md, R_CANCEL_REQUEST, status); }
/* * Toss one packet. * * 0 - * 1 - Cannot open packet * 2 - Bad packet header * 3 - Packet is not for us * 4 - Bad password */ int TossPkt(char *fn) { int rc, count = 0; static int maxrc = 0; static faddr from, to; FILE *pkt; if (!do_quiet) { ftnd_colour(LIGHTGREEN, BLACK); printf("Tossing packet %s\n", fn); } if ((pkt = fopen(fn, "r")) == 0) { WriteError("$Cannot open %s", fn); return 1; } memset(&from, 0, sizeof(faddr)); memset(&to, 0, sizeof(faddr)); if (((rc = getheader(&from, &to, pkt, fn, FALSE)) != 0)) { WriteError("%s, aborting", (rc == 1)?"wrong header type": (rc == 2)?"bad packet header": (rc == 3)?"packet is not for us": (rc == 4)?"bad password": "******"); fclose(pkt); return(rc); } while ((rc = getmessage(pkt, &from, &to)) == 1) { count++; } Syslog('+', "Messages : %d", count); maxrc = rc; if (!do_quiet) printf("\r \r"); if (rc) Syslog('+', "End, rc=%d", maxrc); fclose(pkt); return maxrc; }
/* * s_paper_changed() */ void s_paper_changed(char *m, MESG *md) { short trayNum, mode, pagesPrinted; char *printer, *paper; ushort status; short chgd = 0; register PSTATUS *pps; register FSTATUS *pfs,*pfsWas; getmessage(m, S_PAPER_CHANGED, &printer, &trayNum, &paper, &mode, &pagesPrinted); syslog(LOG_DEBUG, "s_paper_changed(%s, %d, %s, %d, %d)", (printer ? printer : "NULL"), trayNum, (paper ? paper : "NULL"), mode, pagesPrinted); if (!(pps = search_ptable(printer))) status = MNODEST; else if ((trayNum <=0) || (trayNum > pps->numForms)) status = MNOTRAY; else { status = MOK; if (*paper && (pfsWas = pps->forms[trayNum-1].form) && (!STREQU(pfsWas->form->paper,paper))) { pfs = search_fptable(paper); if (pfs) { remount_form(pps, pfs, trayNum); chgd = 1; } else status = MNOMEDIA; } if ( status == MOK ) { pps->forms[trayNum].isAvailable = mode; if ((chgd || !mode) && (!pagesPrinted) && LP_KILL_NO_PAPER && pps->exec) { if (pps->request) pps->request->request->outcome |= RS_STOPPED; terminate(pps->exec); schedule(EV_LATER, 1, EV_INTERF, pps); } } } mputm(md, R_PAPER_CHANGED, status); }
void s_move_request(char *m, MESG *md) { RSTATUS *rp; short err; char *req_id; char *dest; (void) getmessage(m, S_MOVE_REQUEST, &req_id, &dest); syslog(LOG_DEBUG, "s_move_request(%s, %s)", (req_id ? req_id : "NULL"), (dest ? dest : "NULL")); if (!(search_pstatus(dest)) && !(search_cstatus(dest))) { mputm(md, R_MOVE_REQUEST, MNODEST, 0L); return; } if ((rp = request_by_id(req_id))) { if (STREQU(rp->request->destination, dest)) { mputm(md, R_MOVE_REQUEST, MOK, 0L); return; } if (rp->request->outcome & (RS_DONE|RS_NOTIFYING)) { mputm(md, R_MOVE_REQUEST, M2LATE, 0L); return; } if (rp->request->outcome & RS_CHANGING) { mputm(md, R_MOVE_REQUEST, MBUSY, 0L); return; } if ((err = mv_file(rp, dest)) == MOK) { mputm(md, R_MOVE_REQUEST, MOK, 0L); return; } mputm(md, R_MOVE_REQUEST, err, chkprinter_result); return; } mputm(md, R_MOVE_REQUEST, MUNKNOWN, 0L); }
void s_cancel(char *m, MESG *md) { char *req_id; char *user; char *destination; char *rid; char *nrid; int nerrno; int oerrno; (void) getmessage(m, S_CANCEL, &destination, &user, &req_id); syslog(LOG_DEBUG, "s_cancel(%s, %s, %s)", (destination ? destination : "NULL"), (user ? user : "******"), (req_id ? req_id : "NULL")); if (STREQU(destination, NAME_ALL)) destination = ""; if (STREQU(req_id, NAME_ALL)) req_id = ""; if (rid = _cancel(md, destination, user, req_id)) { oerrno = errno; while ((nrid = _cancel(md, NULL, NULL, NULL)) != NULL) { nerrno = errno; mputm(md, R_CANCEL, MOKMORE, oerrno, rid); Free(rid); rid = nrid; oerrno = nerrno; } mputm(md, R_CANCEL, MOK, oerrno, rid); Free(rid); return; } mputm(md, R_CANCEL, MOK, MUNKNOWN, ""); }
void s_shutdown(char *m, MESG *md) { ushort immediate; (void)getmessage (m, S_SHUTDOWN, &immediate); syslog(LOG_DEBUG, "s_shutdown(%d)", immediate); switch (md->type) { case MD_STREAM: case MD_SYS_FIFO: case MD_USR_FIFO: mputm (md, R_SHUTDOWN, MOK); lpshut (immediate); /*NOTREACHED*/ default: syslog(LOG_DEBUG, "Received S_SHUTDOWN on a type %d connection\n", md->type); } return; }
void s_send_fault(char *m, MESG *md) { long key; char *printerOrForm, *alert_text; ushort status; register PSTATUS *pps; getmessage (m, S_SEND_FAULT, &printerOrForm, &key, &alert_text); syslog(LOG_DEBUG, "s_send_fault(%s, %x, %s)", (printerOrForm ? printerOrForm : "NULL"), key, (alert_text ? alert_text : "NULL")); if (!(pps = search_ptable(printerOrForm)) || (!pps->exec) || pps->exec->key != key || !pps->request) { status = MERRDEST; } else { printer_fault(pps, pps->request, alert_text, 0); status = MOK; } mputm (md, R_SEND_FAULT, status); }
static void serverconnect(char *path) { struct hostent *servhost; struct sockaddr_in server = {0}; int fd; #ifdef KONOHA_ON_WINDOWS WSADATA data; WSAStartup(MAKEWORD(2,0), &data); #endif servhost = gethostbyname(UPDATE_HOST); if (servhost == NULL) { DBG_P("[%s] Failed to convert Name to IPAdress \n", UPDATE_HOST); return; } server.sin_family = AF_INET; memcpy(&server.sin_addr, servhost->h_addr, servhost->h_length); server.sin_port = htons(PORT); if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { DBG_P("[%s] Failed to make socket\n", UPDATE_HOST); return; } if (connect(fd, (struct sockaddr *)&server, sizeof(server)) == -1) { DBG_P("[%s] Failed to connect\n", UPDATE_HOST); return; } getmessage(fd, path); #ifdef KONOHA_ON_WINDOWS closesocket(fd); WSACleanup(); #else close(fd); #endif return; }
static Byte MultiMode; /* 0=8M, 1=16, 2=8L, 3=8H */ static Byte MinMoto; static Boolean Rec5; static Boolean SepMoto; static LongWord AVRLen, ValidSegs; static Boolean RelAdr, MotoOccured, IntelOccured, MOSOccured, DSKOccured; static Byte MaxMoto, MaxIntel; static THexFormat DestFormat; static ChunkList UsedList; static void ParamError(Boolean InEnv, char *Arg) BEGIN printf("%s%s\n",getmessage(InEnv?Num_ErrMsgInvEnvParam:Num_ErrMsgInvParam),Arg); printf("%s\n",getmessage(Num_ErrMsgProgTerm)); exit(1); END static void OpenTarget(void) BEGIN TargFile=fopen(TargName,"w"); if (TargFile==Nil) ChkIO(TargName); END static void CloseTarget(void) BEGIN errno=0; fclose(TargFile); ChkIO(TargName); if (Magic!=0) unlink(TargName); END
bool group_proccessor::operator()() { boost::xtime xt; while (!terminated()) { try { if (init()) { while (getmessage(message)) { if (terminated()) break; switch (strategy()) { case STRATEGY_TYPE_REPORT: { if (message.mess == MSG_DVNCITAGREPORT) { if (message.some) { addtag(message.id); } else { removetag(message.id); } } break; } default: { if (selector->group_included(message.some)) { switch (message.mess) { case MSG_DVNCTAGDELFROMGR: case MSG_DVNCIREMREF: { removetag(message.id); break; } case MSG_DVNCTAGADDTOGR: case MSG_DVNCINEWREF: { addtag(message.id); break; } default: { if ((message.mess != MSG_DVNCIREMREF) && (message.mess != MSG_DVNCINEWREF)) optinalchangeid(message.id); } } } else { if ((message.mess != MSG_DVNCIREMREF) && (message.mess != MSG_DVNCINEWREF)) optinalchangeid(message.id); } break; } } } execute_impl(); addmillisec_to_now(xt, 1); } else addmillisec_to_now(xt, 1000); boost::thread::sleep(xt); } catch (boost::system::system_error& boosterr) { if (intf) intf->debugerror("group_proccessor error what=" + std::string(boosterr.what())); } catch (...) { if (intf) intf->debugerror("group_proccessor NODEF error "); } } uninit(); return true; }
void s_start_change_request(char *m, MESG *md) { char *req_id; char *req_file = ""; short status; RSTATUS *rp; char *path; char tmpName[BUFSIZ]; struct stat tmpBuf; (void) getmessage(m, S_START_CHANGE_REQUEST, &req_id); syslog(LOG_DEBUG, "s_start_change_request(%s)", (req_id ? req_id : "NULL")); if (!(rp = request_by_id(req_id))) status = MUNKNOWN; else if ((md->admin == 0) && (is_system_labeled()) && (md->slabel != NULL) && (rp->secure->slabel != NULL) && (!STREQU(md->slabel, rp->secure->slabel))) status = MUNKNOWN; else if (rp->request->outcome & RS_DONE) status = M2LATE; else if (!md->admin && md->uid != rp->secure->uid) status = MNOPERM; else if (rp->request->outcome & RS_CHANGING) status = MNOOPEN; else if (rp->request->outcome & RS_NOTIFYING) status = MBUSY; else { status = MOK; if (rp->request->outcome & RS_FILTERING && !(rp->request->outcome & RS_STOPPED)) { rp->request->outcome |= (RS_REFILTER|RS_STOPPED); terminate(rp->exec); } if (rp->request->outcome & RS_PRINTING && !(rp->request->outcome & RS_STOPPED)) { rp->request->outcome |= RS_STOPPED; terminate(rp->printer->exec); } rp->request->outcome |= RS_CHANGING; /* * Change the ownership of the request file to be "md->uid". * Either this is identical to "rp->secure->uid", or it is * "Lp_Uid" or it is root. The idea is that the * person at the other end needs access, and that may not * be who queued the request. */ path = makepath(Lp_Tmp, rp->req_file, (char *)0); (void) Chown(path, md->uid, rp->secure->gid); Free(path); #ifdef LP_USE_PAPI_ATTR /* * Check if the PAPI job attribute file exists, if it does * change the ownership of the file to be "md->uid". * Either this is identical to "rp->secure->uid", or it is * "Lp_Uid" or it is root. The idea is that the * person at the other end needs access, and that may not * be who queued the request. */ snprintf(tmpName, sizeof (tmpName), "%s-%s", strtok(strdup(rp->req_file), "-"), LP_PAPIATTRNAME); path = makepath(Lp_Tmp, tmpName, (char *)0); if (stat(path, &tmpBuf) == 0) { syslog(LOG_DEBUG, "s_start_change_request: attribute file ='%s'", path); /* * IPP job attribute file exists for this job so * change permissions and ownership of the file */ (void) Chown(path, md->uid, rp->secure->gid); Free(path); } else { syslog(LOG_DEBUG, "s_start_change_request: no attribute file"); } #endif add_flt_act(md, FLT_CHANGE, rp); req_file = rp->req_file; } mputm(md, R_START_CHANGE_REQUEST, status, req_file); }
void s_quiet_alert(char *m, MESG *md) { char *name; ushort type, status; register FSTATUS *pfs; register PSTATUS *pps; register PWSTATUS *ppws; /* * We quiet an alert by cancelling it with "cancel_alert()" * and then resetting the active flag. This effectively just * terminates the process running the alert but tricks the * rest of the Spooler into thinking it is still active. * The alert will be reactivated only AFTER "cancel_alert()" * has been called (to clear the active flag) and then "alert()" * is called again. Thus: * * For printer faults the alert will be reactivated when: * - a fault is found after the current fault has been * cleared (i.e. after successful print or after manually * enabled). * * For forms/print-wheels the alert will be reactivated when: * - the form/print-wheel becomes mounted and then unmounted * again, with too many requests still pending; * - the number of requests falls below the threshold and * then rises above it again. */ (void)getmessage (m, S_QUIET_ALERT, &name, &type); syslog(LOG_DEBUG, "s_quiet_alert(%s, %d)", (name ? name : "NULL"), type); if (!*name) status = MNODEST; else switch (type) { case QA_FORM: if (!(pfs = search_ftable(name))) status = MNODEST; else if (!pfs->alert->active) status = MERRDEST; else { cancel_alert (A_FORM, pfs); pfs->alert->active = 1; status = MOK; } break; case QA_PRINTER: if (!(pps = search_ptable(name))) status = MNODEST; else if (!pps->alert->active) status = MERRDEST; else { cancel_alert (A_PRINTER, pps); pps->alert->active = 1; status = MOK; } break; case QA_PRINTWHEEL: if (!(ppws = search_pwtable(name))) status = MNODEST; else if (!ppws->alert->active) status = MERRDEST; else { cancel_alert (A_PWHEEL, ppws); ppws->alert->active = 1; status = MOK; } break; } mputm (md, R_QUIET_ALERT, status); return; }
void s_end_change_request(char *m, MESG *md) { char *req_id; RSTATUS *rp; off_t size; off_t osize; short err; short status; REQUEST *r = 0; REQUEST oldr; int call_schedule = 0; int move_ok = 0; char *path; char tmpName[BUFSIZ]; struct stat tmpBuf; (void) getmessage(m, S_END_CHANGE_REQUEST, &req_id); syslog(LOG_DEBUG, "s_end_change_request(%s)", (req_id ? req_id : "NULL")); if (!(rp = request_by_id(req_id))) status = MUNKNOWN; else if ((md->admin == 0) && (is_system_labeled()) && (md->slabel != NULL) && (rp->secure->slabel != NULL) && (!STREQU(md->slabel, rp->secure->slabel))) status = MUNKNOWN; else if (!(rp->request->outcome & RS_CHANGING)) status = MNOSTART; else { path = makepath(Lp_Tmp, rp->req_file, (char *)0); (void) chownmod(path, Lp_Uid, Lp_Gid, 0644); Free(path); #ifdef LP_USE_PAPI_ATTR /* * Check if the PAPI job attribute file exists, * if it does change the permission and the ownership * of the file to be "Lp_Uid". */ snprintf(tmpName, sizeof (tmpName), "%s-%s", strtok(strdup(rp->req_file), "-"), LP_PAPIATTRNAME); path = makepath(Lp_Tmp, tmpName, (char *)0); if (stat(path, &tmpBuf) == 0) { syslog(LOG_DEBUG, "s_end_change_request: attribute file ='%s'", path); /* * IPP job attribute file exists for this job so * change permissions and ownership of the file */ (void) chownmod(path, Lp_Uid, Lp_Gid, 0644); Free(path); } else { syslog(LOG_DEBUG, "s_end_change_request: no attribute file"); } #endif rp->request->outcome &= ~(RS_CHANGING); del_flt_act(md, FLT_CHANGE); /* * The RS_CHANGING bit may have been the only thing * preventing this request from filtering or printing, * so regardless of what happens below, * we must check to see if the request can proceed. */ call_schedule = 1; if (!(r = Getrequest(rp->req_file))) status = MNOOPEN; else { oldr = *(rp->request); *(rp->request) = *r; move_ok = STREQU(oldr.destination, r->destination); /* * Preserve the current request status! */ rp->request->outcome = oldr.outcome; /* * Here's an example of the dangers one meets * when public flags are used for private * purposes. ".actions" (indeed, anything in the * REQUEST structure) is set by the person * changing the job. However, lpsched uses * ".actions" as place to indicate that a job * came from a remote system and we must send * back job completion--this is a strictly * private flag that we must preserve. */ rp->request->actions |= (oldr.actions & ACT_NOTIFY); if ((rp->request->actions & ACT_SPECIAL) == ACT_HOLD) { rp->request->outcome |= RS_HELD; /* * To be here means either the user owns * the request or he or she is the * administrator. Since we don't want to * set the RS_ADMINHELD flag if the user * is the administrator, the following * compare will work. */ if (md->uid != rp->secure->uid) rp->request->outcome |= RS_ADMINHELD; } if ((rp->request->actions & ACT_SPECIAL) == ACT_RESUME) { if ((rp->request->outcome & RS_ADMINHELD) && !md->admin) { status = MNOPERM; goto Return; } rp->request->outcome &= ~(RS_ADMINHELD|RS_HELD); } if ((rp->request->actions & ACT_SPECIAL) == ACT_IMMEDIATE) { if (!md->admin) { status = MNOPERM; goto Return; } rp->request->outcome |= RS_IMMEDIATE; } size = chfiles(rp->request->file_list, Lp_Uid, Lp_Gid); if (size < 0) { status = MUNKNOWN; goto Return; } if (!(rp->request->outcome & RS_HELD) && size == 0) { status = MNOPERM; goto Return; } osize = rp->secure->size; rp->secure->size = size; if (move_ok == 0) { char *dest = strdup(r->destination); if ((status = mv_file(rp, dest)) == MOK) rp->secure->size = osize; free(dest); } else if ((err = validate_request(rp, (char **)0, move_ok)) != MOK) { status = err; rp->secure->size = osize; } else { status = MOK; if ((rp->request->outcome & RS_IMMEDIATE) || (rp->request->priority != oldr.priority)) { remover(rp); insertr(rp); } freerequest(&oldr); (void) putrequest(rp->req_file, rp->request); /* * fix for bugid 1103890. * use Putsecure instead. */ (void) Putsecure(rp->req_file, rp->secure); } } } Return: if (status != MOK && rp) { if (r) { freerequest(r); *(rp->request) = oldr; } if (status != MNOSTART) (void) putrequest(rp->req_file, rp->request); } if (call_schedule) maybe_schedule(rp); mputm(md, R_END_CHANGE_REQUEST, status, chkprinter_result); }
void robot_finds_kitten::process_input(int input, WINDOW *w) { timespec ts; ts.tv_sec = 1; ts.tv_nsec = 0; int check_x = robot.x; int check_y = robot.y; switch (input) { case KEY_UP: /* up */ check_y--; break; case KEY_DOWN: /* down */ check_y++; break; case KEY_LEFT: /* left */ check_x--; break; case KEY_RIGHT: /* right */ check_x++; break; case 0: break; default: { /* invalid command */ for (int c = 0; c < rfkCOLS; c++) { mvwputch (w, 0, c, c_white, ' '); mvwputch (w, 1, c, c_white, ' '); } mvwprintz (w, 0, 0, c_white, _("Invalid command: Use direction keys or press 'q'.")); return; } } if (check_y < 3 || check_y > rfkLINES - 1 || check_x < 0 || check_x > rfkCOLS - 1) { return; } if (rfkscreen[check_x][check_y] != EMPTY) { switch (rfkscreen[check_x][check_y]) { case ROBOT: /* We didn't move. */ break; case KITTEN: {/* Found it! */ for (int c = 0; c < rfkCOLS; c++) { mvwputch (w, 0, c, c_white, ' '); } /* The grand cinema scene. */ for (int c = 0; c <= 3; c++) { wmove(w, 1, (rfkCOLS / 2) - 5 + c); wputch(w, c_white, ' '); wmove(w, 1, (rfkCOLS / 2) + 4 - c); wputch(w, c_white, ' '); wmove(w, 1, (rfkCOLS / 2) - 4 + c); if (input == KEY_LEFT || input == KEY_UP) { draw_kitten(w); } else { draw_robot(w); } wmove(w, 1, (rfkCOLS / 2) + 3 - c); if (input == KEY_LEFT || input == KEY_UP) { draw_robot(w); } else { draw_kitten(w); } wrefresh (w); nanosleep(&ts, NULL); } /* They're in love! */ mvwprintz(w, 0, ((rfkCOLS - 6) / 2) - 1, c_ltred, "<3<3<3"); wrefresh(w); nanosleep(&ts, NULL); for (int c = 0; c < rfkCOLS; c++) { mvwputch (w, 0, c, c_white, ' '); mvwputch (w, 1, c, c_white, ' '); } mvwprintz (w, 0, 0, c_white, _("You found kitten! Way to go, robot!")); wrefresh(w); ret = true; int ech = input; do { ech = getch (); } while ( ech == input ); } break; default: { for (int c = 0; c < rfkCOLS; c++) { mvwputch (w, 0, c, c_white, ' '); mvwputch (w, 1, c, c_white, ' '); } std::vector<std::string> bogusvstr = foldstring( getmessage( bogus_messages[rfkscreen[check_x][check_y] - 2]), rfkCOLS); for (size_t c = 0; c < bogusvstr.size(); c++) { mvwprintw (w, c, 0, "%s", bogusvstr[c].c_str()); } wrefresh(w); } break; } wmove(w, 2, 0); return; } /* Otherwise, move the robot. */ robot.x = check_x; robot.y = check_y; }
void s_print_request(char *m, MESG *md) { extern char *Local_System; char *file; char *idno; char *path; char *req_file; char *req_id = 0; RSTATUS *rp; REQUEST *r; SECURE *s; struct passwd *pw; short err; short status; off_t size; uid_t org_uid; gid_t org_gid; #ifdef LP_USE_PAPI_ATTR struct stat tmpBuf; char tmpName[BUFSIZ]; #endif (void) getmessage(m, S_PRINT_REQUEST, &file); syslog(LOG_DEBUG, "s_print_request(%s)", (file ? file : "NULL")); /* * "NewRequest" points to a request that's not yet in the * request list but is to be considered with the rest of the * requests (e.g. calculating # of requests awaiting a form). */ if ((rp = NewRequest = new_rstatus(NULL, NULL)) == NULL) status = MNOMEM; else { req_file = reqpath(file, &idno); path = makepath(Lp_Tmp, req_file, (char *)0); (void) chownmod(path, Lp_Uid, Lp_Gid, 0644); Free(path); if (!(r = Getrequest(req_file))) status = MNOOPEN; else { rp->req_file = Strdup(req_file); freerequest(rp->request); rp->request = r; rp->request->outcome = 0; rp->secure->uid = md->uid; rp->secure->gid = md->gid; if (md->slabel != NULL) rp->secure->slabel = Strdup(md->slabel); pw = getpwuid(md->uid); endpwent(); if (pw && pw->pw_name && *pw->pw_name) rp->secure->user = Strdup(pw->pw_name); else { rp->secure->user = Strdup(BIGGEST_NUMBER_S); (void) sprintf(rp->secure->user, "%u", md->uid); } if ((rp->request->actions & ACT_SPECIAL) == ACT_HOLD) rp->request->outcome |= RS_HELD; if ((rp->request->actions & ACT_SPECIAL) == ACT_RESUME) rp->request->outcome &= ~RS_HELD; if ((rp->request->actions & ACT_SPECIAL) == ACT_IMMEDIATE) { if (!md->admin) { status = MNOPERM; goto Return; } rp->request->outcome |= RS_IMMEDIATE; } size = chfiles(rp->request->file_list, Lp_Uid, Lp_Gid); if (size < 0) { /* * at this point, chfiles() may have * failed because the file may live on * an NFS mounted filesystem, under * a directory of mode 700. such a * directory isn't accessible even by * root, according to the NFS protocol * (i.e. the Stat() in chfiles() failed). * this most commonly happens via the * automounter, and rlogin. thus we * change our euid/egid to that of the * user, and try again. if *this* fails, * then the file must really be * inaccessible. */ org_uid = geteuid(); org_gid = getegid(); if (setegid(md->gid) != 0) { status = MUNKNOWN; goto Return; } if (seteuid(md->uid) != 0) { setgid(org_gid); status = MUNKNOWN; goto Return; } size = chfiles(rp->request->file_list, Lp_Uid, Lp_Gid); if (seteuid(org_uid) != 0) { /* should never happen */ note("s_print_request(): "); note("seteuid back to uid=%d " "failed!!\n", org_uid); size = -1; } if (setegid(org_gid) != 0) { /* should never happen */ note("s_print_request(): "); note("setegid back to uid=%d " "failed!!\n", org_uid); size = -1; } if (size < 0) { status = MUNKNOWN; goto Return; } } if (!(rp->request->outcome & RS_HELD) && size == 0) { status = MNOPERM; goto Return; } rp->secure->size = size; (void) time(&rp->secure->date); rp->secure->req_id = NULL; if (!rp->request->title) { if (strlen(*rp->request->file_list) < (size_t)24) rp->request->title = Strdup(*rp->request->file_list); else { char *r; if (r = strrchr( *rp->request->file_list, '/')) r++; else r = *rp->request->file_list; rp->request->title = malloc(25); sprintf(rp->request->title, "%-.24s", r); } } if ((err = validate_request(rp, &req_id, 0)) != MOK) status = err; else { /* * "req_id" will be supplied if this is from a * remote system. */ if (rp->secure->req_id == NULL) { req_id = makestr(req_id, "-", idno, (char *)0); rp->secure->req_id = req_id; } else req_id = rp->secure->req_id; #ifdef LP_USE_PAPI_ATTR /* * Check if the PAPI job attribute file * exists, if it does change the * permissions and ownership of the file. * This file is created when print jobs * are submitted via the PAPI interface, * the file pathname of this file is * passed to the slow-filters and printer * interface script as an environment * variable when they are executed */ snprintf(tmpName, sizeof (tmpName), "%s-%s", idno, LP_PAPIATTRNAME); path = makepath(Lp_Temp, tmpName, (char *)0); if (stat(path, &tmpBuf) == 0) { syslog(LOG_DEBUG, "s_print_request: "\ "attribute file ='%s'", path); /* * IPP job attribute file exists * for this job so change * permissions and ownership of * the file */ (void) chownmod(path, Lp_Uid, Lp_Gid, 0644); Free(path); } else { syslog(LOG_DEBUG, "s_print_request: "\ "no attribute file"); } #endif /* * fix for bugid 1103890. * use Putsecure instead. */ if ((Putsecure(req_file, rp->secure) == -1) || (putrequest(req_file, rp->request) == -1)) status = MNOMEM; else { status = MOK; insertr(rp); NewRequest = 0; if (rp->slow) schedule(EV_SLOWF, rp); else schedule(EV_INTERF, rp->printer); del_flt_act(md, FLT_FILES); } } } } Return: NewRequest = 0; Free(req_file); Free(idno); if (status != MOK && rp) { rmfiles(rp, 0); free_rstatus(rp); } mputm(md, R_PRINT_REQUEST, status, NB(req_id), chkprinter_result); }
void s_inquire_request_rank(char *m, MESG *md) { char *form; char *dest; char *pwheel; char *user; char *req_id; RSTATUS *rp; RSTATUS *found = NULL; int found_rank = 0; short prop; char files[BUFSIZ]; int i; (void) getmessage(m, S_INQUIRE_REQUEST_RANK, &prop, &form, &dest, &req_id, &user, &pwheel); syslog(LOG_DEBUG, "s_inquire_request_rank(%d, %s, %s, %s, %s, %s)", prop, (form ? form : "NULL"), (dest ? dest : "NULL"), (req_id ? req_id : "NULL"), (user ? user : "******"), (pwheel ? pwheel : "NULL")); for (i = 0; PStatus != NULL && PStatus[i] != NULL; i++) PStatus[i]->nrequests = 0; for (rp = Request_List; rp != NULL; rp = rp->next) { if (rp->printer && !(rp->request->outcome & RS_DONE)) rp->printer->nrequests++; if (*form && !SAME(form, rp->request->form)) continue; if (*dest && !STREQU(dest, rp->request->destination)) { if (!rp->printer) continue; if (!STREQU(dest, rp->printer->printer->name)) continue; } if (*req_id && !STREQU(req_id, rp->secure->req_id)) continue; if (*user && !bangequ(user, rp->secure->user)) continue; if (*pwheel && !SAME(pwheel, rp->pwheel_name)) continue; /* * For Trusted Extensions, we need to check the sensitivity * label of the connection and job before we return it to the * client. */ if ((md->admin <= 0) && (is_system_labeled()) && (md->slabel != NULL) && (rp->secure->slabel != NULL) && (!STREQU(md->slabel, rp->secure->slabel))) continue; if (found) { GetRequestFiles(found->request, files, sizeof (files)); mputm(md, R_INQUIRE_REQUEST_RANK, MOKMORE, found->secure->req_id, found->request->user, /* bgolden 091996, bug 1257405 */ found->secure->slabel, found->secure->size, found->secure->date, found->request->outcome, found->printer->printer->name, (found->form? found->form->form->name : ""), NB(found->pwheel_name), found_rank, files); } found = rp; found_rank = found->printer->nrequests; } if (found) { GetRequestFiles(found->request, files, sizeof (files)); mputm(md, R_INQUIRE_REQUEST_RANK, MOK, found->secure->req_id, found->request->user, /* bgolden 091996, bug 1257405 */ found->secure->slabel, found->secure->size, found->secure->date, found->request->outcome, found->printer->printer->name, (found->form? found->form->form->name : ""), NB(found->pwheel_name), found_rank, files); } else mputm(md, R_INQUIRE_REQUEST_RANK, MNOINFO, "", "", "", 0L, 0L, 0, "", "", "", 0, ""); }
int main(int argc, char *argv[]) { int mtype, size, c, list = FALSE, limit = -1, deflt = -1; int fd; char *userlist = 0, *user, **users, *p; short status; struct user_priority *ppri_tbl, *ld_priority_file(); extern char *optarg; extern int optind, opterr, optopt, errno; setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); if(argc == 1) { usage: (void) printf(gettext("usage: \n")); (void) printf(gettext("(assign priority limit to users)\n")); (void) printf(gettext("\tlpusers -q priority -u user-list\n")); (void) printf(gettext( "(assign default priority limit for balance of users)\n")); (void) printf(gettext("\tlpusers -q priority\n")); (void) printf(gettext("(put users back to default priority limit)\n")); (void) printf(gettext("\tlpusers -u user-list\n")); (void) printf(gettext("(assign default priority)\n")); (void) printf(gettext("\tlpusers -d priority\n")); (void) printf(gettext("(examine priority limits, defaults)\n")); (void) printf(gettext("\tlpusers -l\n")); exit(argc == 1); } opterr = 0; /* disable printing of errors by getopt */ while ((c = getopt(argc, argv, "ld:q:u:")) != -1) switch(c) { case 'l': if (list) LP_ERRMSG1(WARNING, E_LP_2MANY, 'l'); list = TRUE; break; case 'd': if (deflt != -1) LP_ERRMSG1(WARNING, E_LP_2MANY, 'd'); deflt = (int)strtol(optarg,&p,10); if (*p || deflt<PRI_MIN || deflt>PRI_MAX) { LP_ERRMSG1(ERROR, E_LP_BADPRI, optarg); exit(1); } break; case 'q': if (limit != -1) LP_ERRMSG1(WARNING, E_LP_2MANY, 'q'); limit = (int)strtol(optarg,&p,10); if (*p || limit<PRI_MIN || limit>PRI_MAX) { LP_ERRMSG1(ERROR, E_LP_BADPRI, optarg); exit(1); } break; case 'u': if (userlist) LP_ERRMSG1(WARNING, E_LP_2MANY, 'u'); userlist = optarg; break; case '?': if (optopt == '?') goto usage; (p = "-X")[1] = optopt; if (strchr("ldqu", optopt)) LP_ERRMSG1(ERROR, E_LP_OPTARG, p); else LP_ERRMSG1(ERROR, E_LP_OPTION, p); exit(1); } if (optind < argc) { LP_ERRMSG1(ERROR, E_LP_EXTRA, argv[optind]); exit(1); } if (((list || deflt != -1) && (limit != -1 || userlist)) || (list && deflt != -1)) { LP_ERRMSG(ERROR, E_LP_OPTCOMB); /* invalid combination of options */ exit(1); } PRIORITY = Lp_Users; /* load existing priorities from file */ if (!(ppri_tbl = ld_priority_file(PRIORITY))) { switch (errno) { case EBADF: LP_ERRMSG1(ERROR, E_LPU_BADFORM, PRIORITY); break; default: LP_ERRMSG2(ERROR, E_LPU_BADFILE, PRIORITY, errno); } exit(1); } if (list) { print_tbl(ppri_tbl); exit (0); } else { if (userlist) { users = getlist(userlist, " \t", ","); if (users) while (user = *users++) { if (del_user(ppri_tbl, user) && (limit == -1)) LP_ERRMSG1(WARNING, E_LPU_NOUSER, user); if (limit != -1) { if (add_user(ppri_tbl, user, limit)) LP_ERRMSG1(WARNING, E_LPU_BADU, user); } } } else if (deflt != -1) ppri_tbl->deflt = deflt; else ppri_tbl->deflt_limit = limit; if ((fd = open_locked(PRIORITY, "w", LPU_MODE)) < 0) { LP_ERRMSG1(ERROR, E_LP_ACCESS, PRIORITY); exit(1); } output_tbl(fd, ppri_tbl); close(fd); } if (mopen()) /* error on mopen == no spooler, exit quietly */ exit(0); (void)putmessage (message, S_LOAD_USER_FILE); if (msend(message)) goto Error; if (mrecv(reply, sizeof(reply)) == -1) goto Error; mtype = getmessage(reply, R_LOAD_USER_FILE, &status); if (mtype != R_LOAD_USER_FILE) { LP_ERRMSG1 (ERROR, E_LP_BADREPLY, mtype); goto NoError; } if (status == 0) goto NoError; Error: LP_ERRMSG (ERROR, E_LPU_NOLOAD); NoError:(void)mclose (); return (0); }
void editor (char *filename, int startpos) { int stop = FALSE; // exit main loop? int fline = 0; // no. of first displayed line int cline = 0; // no. of line with cursor int shift = 0; // shift to the right int ccol = 0; // column of the cursor position in the file window int k, i, ndisp, rc, reply; char *p, buf[1024]; if (editor_open_file (filename) < 0) return; cline = min1 (startpos, nl-1); fline = max1 (0, cline - video_vsize()/2); // enter the loop while (1) { if (stop) { rc = 0; if (changed) { rc = -1; reply = fly_ask (0, " Save file `%s'? ", " Yes \n No \n Cancel ", filename); if (reply == 1) rc = editor_save_file (filename); if (reply == 2) rc = 0; if (reply == 3) stop = FALSE; } if (rc == 0) break; } ndisp = video_vsize()-1; // draw the screen for (i=0; i<ndisp; i++) { video_put_n_cell (' ', _BackWhite+_Black, video_hsize(), i, 0); if (i+fline < nl) editor_display_line (i, fline+i, shift); } video_put_n_cell (' ', _BackBlue+_White, video_hsize(), video_vsize()-1, 0); snprintf1 (buf, sizeof(buf), "L%d:C%d:S%d %c %s%s", cline, ccol, shift, fl_sym.v, changed ? "*" : "", filename); video_put (buf, video_vsize()-1, 0); video_set_cursor (cline-fline, ccol-shift); video_update (0); // get a keyboard/mouse event and process it k = getmessage (-1); if (IS_KEY(k)) { switch (k) { // Navigation keys case _Up: case _Down: case _PgUp: case _PgDn: fly_scroll_it (k, &fline, &cline, nl, video_vsize()-1); break; case _Right: ccol++; if (ccol-shift > video_hsize()-1) shift = ccol-video_hsize()+1; break; case _Left: ccol = max1 (ccol-1, 0); if (ccol < shift) shift = ccol; break; case _Home: ccol = 0; shift = 0; break; case _End: ccol = strlen(lines[cline]); if (ccol-shift > video_hsize()-1) shift = ccol-video_hsize()+1; break; case _CtrlHome: fline = 0; cline = 0; ccol = 0; shift = 0; break; case _CtrlEnd: fline = max1 (0, nl-video_vsize()+1); cline = min1 (fline+video_vsize()-1, nl-1); shift = 0; ccol = 0; break; // Action keys case _CtrlY: put_clipboard (lines[cline]); free (lines[cline]); for (i=cline; i<nl-1; i++) lines[i] = lines[i+1]; nl--; changed = TRUE; break; case _ShiftInsert: case _CtrlV: p = get_clipboard (); if (p == NULL || *p == '\0') break; if (nl == na) { na *= 2; lines = realloc (lines, sizeof(char *) * na); } for (i=nl-1; i>cline; i--) lines[i+1] = lines[i]; lines[cline+1] = p; ccol = 0; shift = 0; cline++; if (cline-fline == video_vsize()-1) fline++; nl++; changed = TRUE; break; case _BackSpace: if (ccol == 0) { // ccol == 0: glue this line to the previous if (cline == 0) break; p = malloc (strlen (lines[cline])+strlen(lines[cline-1])+1); strcpy (p, lines[cline-1]); strcat (p, lines[cline]); ccol = strlen (lines[cline-1]); if (ccol-shift > video_hsize()-1) shift = ccol-video_hsize()+1; free (lines[cline-1]); free (lines[cline]); lines[cline-1] = p; for (i=cline; i<nl-1; i++) lines[i] = lines[i+1]; cline--; nl--; } else { // ccol != 0: delete char at ccol-1, move cursor left str_delete (lines[cline], lines[cline]+ccol-1); ccol--; if (ccol < shift) shift = ccol; } changed = TRUE; break; case _Enter: if (nl == na) { na *= 2; lines = realloc (lines, sizeof(char *) * na); } for (i=nl-1; i>cline; i--) lines[i+1] = lines[i]; if (ccol < strlen (lines[cline])) { lines[cline+1] = strdup (lines[cline]+ccol); lines[cline][ccol] = '\0'; } else { lines[cline+1] = strdup (""); } ccol = 0; shift = 0; cline++; if (cline-fline == video_vsize()-1) fline++; nl++; changed = TRUE; break; case _Delete: if (ccol >= strlen (lines[cline])) { // glue previous line to this one if (cline == nl-1) break; p = malloc (ccol+strlen(lines[cline+1])+1); strcpy (p, lines[cline]); memset (p+strlen(lines[cline]), ' ', ccol-strlen(lines[cline])); strcpy (p+ccol, lines[cline+1]); free (lines[cline]); free (lines[cline+1]); lines[cline] = p; for (i=cline+1; i<nl-1; i++) lines[i] = lines[i+1]; nl--; } else { // ccol != 0: delete char at ccol-1, move cursor left str_delete (lines[cline], lines[cline]+ccol); } changed = TRUE; break; case _F2: rc = editor_save_file (filename); if (rc == 0) changed = FALSE; break; case _Esc: case _F10: stop = TRUE; break; // character keys default: if (k >= ' ' && k <= 255) { str_insert_at (cline, k, ccol); ccol++; changed = TRUE; } } } else if (IS_MOUSE(k)) { } else if (IS_SYSTEM(k)) { switch (SYS_TYPE(k)) { case SYSTEM_QUIT: stop = TRUE; break; } } } if (nl != 0 && lines != NULL) for (i=0; i<nl; i++) free (lines[i]); if (na != 0 && lines != NULL) free (lines); na = 0; lines = NULL; }